Skip to content

render-pipeline: a formula opening with \displaystyle is set in display style - #427

Merged
GoKubar merged 1 commit into
mainfrom
lane/nixos-offpage-glyphs/displaystyle-switch
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
lane/nixos-offpage-glyphs/displaystyle-switch

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

render-pipeline: a formula opening with \displaystyle is set in display style

\displaystyle is a style switch, not a command with an argument: it changes
the style for the rest of the enclosing group (TeX §1171). The pinned compiler
models none of that. All four switches, and \nonumber, \notag and
\middle with them, share one arm:

// crates/compiler/src/math.rs
"displaystyle" | "textstyle" | "scriptstyle" | "scriptscriptstyle"
| "nonumber" | "notag" | "middle" => space(0.0, span),

— a zero-width Nucleus::Space atom, which the pipeline then skips. So
$\displaystyle\sum_{n=1}^{\infty}(a_n-\tfrac25)$ was laid out in text
style, with the limits beside the operator as scripts.

That is a vertical defect as much as a horizontal one, and it is the largest
single cause of the drift down fixtures/real-world/ps-calculus. A text-style
sum is about 8 pt shorter than a display-style one, and a short box never
trips TeX's interline rule (§679: interline glue is \baselineskip - \prevdepth - height, or \lineskip when that falls below \lineskiplimit),
so the following baseline stayed a plain \baselineskip away — and so did
every later line on the page. Measured on the enumerate of ps-calculus's
Problem 1 against pdflatex (TeX Live 2025, oracle only):

baseline-to-baseline           pdflatex   before    after
item (a) -> item (b)            35.758    22.516   30.848
item (b) line 1 -> line 2       22.297    13.549   22.297
accumulated by the next para   (0)       -21.99    -4.910

The switch is read back from the source at the atom's span, exactly as
class_override_of already reads \mathbin/\mathrel back for a pin that
keeps MathAtom::class_override private, and for the same reason: the
information is in the document and not in the parse tree. math-layout needs
nothing — layout_with_report already takes the starting Style.

Only a switch that is the formula's first atom is honoured, which is the
case where it governs the whole formula and nothing else. That is every use in
the corpus (six: five in ps-calculus, one in math-sheet, all
$\displaystyle\int…$-shaped). A switch in the middle of a list, or inside a
grid cell or a sub-formula, still needs the compiler to emit an atom for it;
math-layout is ready for that too (Nucleus::Styled, laid out at
vendor/math-layout/src/layout.rs:345). No vendor file is touched here and no
re-pin is required.

Corpus effect, both sides through PR #415's rank.py (geometry only, no
raster stage; #415 is still open, so do not compare these with numbers taken
from main's word grouping):

fixture         dx %            dy %            both %
ps-calculus     72.58 -> 76.03  10.89 -> 13.40  10.89 -> 12.37
math-sheet      46.20 -> 46.20  26.14 -> 24.62  10.03 -> 10.03
corpus          85.59 -> 85.74  75.08 -> 75.04  69.02 -> 68.97

ps-calculus's page medians go -20.83 / -63.35 / -97.97 bp to -3.5 / -37.05 /
-49.02. math-sheet's steps improve too — the step at Integration by parts
goes -1.98 -> +2.90 and the one after it -1.71 -> +0.46, and the drift below
that line goes -9.99 -> -8.03 — but a band of its lines sat just inside 0.5 bp
on top of a pre-existing -25.50 bp offset near the top of the page and now
sits just outside, which is what the -1.52 pp is. The corpus dy and both
columns move by -0.04 and -0.05 pp, i.e. they do not move: the remaining error
on these pages is in the display-style boxes themselves, which is the next
cause, not this one.

