Repository navigation
render-pipeline: amsthm theorem-like environments are a \trivlist \item (lecture-notes line breaks) - #190
Merged
Conversation
The three remaining line-break differences in fixtures/real-world/lecture-notes
are not breaker bugs. Both sides of each break are decided by the *content* of
the theorem line, and two content errors were partly cancelling each other
(+17pt of spurious indent against ~8.4pt of missing head width), which is why
only 3 of 45 lines showed it.
Measured against pdflatex (TeX Live 2025, 11pt article, T1 ecrm1095/ecbx1095 --
the same TFMs this crate reads), with \tracingparagraphs=1 and \showbox:
1. `\trivlist` leaves `\itemindent` at `\z@` (`\showthe\itemindent` inside
`proof` and `theorem` both print `0.0pt`), and `\@item`'s `\everypar` takes
the `\parindent` box back off the first line before unboxing `\@labels`,
whose leading `\hskip\itemindent \hskip-\labelwidth \hskip-\labelsep` is
`-\labelsep` here and exactly cancels the `\hskip\labelsep` the head box
starts with. The head therefore sits flush on the left margin: the oracle
PDF puts "Proof" at x=72.000, we put it at 88.936 (= +17pt = \parindent).
Only the *following* paragraphs of the environment take the ambient
`\parindent`, which the oracle confirms ("Uniqueness." at x=88.936).
2. The head font (`\bfseries` for the `plain`/`definition` styles, `\itshape`
for `remark`/`proof`) and the `plain` style's italic body are declared by
amsthm, not written in the source at the head's span -- which is the
`\begin` command itself -- so `style_at` read the enclosing (regular) style
and the whole theorem was set from the regular face.
`\hbox{\bfseries Definition 3.1.}` is 77.85793pt; we produced 69.41731pt.
Weights now come from the compiler's own scoping inside a theorem-like
environment (the existing `compiler_weight` path, threaded through
`items_cached` and its key).
3. The blank inside synthesised head text ("Definition 3.1") was shaped as a
character -- the T1 slot-32 glyph, 5.44394pt and rigid -- instead of the
space *token* it stands for. It is now interword glue in the font in force,
which for the bold head is `4.17043pt plus 2.08443 minus 1.3896`, exactly
pdflatex's. Scoped by the existing `exact` flag, so the source's own bytes
(verbatim included) keep a literal blank.
Evidence, all on this NixOS host with the bundled fonts and no font
diagnostics on any run:
* lecture-notes: all three break differences gone, no new ones. Line-by-line
against the oracle PDF 44/51 -> 50/51; the single residual is the
pre-existing `B\'ezout` accent-composition artifact, which puts the same
words on the same line. 0 overfull. Word geometry vs the reference PDF:
mean |dx| 11.6194 -> 1.4566 bp, median 2.0880 -> 0.0950 bp, words within
0.5 bp 137 -> 263, max 452.94 -> 102.20.
* HW1 and HW2 display lists byte-identical to origin/main, as are cv,
inline-math, input-bibliography, letter, math-sheet and unicode-accents.
* article-twocolumn: no line break moves; the `\cite` separator becomes glue
instead of the slot-32 glyph (the oracle sets "[1,2]." with no gap at all,
since the `cite` package compresses it, so glue is the closer of the two).
Median |dx| unchanged at 0.0042 bp, words within 0.5 bp 201 -> 203.
* amsmath oracle corpus: 59/59 within 0.5 bp.
* `cargo test --release --no-fail-fast` on crates/render-pipeline WITH fonts
configured: 163 passed / 8 failed, against an origin/main control in the
same worktree at 162 passed / 8 failed -- the identical failing set (the
partial-font control tests contaminated by the global env), plus the new
test here.
Known deviations left, neither of which moves a break in this corpus: the
head's trailing punctuation is emitted by the compiler with the default style
where amsthm sets it in the head font, and the head-to-body separator is a
sentence space where amsthm uses its `headspace` (`5pt plus1pt minus1pt` for
`\newtheorem` styles) and `proof` uses `\hskip\labelsep` (5.475pt, rigid).
Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary
Commit-Executor: engine-engineer (Claude Opus 5), direct git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…ecture-notes-trivlist-breaks
This was referenced Sep 13, 2026
GoKubar
marked this pull request as ready for review
September 13, 2026 23:36
GoKubar
added a commit
that referenced
this pull request
Sep 14, 2026
… a space
The gap between a theorem-like head and its body was an interword space read
from the source newline after `\begin{...}` — and because the head ends in
`.`, a *sentence* space (`4.83948 plus 5.44014 minus 0.40297` at 11pt).
amsthm puts its own glue there and then `\ignorespaces`.
Measured against pdflatex (TeX Live 2025, oracle only, never in the product
path), `\documentclass[11pt]{article}` + `[T1]{fontenc}` + amsthm with
`\tracingoutput=1`:
* a `\newtheorem` environment's head ends with `\hskip\thm@headsep`
(amsthm.sty `\@begintheorem`), `\thm@headsep = 5\p@ plus\p@ minus\p@`.
The shipped page: `\T1/cmr/bx/n/10.95 .`, `\glue 5.0 plus 1.0 minus 1.0`,
then the body. It is absolute — the same 5pt at 10, 11 and 12pt — and it
stretches, which a sentence space's five-times-larger stretch does not
reproduce on a line that is set loose;
* `proof` is not a `\newtheorem` style but a plain `\trivlist` `\item
[\hskip\labelsep \itshape #1\@addpunct{.}]`, so the glue after its label
is the `\hskip\labelsep` `\@item` appends after the label box, rigid:
`\hbox(7.60416+2.12917)x67.05003` then `\glue 5.475` then `\penalty 0`.
`\showthe\labelsep` prints 5.0pt / 5.475pt / 5.87494pt at 10 / 11 / 12pt,
which is what `flashtex_document_style::list_level` already resolves.
New `src/amsthm.rs` recognises the head from the compiler's own output
rather than from a `\newtheorem` scan: `parser::begin_theorem`/`begin_proof`
are the only places that give a synthesised `Inline::Text` the span of a
`\begin` control word. It returns the glue and the byte the head ends at
(past `{<env>}` and any `[<note>]`); `items_from_inlines_styled` emits that
glue in place of the gap before the first inline at or after it, so the
source's own whitespace is dropped exactly as `\ignorespaces` drops it —
`\begin{theorem}Body`, `\begin{theorem}\n Body` and
`\begin{theorem}\label{k}\n Body` all give the same head (`\label`'s
`\@esphack` takes the glue off and puts it back with `\ignorespaces`).
`Item::HSpace` grows `stretch_pt`/`shrink_pt` and becomes `Glue::finite`
rather than `Glue::fixed`; `\hspace` keeps passing 0/0 and is unchanged.
## Gates
NixOS host, bundled `apps/mac/Fonts` with the explicit `FLASHTEX_TFM_DIRS`
spelling that reaches the rooted metrics reader; never the system TeX Live.
Real-world corpus, v2 display lists against an `origin/main` control: nine of
ten fixtures **byte-identical** (hw1, hw2, cv, inline-math,
input-bibliography, letter, math-sheet, unicode-accents, article-twocolumn),
`lecture-notes` the only one that moves. Its diagnostics are byte-identical
too (8, none of them a font substitution, 0 overfull); every status and page
count unchanged.
`lecture-notes` word geometry against the committed `reference.pdf`
(difflib-aligned words, |dx| in bp). The head is only *exact* with all three
parts in place, and the errors partly cancel, so every combination is
measured:
| build | median |dx| | ≤0.01 bp | ≤0.1 bp | ≤0.5 bp | lines |
|---|---|---|---|---|---|
| `main` | 7.6051 | 116 | 125 | 138 | 32/56 |
| + this PR | 7.2493 | 116 | 125 | 138 | 32/56 |
| + #190 | 0.1366 | 174 | 199 | 285 | 38/56 |
| + #190 + this PR | 0.0305 | 199 | 245 | 340 | 38/56 |
| + #190 + this PR + the compiler PR | **0.0048** | **235** | **284** | 339 | 38/56 |
No line is lost in any combination, and the 419 aligned words and the
`max |dx|` (112.737 bp, the pre-existing math-run/extraction outliers) are
the same throughout.
On the fixture's own `Definition 3.1.` line, body start against the oracle's
155.3717 bp: `main` + #190 155.8772 (+0.5055), with this PR 154.9534
(−0.4183), with the compiler PR as well **155.3744 (+0.0027)** — and the
whole rest of that line then lands inside 0.06 bp.
`cargo test --release --no-fail-fast` on `crates/render-pipeline`, with the
font environment: see the PR description for the failing-set comparison
against an `origin/main` control of the same base.
Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary
Commit-Executor: engine-engineer (Claude Opus 5), direct git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
This was referenced Sep 15, 2026
GoKubar
deleted the
agent/linux-primary/lecture-notes-trivlist-breaks
branch
September 16, 2026 04:17
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.
Closes the remaining line-break differences in
fixtures/real-world/lecture-notesagainst pdflatex.None of them is a breaker bug. Our Knuth–Plass implementation agrees
with TeX's own feasible breakpoints once it is fed the same horizontal list;
what differed was the content of the theorem lines. Two content errors were
partly cancelling each other —
+17ptof spurious indent against~8.4ptofmissing head width — which is why only 3 of 45 lines showed it, and why fixing
either one alone makes the fixture worse (measured: indent-only goes 44/51 →
46/51 but breaks the
Example 1.2line that used to match).Method
pdflatexas an oracle only, TeX Live 2025, never in the product path.\tracingparagraphs=1on the whole fixture,\showboxon the paragraphs ofinterest,
\showthefor the individual dimensions, plus a temporaryTeX-format trace in our own breaker (reverted; nothing under
crates/render-pipeline/vendor/is committed).Every paragraph of this document is resolved in
@firstpass— no second pass,no hyphenation, no
\emergencystretch. So\tolerance, hyphenation and theemergency pass were never in play.
The cases
3. "Proof sketch. Run the Euclidean algorithm…" (prose only)
TeX's trace finds exactly one feasible break on line 1, after integer, at
b=0 p=0 d=100. We break after "is an" instead. The oracle line is66.56969 + 404.93347 = 471.50316ptagainst\hsize469.75502pt— itshrinks by
1.74814pt,r = −0.124, badness 0. We had17ptless room, so"integer" could not fit at all.
\trivlistleaves\itemindentat\z@(\showthe\itemindentinside bothproofandtheoremprints0.0pt), and\@item's\everypartakes the\parindentbox back off the first line (\setbox\z@\lastbox) beforeunboxing
\@labels, whose leading\hskip\itemindent \hskip-\labelwidth \hskip-\labelsepis-\labelsephere and exactly cancels the\hskip\labelsepthe head box begins with. The head sits flush on the leftmargin: the oracle puts
Proofatx=72.000, we put it at88.936(
= +17pt). Only the following paragraphs of the environment take theambient
\parindent— the oracle confirms this too (Uniqueness.atx=88.936), and we already agreed there.2. "…as in Theorem 2.1. Then", and 4. "The set is non-empty take"
Same mechanism (case 4 is the one that appeared on
mainafter the brief). TeX has two feasible breaks: afterTheorem 2.1.atb=19 d=841and afterThenatb=3 d=169, and takes the second (t=269vs941). With17ptless measure theThenbreak is not feasible for us atall.
1. "…with$d \mid a$ and $d \mid b$ . We"
Not the indent — this paragraph follows a
\section, so both sides alreadystart at
x=72. TeX's two candidates are the break after the period(
b=2 d=144, stretching, glue set0.2667) and the break afterWe(
b=4 d=196, shrinking), and it takes the cheaper first one fort=244.We computed
b=7andb=0and took the second.\showboxgives the oracle's line exactly: natural456.03478pt, stretch51.44446pt. Ours was natural447.32712, stretch53.80032— a constant8.70766pttoo narrow, identical at both candidate breaks, i.e. one item, nota per-space error. Component-by-component against
\showthe\wd:Definition 3.1.For,not,both,zero,,is,the,largest,with,and,We2e-5 pt$a, b \in \Z$$\gcd(a, b)$$d \mid a$/$d \mid b$So the head box alone accounts for
8.44062of the8.70766. Two causes:(
\bfseries;\itshapeforremark/proof) and theplainstyle's italicbody — none of it appears in the source at the head's span, which is the
\begincommand itself, sostyle_atread the enclosing style. The wholetheorem, head and body, came out in
LMRoman10-Regular.the T1 slot-32 glyph,
5.44394pt, rigid — rather than the space token itstands for (
4.17043pt plus 2.08443 minus 1.3896in the bold face).Changes
theorem_environments/opens_theorem_item: a paragraph that opens a\newtheorem-declared environment orproofis that environment's\item, so it gets no first-line indent.in_theorem_environment: inside such an environment, weights come from thecompiler's own scoping — the existing
compiler_weightpath, threadedthrough
items_cachedand its cache key.exact(synthesised / macro replacement) text becomesinterword glue instead of a character. Scoped by the
exactflag that wasalready computed, so the source's own bytes — verbatim included — keep a
literal blank.
New
tests/theorem_items.rspins the flush head, the oracle's bold head width(
\hbox{\bfseries Definition}=54.2265pt; we now produce54.22656), thehead being two runs rather than one run holding a space character, and the
second paragraph of the environment still taking
\parindent.Gates
All on this NixOS host with the bundled
apps/mac/Fontsand explicitFLASHTEX_TFM_DIRS; no font diagnostic on any run (a fallback run wouldchange every break, so each was checked).
cargo test --release --no-fail-fast, render-pipeline, with fontsAll three residual lines in the 48/51 are text-extraction artifacts with the
same words on the same line, not break differences:
q′/r′primes on twopage-1 lines (the oracle's prime glyph reads as
0, ours carries no ASCIItext) and the pre-existing
B\'ezoutaccent composition.The control was an
origin/maincheckout ofadapter.rsin this sameworktree, per the coordinator's note that the ~8 "with fonts" failures are
partial-font control tests contaminated by the global env rather than ordinary
pre-existing breakage; the signal is the identical failing set.
Left deliberately, with numbers
Neither moves a break anywhere in this corpus, and both belong to amsthm
rendering rather than line breaking:
default style (
begin_theorempushes"."asTextStyle::default()) whereamsthm sets it in the head font — pdflatex shows
\T1/cmr/bx/n/10.95 ..crates/compileris vendored here, so this is thecompiler owner's call.
(
4.83948 plus 5.44014 minus 0.40297, because the head ends in.) whereamsthm uses the
\newtheoremstyleheadspace —\showboxgives\glue 5.0 plus 1.0 minus 1.0— andproof, which is not a\newtheoremstyle, uses\hskip\labelsep=5.475pt, rigid (the oracleputs
Runatx=138.326, i.e.66.56969ptfrom the margin, which isexactly
\labelsep + \wd{\itshape Proof sketch.}=5.475 + 61.09468).Draft because the amsthm head is now correct enough for every break in the
corpus but not yet exact; the two items above are the remaining known gap.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu