Skip to content

render-pipeline: the amsthm head separator is the package's glue, not a space (rebase of #197 + the dropped-separator bug its tests found) - #267

Merged
GoKubar merged 3 commits into
mainfrom
rebase/197-amsthm-head-separator
Sep 14, 2026
Merged

GoKubar merged 3 commits into
mainfrom
rebase/197-amsthm-head-separator

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Rebase of #197 onto current main (its base is 140 commits back, not 40), plus the real bug that its two failing tests were pointing at. Supersedes #197 — its branch is untouched.

The construct work is unchanged from #197: the amsthm head→body gap is \hskip\thm@headsep (5pt plus1pt minus1pt, absolute) for a \newtheorem environment and \hskip\labelsep for proof, not the sentence space the adapter used to read from the source newline. See #197 for the \tracingoutput evidence.

The two failing tests: one was a false alarm, one was not

4.155 vs 4.981 was the test, not the engine. gap_after(words, "Theorem") took the first run starting with Theorem and measured to the next run on its line. The head is not one run — Theorem 1. is the name and the stepped counter, painted as separate runs with their own source spans — so it was measuring the ordinary interword space in front of the counter (cmbx10's space at 10.95pt is 4.155 bp). Read straight off the v2 display list, the separator is exact:

head ends body starts gap expected
Theorem 1. 188.354 bp 193.335 bp 4.98132 bp \thm@headsep 5 pt = 4.98132
Proof. 154.300 bp 159.755 bp 5.45456 bp \labelsep 5.475 pt = 5.45456

The test now walks forward over the head's runs until one ends with \the\thm@headpunct.

The same line case was a genuine bug — the separator was dropped entirely. pending_head_sep is drained only by push_gap, and five of that closure's twelve callers call it only inside if has_space. That is right for a replacement, but amsthm's head ends with \ignorespaces, so \begin{theorem}Body has no source gap, nothing calls push_gap, and the glue vanished: measured gap 0.00 bp. The guard is now has_space || pending_head_sep.get().is_some().

This is latent in #197 rather than caused by the rebase — on its base the adapter still invented an interword space after the \begin control word, so there was always something to replace. main correctly stopped doing that, leaving the separator with nothing to substitute for. The three spellings the module documents now agree exactly, all at 4.98132 bp:

\begin{theorem}Body
\begin{theorem}\n Body
\begin{theorem}\label{k}\n Body

Gates, measured on this tree

Control is main @ 5e6c65be with its committed vendor pin; this branch needs no re-pin (it adds nothing to crates/compiler).

gate control this branch
crates/render-pipeline cargo test --release 213 passed, 0 failed 219 passed, 0 failed
amsmath corpus 59/59 59/59
tabular corpus (oracle.py check) 59/59 59/59
font diagnostics over both corpora 0 0
real-world corpus, all 10 fixtures — identical to control: every page count, status and diagnostic count unchanged
real-world corpus, HW1 / HW2 render 3 pages, 0 errors, 0 overfull 3 / 3 pages, 0 errors, 0 overfull

The +6 are exactly what #197 predicted: 2 new integration tests + 4 new amsthm unit tests.

#197's own control numbers no longer describe this repo. It reported 187 passed / 8 failed against a control of 181 / 10, with the 8 explained as font-environment contamination. On current main the control is 213 / 0 and this branch is 219 / 0 — the font-environment failures are gone (#183 and #193, in that branch's own lineage, have since merged). There is no failing set left to compare, which is a better position than the PR described.

Left, unchanged from #197

  • the proof head is a box in TeX (\box\@labels), so the interword space inside Proof sketch. does not stretch with the line; ours does. Worth ~1.4 pt on a loose line.
  • \penalty 0 after \box\@labels: our rigid glue is already a legal breakpoint of the same cost.

No committed oracle data was regenerated. Nothing under crates/render-pipeline/vendor/ is committed.


Rebased and re-measured against main 5e6c65be. main moved 53 commits during this work, including changes to parser.rs, typeset.rs and mathtex.rs; every number in this PR is from the final tree, not the earlier base.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 13, 2026 22:49
… 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 &#124;dx&#124; | ≤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
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
…he head

`gap_after(words, "Theorem")` took the first run starting with `Theorem` and
measured to the next run on its line. The head is not one run: `Theorem 1.`
is the environment's name and the stepped counter, painted as separate runs
with their own source spans, so the run after `Theorem` is the counter -- with
an ordinary interword space in front of it, not `\thm@headsep`. The test
measured that space, got 4.155 bp (cmbx10's space at 10.95 pt) against an
expected 4.981, and reported a missing separator on a tree whose separator is
in fact exactly right.

It now walks forward over the head's runs until one ends with
`\the\thm@headpunct` and measures from there. `proof`, whose head is the
single run `Proof.`, is unaffected either way.

Verified directly off the v2 display list, 11pt article, bundled Latin Modern:
`1.` ends at 188.354 bp and the body starts at 193.335 -> 4.98132 bp, which is
5 pt exactly; `Proof.` ends at 154.300 and its body starts at 159.755 ->
5.45456 bp, which is `\labelsep` = 5.475 pt exactly.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar
GoKubar force-pushed the rebase/197-amsthm-head-separator branch from 74c7e90 to bf8271b Compare September 14, 2026 02:54
@GoKubar
GoKubar merged commit f9bab2a into main Sep 14, 2026
17 of 20 checks passed
GoKubar added a commit that referenced this pull request Sep 14, 2026
… natbib (#386)

* render-pipeline: re-pin vendor/compiler to main so the corpus can see natbib

`crates/render-pipeline/vendor/*` are frozen `git archive` snapshots, so a
compiler-side change is invisible to `flashtex-render` -- and therefore to the
whole rendered corpus -- until the pin moves. `vendor/compiler` sat at
`f9bab2a7` (PR #267), one `crates/compiler` commit behind: PR #380
(`dd4a9809`, natbib citations and the `\bibitem[Author(Year)]` labels behind
them). #381 had already landed the render-pipeline half against the live
crate, so the corpus's `natbib-review` fixture was being measured against a
pipeline whose vendored compiler still could not parse `\citep`/`\citet`.

Re-exported from `main` at `c1ae760d`:

    git archive c1ae760:crates/compiler | tar -x -C vendor/compiler
    git rev-parse c1ae760 > vendor/compiler/PIN

Byte-identity verified two independent ways: a path/mode/blob-SHA listing of
the vendored tree matches `git ls-tree -r c1ae760:crates/compiler` on all 553
files, and `diff -r --exclude=PIN` against a fresh re-extraction is empty.

PR #385 (hyperref/`\hypersetup` and url.sty URL breaking -- the rebase of the
closed #379) was still OPEN when this pin was taken, so it is deliberately not
carried here: a vendor pin never holds an unmerged branch. It will arrive with
the next re-pin after it merges.

No other vendor directory needed re-pinning, and this was checked rather than
assumed. `crates/compiler`'s own path dependencies at `c1ae760d` are
`font-engine`, `tex-text-encoding`, `tex-boxes` and `tex-expansion`; a
recursive diff of every vendor directory against `main`'s crate of the same
name shows `math-layout`, `paragraph-layout`, `microtype`, `document-style`,
`font-resources`, `tex-text-encoding`, `tex-boxes` and `tex-expansion` already
byte-identical to `main`. `font-engine`, `pdf` and `project-files` do differ,
but each by its own VENDORING.md row's deliberate choice, and none of those
deltas is an API the new compiler needs -- the build and the full test run
below confirm it.

Also noted in the VENDORING.md row: that table's `compiler` and `math-layout`
cells still name `ea4ee5c8`, while the `PIN` files held `f9bab2a7` and
`9a82257b`. The table had drifted behind `PIN`; `PIN` is the authority. Only
the `compiler` row is corrected here, and by prepending -- the old log text is
kept intact.

Gates, all with `FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` set to
`apps/mac/Fonts` and its lm + jknappen/ec + amsfonts/symbols TFM trees:

  cargo test --release on crates/render-pipeline   249 passed, 0 failed, 1 ignored
  amsmath corpus                                   59/59 within 0.5 bp
  tabular corpus                                   106/106 (words 0.5 bp, rules 0.1 bp)
  HW1 render                                       3 pages, 0 errors
  HW2 render                                       3 pages, 0 errors

Zero font-failure diagnostics on either HW document. The only diagnostics are
`math_resource_profile` (4 on HW1, 7 on HW2), which report that Latin Modern
Math supplies one 10 pt design for several optical sizes -- informational, not
a failure, and unchanged by this re-pin.

Implementation-Agent: Claude Opus 5 (lane nixos-vendor-repin, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>

* render-pipeline: move the vendor/compiler pin forward to current main

`main` advanced by 16 commits while the first re-pin was being measured, five
of them in `crates/compiler`, so `c1ae760d` was already stale. Re-exported at
`e44d5917`, which also carries #339 (`\langle`/`\rangle` as U+27E8/U+27E9
mathopen/mathclose -- the corpus's `twelvept-plain` fixture was reporting "no
math glyph for '<'" and drawing an empty box), #321 (`\pagestyle`,
`\thispagestyle`, `\pagenumbering` in the preamble), #244 (`\maketitle`
without `\author`), #314 (`\odot`/`\ominus`/`\oslash`/`\bigcirc` as binary
operators) and #331 (siunitx `S[...]`/`s` columns) on top of #380's natbib.

Byte-identity re-verified at the new SHA the same two ways: the vendored
tree's path/mode/blob-SHA listing matches `git ls-tree -r
e44d591:crates/compiler` on all 555 files, and `diff -r --exclude=PIN`
against a fresh re-extraction is empty.

The no-other-directory-needs-re-pinning finding was re-checked against the new
`main` rather than carried over: `math-layout`, `paragraph-layout`,
`microtype`, `document-style`, `font-resources`, `tex-text-encoding`,
`tex-boxes`, `tex-expansion` and `vector-graphics` are still byte-identical to
`main`'s crates, and `font-engine`/`pdf`/`project-files` still differ only by
their own rows' deliberate choices.

Gates re-run at this pin, same font environment:

  cargo test --release on crates/render-pipeline   254 passed, 0 failed, 2 ignored
  amsmath corpus                                   59/59 within 0.5 bp
  tabular corpus                                   106/106 (words 0.5 bp, rules 0.1 bp)
  HW1 render                                       3 pages, 0 errors
  HW2 render                                       3 pages, 0 errors

Zero font-failure diagnostics on either HW document; the only diagnostics
remain `math_resource_profile` (4 on HW1, 7 on HW2), which are informational.

PR #385 (hyperref/`\hypersetup` and url.sty URL breaking) is still OPEN and so
is still deliberately absent from this pin.

Implementation-Agent: Claude Opus 5 (lane nixos-vendor-repin, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
@GoKubar
GoKubar deleted the rebase/197-amsthm-head-separator 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