What is left on ps-calculus, measured and not fixed here — two further
mechanisms, each its own PR:

  • \lim, \max, \min, \sup, \inf, \det, \gcd, \Pr never take
    display limits, \displaystyle or not, because convert_math_classed maps
    every compiler Nucleus::Text to an Ord atom
    (typeset.rs, N::Text(text) => vec![sink.atom(text)]) where math-layout
    has Atom::text_op (Op class, Limits::Limits by default) for exactly
    this. In \[\lim_{n\to\infty}a_n\] pdflatex puts n→∞ 6.546 bp below the
    baseline and this puts it 1.636 below, as a subscript. \sum and \prod
    are unaffected — they are Nucleus::Symbol and already stack.
  • A display-style operator's box runs about 2.8 bp deeper than pdfTeX's. With
    the limits themselves landing exactly right (the \infty 13.637 bp above
    the baseline and the n=1 12.954 below, both matching pdflatex to 0.001),
    the box beneath the lower limit is still too deep, so the next line
    overshoots: pdflatex 19.738 bp, this 22.555.

An attribution control, for whoever picks those up: running local pdflatex and
this renderer on ps-calculus with every \displaystyle deleted from the
source gives page medians +7.65 / +1.22 / +0.06 bp and 99.7% of page 3's words
within 0.5 bp — text-style math on this document is right, and what is left
above is display-style math.

Gates: cargo test --release --no-fail-fast on crates/render-pipeline, 60
test binaries, 0 failed (one new, displaystyle_switch, two of whose three
tests fail on today's main); amsmath 59/59 within 0.5 bp, tabular 106/106
(words 0.5 bp, rules 0.1 bp), HW1 and HW2 3 pages / 0 errors / 0 font-FAILURE
diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-offpage-glyphs, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)

…play style

`\displaystyle` is a style switch, not a command with an argument: it changes
the style for the rest of the enclosing group (TeX §1171). The pinned compiler
models none of that. All four switches, and `\nonumber`, `\notag` and
`\middle` with them, share one arm:

    // crates/compiler/src/math.rs
    "displaystyle" | "textstyle" | "scriptstyle" | "scriptscriptstyle"
    | "nonumber" | "notag" | "middle" => space(0.0, span),

— a zero-width `Nucleus::Space` atom, which the pipeline then skips. So
`$\displaystyle\sum_{n=1}^{\infty}(a_n-\tfrac25)$` was laid out in *text*
style, with the limits beside the operator as scripts.

