mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
ParenthesisNode: Make use of the parenthesis config option
This commit is contained in:
parent
6c2cd7f7b7
commit
60e2b5700a
@ -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;
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user