diff --git a/lib/expression/node/ArrayNode.js b/lib/expression/node/ArrayNode.js index 4d9d05c82..caf7a6078 100644 --- a/lib/expression/node/ArrayNode.js +++ b/lib/expression/node/ArrayNode.js @@ -99,7 +99,7 @@ ArrayNode.prototype.toString = function() { * @param {String} type * @return {String} str */ -ArrayNode.prototype.toTex = function(customFunctions, type) { +ArrayNode.prototype._toTex = function(customFunctions, type) { type = type || 'bmatrix'; var s = '\\begin{' + type + '}'; diff --git a/lib/expression/node/AssignmentNode.js b/lib/expression/node/AssignmentNode.js index 1223166da..ce9da5cfc 100644 --- a/lib/expression/node/AssignmentNode.js +++ b/lib/expression/node/AssignmentNode.js @@ -92,7 +92,7 @@ AssignmentNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} */ -AssignmentNode.prototype.toTex = function(customFunctions) { +AssignmentNode.prototype._toTex = function(customFunctions) { var precedence = operators.getPrecedence(this); var exprPrecedence = operators.getPrecedence(this.expr); diff --git a/lib/expression/node/BlockNode.js b/lib/expression/node/BlockNode.js index 9f674ba50..90b2d1a14 100644 --- a/lib/expression/node/BlockNode.js +++ b/lib/expression/node/BlockNode.js @@ -125,7 +125,7 @@ BlockNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -BlockNode.prototype.toTex = function(customFunctions) { +BlockNode.prototype._toTex = function(customFunctions) { return this.blocks.map(function (param) { return param.node.toTex(customFunctions) + (param.visible ? '' : ';'); }).join('\n'); diff --git a/lib/expression/node/ConditionalNode.js b/lib/expression/node/ConditionalNode.js index 1ab699f12..29f4c9ff3 100644 --- a/lib/expression/node/ConditionalNode.js +++ b/lib/expression/node/ConditionalNode.js @@ -154,7 +154,7 @@ ConditionalNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -ConditionalNode.prototype.toTex = function(customFunctions) { +ConditionalNode.prototype._toTex = function(customFunctions) { var s = ( latex.addBraces(this.trueExpr.toTex(customFunctions)) + ', &\\quad' + diff --git a/lib/expression/node/ConstantNode.js b/lib/expression/node/ConstantNode.js index f50071886..dd001315e 100644 --- a/lib/expression/node/ConstantNode.js +++ b/lib/expression/node/ConstantNode.js @@ -159,7 +159,7 @@ ConstantNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -ConstantNode.prototype.toTex = function(customFunctions) { +ConstantNode.prototype._toTex = function(customFunctions) { var value = this.value, index; switch (this.valueType) { diff --git a/lib/expression/node/FunctionAssignmentNode.js b/lib/expression/node/FunctionAssignmentNode.js index 97138fca0..5718c0908 100644 --- a/lib/expression/node/FunctionAssignmentNode.js +++ b/lib/expression/node/FunctionAssignmentNode.js @@ -113,7 +113,7 @@ FunctionAssignmentNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -FunctionAssignmentNode.prototype.toTex = function(customFunctions) { +FunctionAssignmentNode.prototype._toTex = function(customFunctions) { var precedence = operators.getPrecedence(this); var exprPrecedence = operators.getPrecedence(this.expr); diff --git a/lib/expression/node/FunctionNode.js b/lib/expression/node/FunctionNode.js index 1f613855c..eaeee60d2 100644 --- a/lib/expression/node/FunctionNode.js +++ b/lib/expression/node/FunctionNode.js @@ -116,7 +116,7 @@ FunctionNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -FunctionNode.prototype.toTex = function(customFunctions) { +FunctionNode.prototype._toTex = function(customFunctions) { return latex.toArgs(this, customFunctions); }; diff --git a/lib/expression/node/IndexNode.js b/lib/expression/node/IndexNode.js index d6bd5b995..175826630 100644 --- a/lib/expression/node/IndexNode.js +++ b/lib/expression/node/IndexNode.js @@ -212,7 +212,7 @@ IndexNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -IndexNode.prototype.toTex = function(customFunctions) { +IndexNode.prototype._toTex = function(customFunctions) { return this.object.toTex(customFunctions) + '[' + this.ranges.join(', ') + ']'; }; diff --git a/lib/expression/node/Node.js b/lib/expression/node/Node.js index 5b97d5693..fcd8d5cc3 100644 --- a/lib/expression/node/Node.js +++ b/lib/expression/node/Node.js @@ -222,10 +222,23 @@ Node.prototype.toString = function() { /** * Get LaTeX representation + * @param {Object|function} callback(s) * @return {String} */ -Node.prototype.toTex = function() { - return ''; +Node.prototype.toTex = function(customFunctions) { + return this._toTex(customFunctions); +}; + +/** + * Internal function to generate the LaTeX output. + * This has to be implemented by every Node + * + * @param {Object}|function} + * @throws {Error} + */ +Node.prototype._toTex = function () { + //must be implemented by each of the Node implementations + throw new Error('_toTex not implemented for this Node'); }; /** diff --git a/lib/expression/node/OperatorNode.js b/lib/expression/node/OperatorNode.js index 9a02e79e6..986fed1af 100644 --- a/lib/expression/node/OperatorNode.js +++ b/lib/expression/node/OperatorNode.js @@ -239,7 +239,7 @@ OperatorNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} str */ -OperatorNode.prototype.toTex = function(customFunctions) { +OperatorNode.prototype._toTex = function(customFunctions) { var args = this.args; var parens = calculateNecessaryParentheses(this, args); var op = latex.toOperator(this.op); //operator diff --git a/lib/expression/node/RangeNode.js b/lib/expression/node/RangeNode.js index 7702c6f6c..f28cfc156 100644 --- a/lib/expression/node/RangeNode.js +++ b/lib/expression/node/RangeNode.js @@ -124,7 +124,7 @@ RangeNode.prototype.toString = function() { * @params {Object|function} callback(s) * @return {String} str */ -RangeNode.prototype.toTex = function(customFunctions) { +RangeNode.prototype._toTex = function(customFunctions) { var str = this.start.toTex(customFunctions); if (this.step) { str += ':' + this.step.toTex(customFunctions); diff --git a/lib/expression/node/SymbolNode.js b/lib/expression/node/SymbolNode.js index cb3ff1ad8..34409fe80 100644 --- a/lib/expression/node/SymbolNode.js +++ b/lib/expression/node/SymbolNode.js @@ -103,7 +103,7 @@ SymbolNode.prototype.toString = function() { * @return {String} str * @override */ -SymbolNode.prototype.toTex = function(customFunctions) { +SymbolNode.prototype._toTex = function(customFunctions) { return latex.toSymbol(this.name, customFunctions); }; diff --git a/lib/expression/node/UpdateNode.js b/lib/expression/node/UpdateNode.js index f48c8cb46..346504ff6 100644 --- a/lib/expression/node/UpdateNode.js +++ b/lib/expression/node/UpdateNode.js @@ -87,7 +87,7 @@ UpdateNode.prototype.toString = function() { * @param {Object|function} callback(s) * @return {String} */ -UpdateNode.prototype.toTex = function(customFunctions) { +UpdateNode.prototype._toTex = function(customFunctions) { return this.index.toTex(customFunctions) + ' = ' + this.expr.toTex(customFunctions); }; diff --git a/test/expression/node/Node.test.js b/test/expression/node/Node.test.js index 355856d16..02589a4e7 100644 --- a/test/expression/node/Node.test.js +++ b/test/expression/node/Node.test.js @@ -74,9 +74,11 @@ describe('Node', function() { assert.equal(node.toString(), ''); }); - it ('should LaTeX a Node', function () { - var node = new Node(); - assert.equal(node.toTex(), ''); + it ('should throw an error when calling toTex', function () { + assert.throws(function () { + var node = new Node(); + node.toTex(); + }, /_toTex not implemented for this Node/); }); it ('should throw an error in case of wrong arguments for compile', function () {