fix: bracket a fraction only where the slash would split it
`\frac{n(n+1)}{2}` came out as `(n(n+1))/2` and the quadratic formula
as a wall of parentheses, because the test was "is this operand a
single token" rather than "would the slash change what this means".
Brackets now appear in exactly two cases: a sum, where the slash would
otherwise divide only the last term, and a denominator that is more
than one term, where `1/2a` is read two ways. `n(n+1)/2`, `√π/2` and
`mc²/√(1 − v²/c²)` need nothing, while `1 / (2a)` and
`(−b ± √(b² − 4ac)) / (2a)` keep their brackets. A script is read
through rather than counted, since a sum above the line is unambiguous
by construction.
The slash is spaced only when something beside it is bracketed, which
is where the brackets would otherwise crowd it.
This commit is contained in:
@@ -275,6 +275,8 @@ Two facts about the renderer decided the design. A paragraph is a `TextEdit` wit
|
||||
|
||||
So this is a linearisation rather than a typesetter. `\frac{a}{b}` becomes `a/b`, `\sqrt{x+1}` becomes `√(x+1)`, `\sum_{i=1}^{n}` becomes `∑ᵢ₌₁ⁿ`, and only what Unicode has no form for falls back to a tag, so `x^{a/b}` becomes `x<sup>a/b</sup>`. `$...$`, `\(...\)`, `$$...$$` or `\[...\]` on a line of its own, and a fence labelled `math`, are all read.
|
||||
|
||||
Brackets appear only where the slash would otherwise change what the formula means. `\frac{n(n+1)}{2}` is `n(n+1)/2` and `\frac{\sqrt{\pi}}{2}` is `√π/2`, because one product either side of a slash needs nothing, while `\frac{1}{2a}` is `1 / (2a)` because `1/2a` is read two ways, and a sum is always bracketed so the slash cannot divide only its last term: `(−b ± √(b² − 4ac)) / (2a)`. The space around the slash shows up only when something beside it is bracketed, which is where the brackets would otherwise crowd it.
|
||||
|
||||
The one guard is worth knowing about. A lone `$` pair counts as maths only when the inside looks like maths, because `x=$a$b` and `cd $A; echo $B` are not formulas, and turning them into one is the single way this feature can make an answer worse than the dollar signs it replaced. `$5 and $10` is left exactly as written.
|
||||
|
||||
### Custom HTML
|
||||
|
||||
Reference in New Issue
Block a user