Replies: 2 comments
-
Thanks Beriwan, interesting issue. The option We could consider extending this option to also render explicit multiplications as implicit when passing |
Beta Was this translation helpful? Give feedback.
-
As this seems more of a possible idea for mathjs rather than a specific concrete proposal that could be directly implemented, moving to discussions. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to remove implicit multiplication signs from an expression, but I just can't get it to work like in the docs.
Here is a basic example that I tried:
const nodeTest = math.parse('2*a');
console.log(nodeTest.toString({implicit: 'hide'}));
2 a
2 * a
It seems to work the other way around:
const nodeTest = math.parse('2a');
console.log(nodeTest.toString({implicit: 'show'}));
In this case I actually get
2 * a
as expected.Edit:
There actually is a bug in the current toString method of the OperatorNode class.
In line 389 of OperatorNode.js there is a variable "implicit" being set to whatever value you provide to the function within the options object:
var implicit = options && options.implicit ? options.implicit : 'hide';
Later on in line 430, this value should be used to check if the Operator sign should be removed, but instead this.implicit is used, which is oftentimes false.
if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') { return lhs + ' ' + rhs; }
If you change
this.implicit
toimplicit
it works as expected.Beta Was this translation helpful? Give feedback.
All reactions