Repository navigation
render-pipeline: an amsthm theorem is a \trivlist — it has \topsep - #480
Merged
Merged
Conversation
The pipeline knew amsthm's head separator (`crate::amsthm`) and that a
theorem's first line is not indented (`adapter::opens_theorem_item`), but gave
the environment no vertical space at all. Every `\begin{theorem}` and every
`\end{theorem}` was one `\topsep` too tight — 8 / 9 / 10 pt at a 10 / 11 / 12pt
base.
`fixtures/real-world/lecture-notes` has eight such boundaries on page 1 alone,
and its words were a staircase reaching −49.6 bp against the committed
reference: 9.65% of aligned words within 0.5 bp on `dy`.
## The mechanism, from the oracle
pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025), `\showoutput`, between the last
line of one theorem and the first line of the next:
...\hbox(8.2125+2.73749)x469.75502 % last line of the definition
...\penalty -51
...\glue 9.0 plus 3.0 minus 5.0 % \@endparenv's \@topsepadd
...\glue -11.73749 plus -3.0 minus -5.0 % \endtrivlist: -(that + depth)
...\penalty -51
...\glue 2.73749 % + the depth back
...\glue 9.0 plus 3.0 minus 5.0 % \@item's \@topsep for the next
...\glue(\parskip) 0.0 plus 1.0
...\glue(\parskip) 0.0
...\glue(\baselineskip) 2.65002
...\hbox(8.2125+2.73749)x469.75502 % first line of the lemma
The four explicit glues net to **one** `\topsep`: `\addvspace` keeps the larger
of the new skip and `\lastskip`, it does not add them. So the separation is
`\baselineskip` + `\topsep` = 22.6 pt at 11pt, 20.0 at 10pt, 24.5 at 12pt.
The value is `\topsep` alone — never `\partopsep`, never `\parskip` — because
`\@thm` assigns `\@topsep\thm@preskip` and `\@topsepadd\thm@postskip` outright
(amsthm.sty 140–141) and `\thm@space@setup` sets both to `\topsep`. The
`\@trivlist` derivation that `center`/`quote` go through never runs for a
theorem. `proof` is the exception: it is a plain `\trivlist` opened from `\par`
under amsthm's own `\topsep6\p@\@Plus6\p@`, so its *closing* `\@topsepadd` is
6pt + `\partopsep` (`8.0 plus 7.0 minus 1.0`, `9.0 plus 7.0 minus 1.0`,
`9.0 plus 8.0 minus 2.0` at 10 / 11 / 12pt).
`EnvOpen` therefore gains an optional `EnvSkips`: an environment that sets
`\@topsep`/`\@topsepadd` itself carries them, and the existing `center`/`quote`
machinery — which already models `\addvspace`'s max on the opening side —
does the rest. `env_close` for a theorem is set from the `\end{<theorem>}` that
actually closed it, tracked as the unit loop runs so the later `toc_lists`
splice cannot shift the index.
## `\addvspace` does not sum
Closing an environment used to *add* its `\@endparenv` skip to whatever the
block already left. That was invisible while nothing was ever left there, and
wrong the moment a theorem ended in a display: `lecture-notes` page 1 again,
...\hbox(7.60416+2.12917)..., display
...\penalty 0
...\glue(\belowdisplayskip) 11.0 plus 3.0 minus 6.0
...\glue -11.0 plus -3.0 minus -6.0 % \@endparenv takes it off
...\glue 11.0 plus 3.0 minus 6.0 % and puts back the larger
net 11.0 pt, not 11.0 + 9.0.
This takes the max only for an environment that declares its own skips. For the
rest, `space_after` is not necessarily `\lastskip`: the abstract head's
`\vspace{-.5em}` reaches the page through `\vadjust`, *before* the penalty and
the closing skip, so `\addvspace` cannot see it and the two genuinely do add
(`SizedPara::vspace_after_em`). Taking the max there cost `hyperref-toc`,
`lab-report`, `natbib-review` and `plain-article` 25–40 points of `dy` in an
intermediate state of this branch; the guard that caught it is the second test
below. Separating the two for every environment needs `VBlock` to carry
`\vadjust` vspace apart from glue — a change of its own, not made here.
## Effect, against the committed reference PDFs
lecture-notes dy 9.65% -> 61.41% max |dy| 49.6 bp -> 1.08 bp
dx 77.74% unchanged pages 2/2
corpus dy 84.91% -> 86.74% dx 89.89% unchanged, pages 22/22
No other fixture's geometry moves. `lecture-notes` page 2 is now exact (max
|dy| 0.008 bp); the ≤1.08 bp left on page 1 is not a spacing mechanism but the
page-shrink ratio: pdflatex packs that page with `glue set - 0.30122` and we
land near −0.276, so each `\topsep` differs by 0.124 bp and each `proof` close
by 0.025 — the 5:1 of their `minus 5.0` / `minus 1.0`. Closing it means finding
the ~1.5 pt of natural height page 1 is still short of pdflatex's, whose
remaining candidates are the `\tableofcontents` block and the `\section`
before-skips.
Test: `crates/render-pipeline/tests/amsthm_topsep.rs`, every expected number
quoted from the trace above at all three class sizes. On main it says
10pt paragraph -> definition: 11.9552 bp, pdflatex 19.9253 bp
(off by -7.9701 bp)
pdflatex is an oracle only and never runs in the product path.
Gates: `cargo test --release --no-fail-fast` on `crates/render-pipeline`, 366
passed 0 failed; amsmath 59/59 within 0.5 bp; tabular 106/106; HW1 and HW2 3/3
pages, 0 errors, 0 overfull; corpus page counts 22/22 read from the reference
PDFs; zero font-FAILURE diagnostics.
Implementation-Agent: Claude Opus 5 (lane nixos-cv-lecture, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
# Conflicts: # crates/render-pipeline/src/adapter.rs
This was referenced Sep 15, 2026
Merged
This was referenced Sep 15, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
render-pipeline: an amsthm theorem is a \trivlist — it has \topsep
The pipeline knew amsthm's head separator (
crate::amsthm) and that atheorem's first line is not indented (
adapter::opens_theorem_item), but gavethe environment no vertical space at all. Every
\begin{theorem}and every\end{theorem}was one\topseptoo tight — 8 / 9 / 10 pt at a 10 / 11 / 12ptbase.
fixtures/real-world/lecture-noteshas eight such boundaries on page 1 alone,and its words were a staircase reaching −49.6 bp against the committed
reference: 9.65% of aligned words within 0.5 bp on
dy.The mechanism, from the oracle
pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025),
\showoutput, between the lastline of one theorem and the first line of the next:
The four explicit glues net to one
\topsep:\addvspacekeeps the largerof the new skip and
\lastskip, it does not add them. So the separation is\baselineskip+\topsep= 22.6 pt at 11pt, 20.0 at 10pt, 24.5 at 12pt.The value is
\topsepalone — never\partopsep, never\parskip— because\@thmassigns\@topsep\thm@preskipand\@topsepadd\thm@postskipoutright(amsthm.sty 140–141) and
\thm@space@setupsets both to\topsep. The\@trivlistderivation thatcenter/quotego through never runs for atheorem.
proofis the exception: it is a plain\trivlistopened from\parunder amsthm's own
\topsep6\p@\@plus6\p@, so its closing\@topsepaddis6pt +
\partopsep(8.0 plus 7.0 minus 1.0,9.0 plus 7.0 minus 1.0,9.0 plus 8.0 minus 2.0at 10 / 11 / 12pt).EnvOpentherefore gains an optionalEnvSkips: an environment that sets\@topsep/\@topsepadditself carries them, and the existingcenter/quotemachinery — which already models
\addvspace's max on the opening side —does the rest.
env_closefor a theorem is set from the\end{<theorem>}thatactually closed it, tracked as the unit loop runs so the later
toc_listssplice cannot shift the index.
\addvspacedoes not sumClosing an environment used to add its
\@endparenvskip to whatever theblock already left. That was invisible while nothing was ever left there, and
wrong the moment a theorem ended in a display:
lecture-notespage 1 again,net 11.0 pt, not 11.0 + 9.0.
This takes the max only for an environment that declares its own skips. For the
rest,
space_afteris not necessarily\lastskip: the abstract head's\vspace{-.5em}reaches the page through\vadjust, before the penalty andthe closing skip, so
\addvspacecannot see it and the two genuinely do add(
SizedPara::vspace_after_em). Taking the max there costhyperref-toc,lab-report,natbib-reviewandplain-article25–40 points ofdyin anintermediate state of this branch; the guard that caught it is the second test
below. Separating the two for every environment needs
VBlockto carry\vadjustvspace apart from glue — a change of its own, not made here.Effect, against the committed reference PDFs
No other fixture's geometry moves.
lecture-notespage 2 is now exact (max|dy| 0.008 bp); the ≤1.08 bp left on page 1 is not a spacing mechanism but the
page-shrink ratio: pdflatex packs that page with
glue set - 0.30122and weland near −0.276, so each
\topsepdiffers by 0.124 bp and eachproofcloseby 0.025 — the 5:1 of their
minus 5.0/minus 1.0. Closing it means findingthe ~1.5 pt of natural height page 1 is still short of pdflatex's, whose
remaining candidates are the
\tableofcontentsblock and the\sectionbefore-skips.
Test:
crates/render-pipeline/tests/amsthm_topsep.rs, every expected numberquoted from the trace above at all three class sizes. On main it says
10pt paragraph -> definition: 11.9552 bp, pdflatex 19.9253 bp
(off by -7.9701 bp)
pdflatex is an oracle only and never runs in the product path.
Gates:
cargo test --release --no-fail-fastoncrates/render-pipeline, 366passed 0 failed; amsmath 59/59 within 0.5 bp; tabular 106/106; HW1 and HW2 3/3
pages, 0 errors, 0 overfull; corpus page counts 22/22 read from the reference
PDFs; zero font-FAILURE diagnostics.
Implementation-Agent: Claude Opus 5 (lane nixos-cv-lecture, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu