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
Owner

The fraction line was bracketing by "is this operand a single token", so \frac{n(n+1)}{2} rendered as (n(n+1))/2 and the quadratic formula as a wall of parentheses.

Brackets now appear in exactly two cases:

  • A sum, because the slash would otherwise divide only its last term.
  • A denominator of more than one term, because 1/2a is read as 1/(2a) by some readers and (1/2)a by others.
LaTeX before after
\frac{n(n+1)}{2} (n(n+1))/2 n(n+1)/2
\frac{\sqrt{\pi}}{2} (√π)/2 √π/2
\frac{mc^2}{\sqrt{1 - v^2/c^2}} (mc²)/(√(1 − v²/c²)) mc²/√(1 − v²/c²)
\frac{1}{2a} 1/(2a) 1 / (2a)
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a} (−b ± √(b² − 4ac))/(2a) (−b ± √(b² − 4ac)) / (2a)
\frac{\sin x}{x} (sin x)/x (sin x) / x

The decision is made from the rendered operand, which is what a reader sees, and it tracks bracket depth so that n(n+1) is not read as a sum, and steps over <sup>/<sub> so that a sum above the line is not counted as a split. The slash gets a space only when something beside it is bracketed, which is where the brackets would otherwise crowd it.

npm run typecheck, npm run lint:code and npm test pass: 582 tests, 5 new.

The fraction line was bracketing by "is this operand a single token", so `\frac{n(n+1)}{2}` rendered as `(n(n+1))/2` and the quadratic formula as a wall of parentheses. Brackets now appear in exactly two cases: - **A sum**, because the slash would otherwise divide only its last term. - **A denominator of more than one term**, because `1/2a` is read as `1/(2a)` by some readers and `(1/2)a` by others. | LaTeX | before | after | | --- | --- | --- | | `\frac{n(n+1)}{2}` | `(n(n+1))/2` | `n(n+1)/2` | | `\frac{\sqrt{\pi}}{2}` | `(√π)/2` | `√π/2` | | `\frac{mc^2}{\sqrt{1 - v^2/c^2}}` | `(mc²)/(√(1 − v²/c²))` | `mc²/√(1 − v²/c²)` | | `\frac{1}{2a}` | `1/(2a)` | `1 / (2a)` | | `\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}` | `(−b ± √(b² − 4ac))/(2a)` | `(−b ± √(b² − 4ac)) / (2a)` | | `\frac{\sin x}{x}` | `(sin x)/x` | `(sin x) / x` | The decision is made from the *rendered* operand, which is what a reader sees, and it tracks bracket depth so that `n(n+1)` is not read as a sum, and steps over `<sup>`/`<sub>` so that a sum above the line is not counted as a split. The slash gets a space only when something beside it is bracketed, which is where the brackets would otherwise crowd it. `npm run typecheck`, `npm run lint:code` and `npm test` pass: 582 tests, 5 new.
adrianbonpin added 1 commit 2026-10-07 07:36:34 +00:00
`\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.
adrianbonpin merged commit 72a63e69e6 into prod 2026-10-07 07:36:41 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adrianbonpin/lam-agent-vicinae#20