That is a vertical defect as much as a horizontal one, and it is the largest
single cause of the drift down `fixtures/real-world/ps-calculus`. A text-style
sum is about 8 pt shorter than a display-style one, and a short box never
trips TeX's interline rule (§679: interline glue is `\baselineskip -
\prevdepth - height`, or `\lineskip` when that falls below `\lineskiplimit`),
so the following baseline stayed a plain `\baselineskip` away — and so did
every later line on the page. Measured on the `enumerate` of ps-calculus's
Problem 1 against pdflatex (TeX Live 2025, oracle only):

    baseline-to-baseline           pdflatex   before    after
    item (a) -> item (b)            35.758    22.516   30.848
    item (b) line 1 -> line 2       22.297    13.549   22.297
    accumulated by the next para   (0)       -21.99    -4.910

The switch is read back from the source at the atom's span, exactly as
`class_override_of` already reads `\mathbin`/`\mathrel` back for a pin that
keeps `MathAtom::class_override` private, and for the same reason: the
information is in the document and not in the parse tree. math-layout needs
nothing — `layout_with_report` already takes the starting `Style`.

Only a switch that is the formula's *first* atom is honoured, which is the
case where it governs the whole formula and nothing else. That is every use in
the corpus (six: five in ps-calculus, one in math-sheet, all
`$\displaystyle\int…$`-shaped). A switch in the middle of a list, or inside a
grid cell or a sub-formula, still needs the compiler to emit an atom for it;
math-layout is ready for that too (`Nucleus::Styled`, laid out at
`vendor/math-layout/src/layout.rs:345`). No vendor file is touched here and no
re-pin is required.

Corpus effect, both sides through PR #415's `rank.py` (geometry only, no
raster stage; #415 is still open, so do not compare these with numbers taken
from `main`'s word grouping):

    fixture         dx %            dy %            both %
    ps-calculus     72.58 -> 76.03  10.89 -> 13.40  10.89 -> 12.37
    math-sheet      46.20 -> 46.20  26.14 -> 24.62  10.03 -> 10.03
    corpus          85.59 -> 85.74  75.08 -> 75.04  69.02 -> 68.97

ps-calculus's page medians go -20.83 / -63.35 / -97.97 bp to -3.5 / -37.05 /
-49.02. math-sheet's *steps* improve too — the step at `Integration by parts`
goes -1.98 -> +2.90 and the one after it -1.71 -> +0.46, and the drift below
that line goes -9.99 -> -8.03 — but a band of its lines sat just inside 0.5 bp
on top of a pre-existing -25.50 bp offset near the top of the page and now
sits just outside, which is what the -1.52 pp is. The corpus dy and both
columns move by -0.04 and -0.05 pp, i.e. they do not move: the remaining error
on these pages is in the display-style boxes themselves, which is the next
cause, not this one.

What is left on ps-calculus, measured and *not* fixed here — two further
mechanisms, each its own PR:

* `\lim`, `\max`, `\min`, `\sup`, `\inf`, `\det`, `\gcd`, `\Pr` never take
  display limits, `\displaystyle` or not, because `convert_math_classed` maps
  every compiler `Nucleus::Text` to an **Ord** atom
  (`typeset.rs`, `N::Text(text) => vec![sink.atom(text)]`) where math-layout
  has `Atom::text_op` (Op class, `Limits::Limits` by default) for exactly
  this. In `\[\lim_{n\to\infty}a_n\]` pdflatex puts `n→∞` 6.546 bp below the
  baseline and this puts it 1.636 below, as a subscript. `\sum` and `\prod`
  are unaffected — they are `Nucleus::Symbol` and already stack.
* A display-style operator's box runs about 2.8 bp deeper than pdfTeX's. With
  the limits themselves landing exactly right (the `\infty` 13.637 bp above
  the baseline and the `n=1` 12.954 below, both matching pdflatex to 0.001),
  the box beneath the lower limit is still too deep, so the next line
  overshoots: pdflatex 19.738 bp, this 22.555.

An attribution control, for whoever picks those up: running local pdflatex and
this renderer on ps-calculus with every `\displaystyle` deleted from the
source gives page medians +7.65 / +1.22 / +0.06 bp and 99.7% of page 3's words
within 0.5 bp — text-style math on this document is right, and what is left
above is display-style math.

Gates: `cargo test --release --no-fail-fast` on `crates/render-pipeline`, 60
test binaries, 0 failed (one new, `displaystyle_switch`, two of whose three
tests fail on today's main); amsmath 59/59 within 0.5 bp, tabular 106/106
(words 0.5 bp, rules 0.1 bp), HW1 and HW2 3 pages / 0 errors / 0 font-FAILURE
diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-offpage-glyphs, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar merged commit b529e9d into main Sep 14, 2026
20 of 21 checks passed
d-q222 added a commit that referenced this pull request Sep 14, 2026
Picks up render-pipeline displaystyle after the previous main merge.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged origin/main with ort; no conflicts. Incoming pipeline tests
displaystyle_switch and hyphenated_fragment_units did not touch adapter.rs
preamble scan.

CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-prelen

compiler --lib:
test result: ok. 327 passed; 0 failed; 0 ignored
compiler --test preamble_lengths:
test result: ok. 10 passed; 0 failed; 0 ignored
compiler --test supported_latex:
test result: ok. 8 passed; 0 failed; 0 ignored
compiler full crate: all binaries green; 4 ignored
(hw2_gate, pinned_fixtures, recovery, unsupported_inventory)

render-pipeline --lib:
test result: ok. 121 passed; 0 failed; 2 ignored
(the 110 vs 119 report mismatch: 110 was 245fc95 before this branch's
adapter tests; 119 was a610cba; 121 is 119 plus the two new scan tests.
Ignored: \input preambles; \@setlength)
render-pipeline --test preamble_lengths_oracle:
test result: ok. 5 passed; 0 failed; 0 ignored
render-pipeline full crate: all binaries green; 2 further ignored
(incremental, math_symbols)

Next: push this lane branch. Lane owner splits PRs.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
@GoKubar
GoKubar deleted the lane/nixos-offpage-glyphs/displaystyle-switch branch September 16, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant