Repository navigation
Conversation
… 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 13, 2026
GoKubar
added a commit
that referenced
this pull request
Sep 14, 2026
The head glue was dropped whenever the body was glued to the `\begin`.
`pending_head_sep` is drained only by `push_gap`, and five of that closure's
twelve callers -- the ordinary text arm among them -- call it only inside
`if has_space`. That is fine for a *replacement*: if the source had a space,
the head glue goes in instead of it. But amsthm's head ends with
`\ignorespaces`, so `\begin{theorem}Body` has no source gap at all, nothing
calls `push_gap`, and the separator is silently discarded. The measured gap
between `Theorem 1.` and the body was 0.00 bp against pdflatex's
`\glue 5.0 plus 1.0 minus 1.0`.
The guard is now `has_space || pending_head_sep.get().is_some()`, so the glue
is emitted on its own when there is no space to substitute for. The three
spellings the module documents now agree exactly, all at `bp(5.0)` =
4.98132 bp:
\begin{theorem}Body
\begin{theorem}\n Body
\begin{theorem}\label{k}\n Body
This is latent in #197 rather than introduced by the rebase: nothing on its
base exercised the no-gap path, because the adapter still invented an
interword space after the `\begin` control word there. `main` stopped doing
that, which is correct, and left the separator with nothing to replace.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar
added a commit
that referenced
this pull request
Sep 14, 2026
render-pipeline: the amsthm head separator is the package's glue, not a space (rebase of #197 + the dropped-separator bug its tests found)
Contributor
Author
|
Closing as superseded — the work is already on Replacement: 8a2b21a same title (PR #267) Closed by the integration lane while clearing a 219-PR backlog (112 of them drafts). If this is wrong, reopen it and tell me — I would rather be corrected than leave stale work buried. — orchestrator-astra (Commander) |
GoKubar
deleted the
agent/linux-primary/amsthm-head-separator-pipeline
branch
September 16, 2026 04:18
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.
Finishes the second of the two amsthm items #190 left deliberately: the
head→body separator is a sentence space where amsthm uses its own glue. The
first (the head punctuation's font) is #196, which is independent and also
based on
main.Together they let #190 leave draft: with all three in place the fixture's
theorem heads are exact rather than merely close (numbers below).
What the gap actually is
pdflatex, TeX Live 2025, oracle only, never in the product path.
\documentclass[11pt]{article}+[T1]{fontenc}+ amsthm,\showboxbreadth=100 \showboxdepth=100 \tracingoutput=1. Two different glues,because
proofis not a\newtheoremstyle:\newtheoremenvironments end the head with\hskip\thm@headsep(amsthm.sty
\@begintheorem), and\newskip\thm@headsep \thm@headsep=5pt plus1pt minus1pt— re-asserted by\@thmfor every style, so all three ofplain/definition/remarkget it:It is absolute — 5.0 pt at 10pt, 11pt and 12pt alike, unlike
\labelsepbelow — and it is glue, not a kern: stretch 1.0, shrink 1.0 are both there
and both matter on a line that is set loose.
proofis\item[\hskip\labelsep \itshape #1\@addpunct{.}], an ordinary\trivlistitem, so the glue after the head is the\hskip\labelsepthat\@itemappends after the label box, and it is rigid:\showthe\labelsepprints5.0pt/5.475pt/5.87494ptat 10 / 11 / 12pt(article's
.5emat class-load size — note 12pt is not 6.0), which isexactly what
flashtex_document_style::list_level(...).labelsepalreadyresolves, so this PR reads it from there rather than inventing a constant.
What we emitted instead 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.40297at 11pt. Wrong width, and more than fivetimes the stretch.
The change
New
src/amsthm.rs. The head is recognised from the compiler's own output,not from a
\newtheoremscan:parser::begin_theorem/begin_proofare theonly places that give a synthesised
Inline::Textthe span of a\begincontrol word, so a block whose first inline is a
Textwhose span coversexactly
\beginand whose text is not those bytes is a theorem-like\item.It returns the glue and the byte the head ends at (past
{<env>}and any[<note>]).items_from_inlines_styledthen emits that glue in place of the gap beforethe first inline at or after that byte. In place of, because the head ends with
\ignorespaces:\begin{theorem}Body,\begin{theorem}\n Bodyand\begin{theorem}\label{k}\n Bodymust all give the same head, and they do —\label's\@bsphack/\@esphacktakes the same glue off and puts it back with\ignorespaces(aInline::Labelcontributes no gap, so the glue simply landsin front of the next real item).
Item::HSpacegrowsstretch_pt/shrink_ptand becomesGlue::finiteratherthan
Glue::fixed;\hspacepasses 0/0 and is unchanged.This needs nothing new from
crates/compiler, so it does not wait on avendor/re-pin. It also merges cleanly with #190 (verified locally:git mergeof both, no conflict) — #190 addstheorem_item/in_theoremto the samefunction and the two do not overlap.
Gates
NixOS host, bundled
apps/mac/Fontswith the explicitFLASHTEX_TFM_DIRSspelling that reaches the rooted metrics reader; never the system TeX Live.
Real-world corpus, v2 display lists against an
origin/maincontrol: nineof ten fixtures byte-identical (hw1, hw2, cv, inline-math,
input-bibliography, letter, math-sheet, unicode-accents, article-twocolumn),
lecture-notesthe 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. amsmath oracle corpus 59/59 within 0.5 bp.
cargo test --release --no-fail-fastoncrates/render-pipeline, with thefont environment: 187 passed / 8 failed here; the
origin/maincontrol ofthe same base is 181 / 10, and the two failing sets are identical apart from
the two new tests in this PR, which fail on the control because they measure
exactly what it does not do yet:
(+6 passing = 2 new integration tests + 4 new
amsthmunit tests. Several ofthose 8 are the known partial-font control tests that a global
FLASHTEX_TFM_DIRScontaminates, which is why the set, not the count, is thesignal, and the same 8 fail with or without
FLASHTEX_LM_DIRexported — theenv spelling CI uses.)
lecture-notesword geometry against the committedreference.pdf(difflib-aligned words, |dx| in bp, 419 aligned words and
max |dx|112.737 inevery row — the pre-existing math-run/extraction outliers):
main(Line counts are this script's own grouping — words grouped by page and
baseline, compared with
difflib— so 56 rather than #190's 51; the point isthat no line is lost in any combination, and none is gained: the residual
line differences are the extraction artifacts #190 documented.)
On the fixture's
Definition 3.1.line, body start against the oracle's155.3717 bp:
main+ #190 155.8772 (+0.5055), with this PR 154.9534(−0.4183), with #196 as well 155.3744 (+0.0027) — and the rest of that
line then lands inside 0.06 bp. Two errors of opposite sign again, exactly as
#190 warned; neither of these two PRs should be judged alone on this fixture.
No committed oracle data was regenerated — this box is TeX Live 2025, not
MacTeX. Nothing under
crates/render-pipeline/vendor/is committed.Merge order
#190→ this PR gives the fixture's theorem heads their correct glue;#196(compiler) needs avendor/compilerre-pin after it merges before itshalf is visible here. All three are based on
mainand none conflicts withanother.
Left
proofhead is a box in TeX (\box\@labels), so the interword spaceinside
Proof sketch.does not stretch with the line; ours does. Worth~1.4 pt on a loose line and not addressed here.
\penalty 0after\box\@labels— our rigid glue is already a legalbreakpoint of the same cost, so the difference is only which side keeps the
5.475 pt if a break ever lands there.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu