fix: bracket a fraction only where the slash would split it #20

Merged
adrianbonpin merged 1 commits from fix/fraction-readability into prod 2026-10-07 07:36:41 +00:00
1 Commits
Author SHA1 Message Date
adrianbonpin d958201813 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.
2026-10-07 15:36:27 +08:00