Repository navigation
render-pipeline: natbib's bibliography hangs at \bibhang, and its own spaces are control spaces - #381
Merged
Merged
Conversation
…wn spaces are control spaces
Three things the pipeline had to learn once the compiler started setting
natbib citations (companion PR, `crates/compiler`). Each is a separate
measured defect; together they take `natbib-review` from **257 reflowed words
across three pages to 0**.
**1. `thebibliography` under natbib author-year is a hanging indent, not a
label-width one.** natbib's `\@bibsetup` is `\NAT@bibsetup` (natbib.sty 642):
`\leftmargin\bibhang` (`1em`, line 638) and `\itemindent-\leftmargin`, and its
`\@biblabel` is `\hfill` — no label at all. The class rule the pipeline used
(`\settowidth\labelwidth{\@biblabel{99}}`) put every entry **22.42 bp too far
right**; pdfTeX starts each entry flush at the margin and hangs its
continuation lines 10.909 bp in (`\the\bibhang` at 11 pt is 10.95003 pt, the
body font's own `\fontdimen6`; 10.00002 at 10 pt, 11.74988 at 12 pt — so the
new `ListMargin::Em` keeps it in `em` and resolves it against the font rather
than the class's nominal size). `ListGeom::itemindent_em` carries the
`\itemindent` that `\@labels` puts on the item's first line.
This is gated on the entry's marker actually being empty as well as on the
package options, so a build whose compiler still numbers bibliography entries
keeps the class geometry instead of drawing a `[1]` on top of the hanging
indent. The two PRs are therefore safe in either merge order.
**2. Generated citation text is not the source's own bytes.** Every run of a
citation carries the whole command's span, and `\citet{knuthplass1981}` is 22
bytes and sets exactly 22 characters — so the existing `exact` length test
said "this is the source verbatim" and kept the blanks in "Knuth and Plass
(1981)" as **blank glyphs** (LMRoman10's 0.5 em) instead of interword glue
(cmr10's 0.33333 em). That is 1.825 pt too wide per space at 11 pt, and it
accumulates: on the forms probe the word after a three-space citation sat
5.46 bp out, after six spaces 10.91 bp. `generated_citation` recognises the
`\cite` family at the span and excludes it, exactly as `reference_spans`
already excludes `\ref` and `\verb` output.
**3. natbib's own spaces are control spaces.** `\NAT@spacechar` is `\ `
(natbib.sty 596) and the note's gap is normally a tie (`p.~7`), so the space
factor of the character in front of them does not widen them. Ours were space
*tokens*, so a `.` set `\spacefactor` to 3000 and added `\fontdimen7`: 1.2167
pt at 11 pt, which is exactly where "Jones et al. (1990)" and
"(… , 1981, p. 7)" put a period in front of a space. Measured +1.216 bp on
every such line before, 0 after.
Measured with `tools/visual-oracle/rank.py` against the pinned TeX Live 2025
reference, `FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` at `apps/mac/Fonts`, zero
font-FAILURE diagnostics:
| `natbib-review` | before | after |
|---|---|---|
| page 1 reflowed / max \|dx\| | 89 / 450.39 bp | **0 / 18.48 bp** (a math display, not a citation) |
| page 2 reflowed / max \|dx\| | 108 / 446.79 bp | **0 / 0.91 bp** |
| page 3 reflowed / max \|dx\| | 60 / 390.30 bp | **0 / 1.51 bp** |
| page median shift (dx, dy) | (-0.21, -14.12) / (0.00, -27.10) / (+68.41, -22.52) | **(0.00, 0.00)** on all three |
| words within 0.5 bp | 15 / 1 / 1 | **277 / 416 / 59** |
A 32-form probe (`\citet`, `\citep`, both starred, `[pre][post]` in every
combination, `\citealt`, `\citealp`, `\citeauthor`, `\citeyear`,
`\citeyearpar`, `\cite`, multi-key, same-author, undefined, `\Citet`,
`\citetext`, `\citefullauthor`, long author lists) aligns **201/201** words
against pdfLaTeX with max |dx| 0.914 bp and 181 of them within 0.01 bp.
What is left, and why it is not chased here: the 0.914 bp is natbib's
`\NAT@nmfmt{\NAT@nm}` **group**, which ends pdfTeX's ligature/kern chain, so
`{Hobby},` keeps the `y,` kern that `Hobby,` loses — `\showthe\wd` of the two
is 34.37088 pt vs 33.45836 pt at 11 pt. Reproducing it needs a kern boundary
inside a word, which the display list has no way to express today; it moves
no line break in any fixture.
The `min-natbib` divergence probe goes from 29 reflowed words and a median
+60.58 bp to **0 reflowed, max |dx| 0.03 bp** (51 of 52 reference words
aligned); `min-newblock` next to it is unchanged at 0.03 bp.
`crates/render-pipeline`: 246 tests pass, 0 fail, 1 ignored with fonts
configured, against the **pinned** vendor — 96 lib tests, was 94. HW1 and HW2
through `flashtex-render`: 3 pages, 0 errors, 0 overfull each, identical to
the control build made in this same directory from `cc3232b4`. amsmath oracle
corpus 59/59, tabular 106/106.
Whole real-world corpus (57 compared pages, same harness and same directory
for both builds): **8 pages better, 0 worse, 49 unchanged.**
`natbib-review`'s three pages move from ranks 1-3 of 60 to 45/55/58, and
`thesis-chapter` — the corpus's other natbib document — comes along with
them: 200 reflowed words across its first four pages down to 1, max |dx|
424.09/435.00/426.51/436.21 bp down to 10.61/7.03/426.26/5.93.
The citation text itself comes from `crates/render-pipeline/vendor/compiler`,
a frozen pin: **a vendor re-pin is needed** for any of the numbers above to
appear in a build from this branch alone. The pin is byte-identical to
`crates/compiler` on main apart from its `PIN` file, so the re-pin is
mechanical; every measurement here was taken with it applied locally and not
committed.
Implementation-Agent: Claude Opus 5 (lane linux-natbib, 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
This was referenced Sep 14, 2026
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]>
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.
Companion to #380 (
crates/compiler, natbib citations). Three separate, separately measured defects the pipeline had once the compiler started setting natbib citations. Together they takenatbib-reviewfrom 257 reflowed words across three pages to 0, andthesis-chapterfrom 200 across its first four pages to 1.1.
thebibliographyunder natbib author-year is a hanging indentnatbib's
\@bibsetupis\NAT@bibsetup(natbib.sty 642):\leftmargin\bibhang(1em, line 638),\itemindent-\leftmargin. Its\@biblabelis\hfill— no label at all. The class rule the pipeline used (\settowidth\labelwidth{\@biblabel{99}}) put every entry 22.42 bp too far right. pdfTeX starts each entry flush at the margin and hangs the continuation lines 10.909 bp in:\the\bibhangmeasured from pdfLaTeX: 10.00002 pt at 10 pt, 10.95003 at 11 pt, 11.74988 at 12 pt — the body font's own\fontdimen6, not the class's nominal size. The newListMargin::Emkeeps it inemand resolves it against the font at typeset time;ListGeom::itemindent_emcarries the\itemindentthat\@labelsputs on the item's first line.Gated on the entry's marker actually being empty as well as on the package options, so a build whose compiler still numbers bibliography entries keeps the class geometry instead of drawing a
[1]on top of the hanging indent. The two PRs are therefore safe to merge in either order.2. Generated citation text is not the source's own bytes
Every run of a citation carries the whole command's span, and
\citet{knuthplass1981}is 22 bytes and sets exactly 22 characters — so theexactlength test said "this is the source verbatim" and kept the blanks in "Knuth and Plass (1981)" as blank glyphs (LMRoman10's 0.5 em) instead of interword glue (cmr10's 0.33333 em). 1.825 pt too wide per space at 11 pt, and cumulative: on a probe, the word after a three-space citation sat 5.46 bp out, after six spaces 10.91 bp.generated_citationrecognises the\citefamily at the span and excludes it, exactly asreference_spansalready excludes\refand\verboutput.3. natbib's own spaces are control spaces
\NAT@spacecharis\(natbib.sty 596) and the note's gap is normally a tie (p.~7). Both are control spaces, so the space factor of the character in front of them does not widen them. Ours were space tokens, so a.set\spacefactorto 3000 and added\fontdimen7— 1.2167 pt at 11 pt, and "Jones et al. (1990)" and "(…, 1981, p. 7)" are exactly where a period sits in front of a space. Measured +1.216 bp on every such line before, 0 after.Measurements
tools/visual-oracle/rank.py, pinned TeX Live 2025 references,FLASHTEX_FONT_DIRS/FLASHTEX_TFM_DIRSatapps/mac/Fonts, zero font-FAILURE diagnostics. Control built from the merge basecc3232b4in the same directory as the branch build.natbib-reviewmin-natbibdivergence probe: 29 reflowed words and a median +60.58 bp → 0 reflowed, max |dx| 0.03 bp (51 of 52 reference words aligned).min-newblocknext to it unchanged at 0.03 bp.A 32-form probe (
\citet,\citep, both starred,[pre][post]in every combination,\citealt,\citealp,\citeauthor,\citeyear,\citeyearpar,\cite, multi-key, same-author, undefined,\Citet,\citetext,\citefullauthor, long author lists) aligns 201/201 words against pdfLaTeX, max |dx| 0.914 bp, 181 within 0.01 bp.Reference convergence
Because a bibliography's labels come from the
.aux, the pinned references were re-checked rather than assumed:natbib-review,thesis-chapterandmin-natbibwere rebuilt for four passes each. Pass 2 = pass 3 = pass 4, byte-identical to the pinnedreference.pdfin all three (sha256205caefb2116,329ed1f9c8e1,f620b8b22a18— the values in eachreference.json), and no "Rerun to get …" warning from pass 2 onward. The references are converged; nothing here is measured against a stale label.Gates
crates/render-pipeline: 246 pass, 0 fail, 1 ignored with fonts configured, against the pinned vendor — 96 lib tests, was 94.flashtex-render: 3 pages, 0 errors, 0 overfull each, identical to the control build.natbib-review's pages move from ranks 1-3 of 60 to 45/55/58;thesis-chapterp1-p4 max |dx| 424.09/435.00/426.51/436.21 bp → 10.61/7.03/426.26/5.93.Both the control and the branch runs were re-executed from the pushed commits after a shared-
refs/stashincident on this checkout, and reproduce page-for-page.A vendor re-pin is needed
The citation text comes from
crates/render-pipeline/vendor/compiler, a frozen pin, so none of the numbers above appear in a build from this branch alone. The pin is currently byte-identical tocrates/compileronmainapart from itsPINfile, so the re-pin to #380 is mechanical. Every measurement here was taken with it applied locally and not committed.What remains
The 0.914 bp residual is natbib's
\NAT@nmfmt{\NAT@nm}group, which ends pdfTeX's ligature/kern chain:{Hobby},keeps they,kern thatHobby,loses.\showthe\wdof the two at 11 pt is 34.37088 pt vs 33.45836 pt. Reproducing it needs a kern boundary inside a word, which the display list cannot express today; it moves no line break in any fixture.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu