ParenthesisNode: Make use of the parenthesis config option

This commit is contained in:
Max Bruckner 2015-05-05 10:02:45 +02:00
parent 6c2cd7f7b7
commit 60e2b5700a
2 changed files with 36 additions and 2 deletions

View File

@ -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;

View File

@ -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');
});
});