Created
January 31, 2020 03:05
-
-
Save cosinekitty/a936b1a7f19506a1c5871c4d318ed61d to your computer and use it in GitHub Desktop.
Shows optimizing parentheses in TeX output for a left-associative operator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PrettyMath_Binary_LeftAssoc(opsymbol) { | |
let left = this.arglist[0].PrettyMath(); | |
let right = this.arglist[1].PrettyMath(); | |
// Use parentheses around the left child expression | |
// if its operator precedence is less than this node's precedence. | |
// If it is equal, assume left-associativity means parentheses are not needed. | |
if (this.arglist[0].precedence < this.precedence) { | |
left = '\\left(' + left + '\\right)'; | |
} | |
// Use parentheses around the right child expression | |
// if operator precedence is lower or equal. | |
// Even if equal, parentheses are needed because we are | |
// overriding left-associativity. | |
if (this.arglist[1].precedence <= this.precedence) { | |
right = '\\left(' + right + '\\right)'; | |
} | |
return left + (opsymbol || this.optoken.text) + right; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment