diff --git a/lib/expression/node/ParenthesisNode.js b/lib/expression/node/ParenthesisNode.js index 88c8edb0c..9891b5fbe 100644 --- a/lib/expression/node/ParenthesisNode.js +++ b/lib/expression/node/ParenthesisNode.js @@ -83,7 +83,10 @@ function factory (type, config, load, typed) { * @override */ ParenthesisNode.prototype._toString = function() { - return '(' + this.content._toString() + ')'; + if (config.parenthesis === 'keep') { + return '(' + this.content.toString() + ')'; + } + return this.content._toString(); }; /** @@ -93,7 +96,10 @@ function factory (type, config, load, typed) { * @override */ ParenthesisNode.prototype._toTex = function(callbacks) { - return '\\left(' + this.content.toTex(callbacks) + '\\right)'; + if (config.parenthesis === 'keep') { + return '\\left(' + this.content.toTex(callbacks) + '\\right)'; + } + return this.content.toTex(callbacks); }; return ParenthesisNode; diff --git a/test/expression/node/ParenthesisNode.test.js b/test/expression/node/ParenthesisNode.test.js index 4c6acaaf8..3f886a731 100644 --- a/test/expression/node/ParenthesisNode.test.js +++ b/test/expression/node/ParenthesisNode.test.js @@ -131,10 +131,38 @@ describe('ParenthesisNode', function() { assert.equal(n.toString(), '(1)'); }); + it ('should stringify a ParenthesisNode when not in keep mode', function () { + var allMath = math.create({parenthesis: 'all'}); + var autoMath = math.create({parenthesis: 'auto'}); + + var allC = new allMath.expression.node.ConstantNode(1); + var autoC = new autoMath.expression.node.ConstantNode(1); + + var allP = new allMath.expression.node.ParenthesisNode(allC); + var autoP = new autoMath.expression.node.ParenthesisNode(autoC); + + assert.equal(allP.toString(), '1'); + assert.equal(autoP.toString(), '1'); + }); + it ('should LaTeX a ParenthesisNode', function () { var a = new ConstantNode(1); var n = new ParenthesisNode(a); assert.equal(n.toTex(), '\\left(1\\right)'); }); + + it ('should LaTeX a ParenthesisNode when not in keep mode', function () { + var allMath = math.create({parenthesis: 'all'}); + var autoMath = math.create({parenthesis: 'auto'}); + + var allC = new allMath.expression.node.ConstantNode(1); + var autoC = new autoMath.expression.node.ConstantNode(1); + + var allP = new allMath.expression.node.ParenthesisNode(allC); + var autoP = new autoMath.expression.node.ParenthesisNode(autoC); + + assert.equal(allP.toTex(), '1'); + assert.equal(autoP.toTex(), '1'); + }); });