Properly add parentheses to Fraction::Value objects based on precedence.#512
Conversation
drgrice1
left a comment
There was a problem hiding this comment.
Thanks for fixing this. Looks good.
|
I tested as well, and it works as expected. |
|
I didn't have time to deep-dive, but look at the differences between:
|
|
|
After further testing, when seeing double-parens, the outer parens are from this commit. (So in this example, The parens that appear for Also note: |
|
Furthermore, the other PR only corrects the use of input parameters to the TeX subroutine -- so presumably precedence is now actually being handled properly. Also, look at the difference in behavior for the non-TeX strings
|
Currently, Fraction MathObjects may lose necessary parentheses when stringified or texified. For example
Compute("x^(2/7)")->string;will producex^2/7. This means thatwould produce
$gequivalent toCompute("(x^2)/7")rather than equivalent to$f. (See this Forum post for more details.)This PR resolves the issue by overriding the
string()andTeX()methods to properly insert parentheses when needed. These are added when the operator precedences require it, or (instring()) when the original had them (since the TeX version is a vertical fraction, they are are only added when precedence requires it).To test, use