Repository navigation
render-pipeline: a float body is typeset, not re-scanned for four commands - #357
Merged
Merged
Conversation
…mands
`floats::pieces` matched `\includegraphics`, `\caption`, `\label` and
`\centering` in the raw source and turned **everything else** into
`Piece::Other`, which `prepare` reported as `float_content_unsupported`
-- a *warning* -- and dropped. A `tabular` inside `\begin{table}` came out
as a caption with no cells and no rules. Ten floats across seven of the 22
real-world corpus documents lost their whole body that way.
The scan now reads only what is *float* semantics rather than content:
`\caption` (numbering, the list of figures), `\label` (it resolves to the
float's number and page), the alignment declarations, and -- until
`\includegraphics` sets a box in running text -- a standalone
`\includegraphics`. Everything else is one maximal `Piece::Content` run,
and blank lines inside a run no longer cut it up: the compiler makes the
paragraph break.
`floats::body_blocks` parses each run the way `caption_items` already
parsed one caption argument (`isolate` the bytes, `parse_project`,
`adapter::adapt`) and hands back ordinary `adapter::Block`s; the run's own
diagnostics come with it, the rest of the document's do not.
`Context::box_blocks` then sets those blocks through
`Context::build_paragraph` -- the `Block::Paragraph` arm of
`build_with_floats`, extracted unchanged so there is one code path for
body content wherever it stands. So a `tabular`, an `itemize`, a display,
a `p{}` cell and a paragraph of prose are set inside a float exactly as
they are outside one, and the sixth construct works for the same reason
the fifth does.
`build_box` no longer walks its own private vertical list. Every part of
the float -- a run of graphics, the body's blocks, `\@makecaption`'s
caption -- becomes a `pagebuild::VBlock`, and the box is
`pagebuild::vlist` + `natural_layout` at natural size: the same interline
glue, `\parskip`, `\topsep` and display skips the page itself uses.
Four rules of `\@xfloat`'s box that the four-command scan never had to
model, each pinned by a fixture:
* `\@parboxrestore` (`Context::parbox`): `\parindent` and `\parskip` zero,
and `\sloppy` -- `\tolerance 9999`, `\emergencystretch 3em` -- the same
values `\@startpbox` already gave a `p{}` cell.
* `\@floatboxreset`'s `\@setminipage`: `\addvspace` does nothing while
`\if@minipage` holds, so a list that opens the body adds no `\topsep`
above it, and (TeX 1091) the first paragraph of the empty list adds no
`\parskip` either. Without this an `itemize` in a float sat 10pt low.
* A bare `\centering` is a declaration, not `\begin{center}`. The adapter
decides that from the bytes before the block, which in an isolated run
are the preamble the isolation kept -- so `\begin{document}` read as an
environment opening and added `\topsep` + `\partopsep` before the body
and again after it. Cleared when the run's own bytes hold no
paragraph-shape environment.
* `\endtrivlist`'s closing `\addvspace\@topsepadd`, which `adapt` gives to
the block *after* the list. A float body's last run has no block after
it -- `\caption` is set by `\@makecaption` and the box then ends -- so
`adapter::list_end_skip` answers it rather than a second copy of the
list parameters deriving it again.
The declarations' own bytes stay in the run that holds them and are
carried into every later run of the same float, so `\centering` still
reaches a `tabular` that a `\caption` between them separates -- the
caption-first shape of six of the ten corpus floats.
Implementation-Agent: claude-opus-5 (linux-primary, float-body lane)
Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
The `tabular` feature suite passes 106/106 and says nothing about any of
this: **none of its 106 fixtures wraps a tabular in a float**, and the two
that contain a float hold an empty `figure` with a bare `\caption`. The
suite and the real documents describe disjoint paths.
`fixtures/float-body/*.tex` are written by hand and checked in (unlike the
other generators here, which emit their own fixtures): a ruled
multi-column `tabular` in a `table` and in a `figure`, with and without
`\centering`, caption above and below; booktabs rules; prose; two centred
paragraphs; an `itemize`; a display; a `p{}` column; `\multicolumn` and
`\cline` at 12pt; a picture and a table in one float; `[t]` and `[b]`
bodies on one page; and an `[h]` float that the page must break around.
`tools/float-body-oracle/generate.py` runs pdflatex over them and records
every word origin and baseline, every rule and every image rectangle from
the PDF's own content streams. **reference_engine: pdfTeX
3.141592653-2.6-1.40.27 (TeX Live 2025/nixos.org)**, this host, as
`fixtures/float-notes/` already uses. The MacTeX 2026 data under
`fixtures/footnotes/` and `fixtures/floats/` is untouched, and neither
generator was run.
Two things the existing readers get wrong once a float body has real
content, fixed here rather than worked around:
* A `\hline` and booktabs' `\toprule` are *horizontal* strokes;
`page-frame-oracle`'s scan keeps the vertical ones and the `re`
rectangles, so a ruled table read as no rules at all.
* With a scaled `\includegraphics` on the page, pdfTeX nests one `cm`
inside another, and a regular expression over the bytes then reads an
image (and a translated rule) at the wrong place. `extras_on_page`
tracks the `q`/`cm` stack like the word reader does.
`tests/float_body_oracle.rs` compares words within 0.5bp and rules and
images within 0.1bp/1bp, and fails on a font-failure, dropped-float or
dropped-content diagnostic. Rules are merged on both sides first, as
`tabular_oracle` does: pdfTeX strokes a `|` once per row, this pipeline
once per `\hline` span, and the ink is the same. Non-ASCII text is
reduced to `?` on our side too, which is what the oracle's T1 reader
writes for the `itemize` bullet.
15 fixtures, 2,377 words, 105 rule and image rectangles: all match, worst
deviation **0.024bp**.
Implementation-Agent: claude-opus-5 (linux-primary, float-body lane)
Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
`box_blocks` consumed the flag on the first `Block::Paragraph` it saw, whether or not that block produced a line. A paragraph with no boxes starts no paragraph, so `\everypar` has not run and `\if@minipage` still holds: a list after it would otherwise lose its `\topsep`. A `tikzpicture` is set in a paragraph and does clear it. No measured change: the float-body, float-notes and tabular gates and all 22 corpus documents are identical either way. This is the case none of them reaches. Implementation-Agent: claude-opus-5 (linux-primary, float-body lane) Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
… the five fixtures that pin them
A review of the branch (Opus, engine-engineer) confirmed the
`Block::Paragraph` extraction is byte-identical to the arm it replaced
(`diff -w` empty over 198 lines) and found five real defects the first 15
fixtures could not reach. Each is fixed here and pinned by a fixture that
**fails without the fix** on the branch as it stood.
**A float-level command is only float-level at the body's own level.**
`pieces()` matched `\includegraphics`, `\caption`, `\label` and the
alignment declarations at any depth, so
\begin{tabular}{cc}A\label{r} & \includegraphics{p} \\ \end{tabular}
inside a `figure` was cut into three content runs -- `\begin{tabular}{cc}`,
`&`, `\\ \end{tabular}` -- each parsed standalone. That is worse than the
old whole-body drop: silent nonsense instead of a warning. The scan now
tracks brace and environment nesting and recognises a float-level command
only outside both. `18-table-commands-in-cells` sets `\label` in two cells
(102/102 words, 9/9 rules); a scan-level unit test pins the
`\includegraphics` case, which cannot be measured against pdflatex until
running-text graphics land. A nested `\includegraphics` is now **reported**
rather than dropped in silence.
**`\@parboxrestore` reached only two of five block builders.**
`display_opener_block` carried the page's `\parskip` and its `\parindent`
box, and `picture_block` carried the page's `\parskip`, into a box where
LaTeX has zeroed both. Invisible under article's `\parskip` of 0pt;
6pt per block under `\setlength{\parskip}{6pt}`, which is common.
`parskip_of` is now the single reading, and the `\parindent` box is empty
in a parbox. `19-figure-display-first-parskip` is 79/123 words without the
fix and 123/123 with it. `\sloppy`'s `\hbadness 10000` is set too.
**`box_blocks` wrote into the page's block list.** `build_paragraph` reads
`blocks.last()` to compare an `\addvspace` against what the previous block
left, and `blocks` was the *page's* vector -- so after a graphics line
(which never reaches it) a float's next run compared its `\topsep` against
the document's last body block, and `endlist_adjust` could have mutated
it. The body now builds into the box's own vector and is appended when it
is done.
**`list_end_skip` tested the wrong `\begin` for vertical mode.** It looked
at the run's first `\begin` rather than the one the closing `\end` matches,
and counted `\centering` as material -- so `\centering\begin{itemize}`
lost `\partopsep` (2pt) from the list's closing glue. An alignment
declaration sets nothing and does not leave vertical mode.
`16-figure-centered-itemize`: 82/116 without, 116/116 with.
**The environment-skip strip was all-or-nothing per run.** A run holding
both a bare `\centering` and a real `\begin{quote}` kept the bogus
`EnvOpen` on the `\centering` paragraph (~13pt of `\topsep` + `\partopsep`
inside the box). The strip is now per block: every block before the run's
first paragraph-shape environment, which is all of them when it has none.
`17-figure-centering-and-quote`: 63/116 without, 116/116 with.
**A `\footnote` in a float body is reported.** `footnotes::prepare` runs
before `floatpage::paginate`, so a note raised while the float box is
being set is never placed: the mark appeared, the text did not, and
nothing said so -- the exact failure mode this branch exists to remove.
It now raises `float_footnote_unplaced` and the orphaned note is dropped
rather than left dangling.
Gates, all re-measured: float-body **19/19** (2,834 words, 114 rectangles,
worst 0.024bp), tabular 106/106, float-notes 10/10, footnotes 35/39,
amsmath 59/59, corpus `float_content_unsupported` 10 -> 0 with no page-count
change and no new diagnostic except the two already reported,
`cargo test --release` 49 binaries, 229 passed, 0 failed.
Implementation-Agent: claude-opus-5 (linux-primary, float-body lane)
Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar
marked this pull request as ready for review
September 14, 2026 08:50
This was referenced Sep 14, 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.
The bug
A float's body was re-scanned from the raw source for four commands.
floats::piecesmatched\includegraphics,\caption,\labeland\centering; everything else becamePiece::Other, whichpreparereported as
float_content_unsupported— a warning — and dropped. Atabularinside\begin{table}rendered as a caption with zero rulesand no cells.
Measured on the real-world corpus against a control build of
origin/main@
06007472in this same worktree and target directory:float_content_unsupportedorigin/mainPer document (glyph clusters / rule rectangles, whole document):
siunitx-tables\multicolumn,\cmidrule)hyperref-tocplain-articlelmodern-reportlab-reportS, booktabs)conf-paperarticle-twocolumn+967 glyphs and +53 rules, page counts unchanged in every one of the
22 documents, and the other 15 documents are identical in page count,
glyph count and rule count. (The brief said eight documents; the eighth
document that contains a float is
thesis-chapter, whose figure holdsonly
\centering,\includegraphicsand\captionand never lostanything. Ten floats, seven documents, is what the diagnostic counts say
on both sides.)
Why the suites did not catch it
The
tabularsuite passes 106/106 and says nothing about any of this:none of its 106 fixtures wraps a tabular in a float, and the only two
that contain a float hold an empty
figurewith a bare\caption. Thesuite and the real documents describe disjoint paths.
What it does
The scan now reads only what is float semantics rather than content:
\caption(numbering and the list of figures),\label(it resolves tothe float's number and page), the alignment declarations, and — until
\includegraphicssets a box in running text, which is #325's subject —a standalone
\includegraphics. Everything else is one maximalPiece::Contentrun, and a blank line inside a run no longer cuts itup: the compiler makes the paragraph break.
floats::body_blocksparses each run the waycaption_itemsalreadyparsed one caption argument —
isolatethe bytes,parse_project,adapter::adapt— and hands back ordinaryadapter::Blocks (the run'sown diagnostics come with them; the rest of the document's do not).
Context::box_blockssets those blocks throughContext::build_paragraph,which is the
Block::Paragrapharm ofbuild_with_floatsextractedunchanged. One code path for body content wherever it stands: the sixth
construct works for the same reason the fifth does, instead of needing its
own arm.
build_boxno longer walks a private vertical list of its own. Every partof the float — a run of graphics, the body's blocks,
\@makecaption'scaption — becomes a
pagebuild::VBlock, and the box ispagebuild::vlist+natural_layoutat natural size. The same interlineglue,
\parskip,\topsepand display skips the page itself uses, in themodel #343 reconciled.
Four rules of
\@xfloat's box the four-command scan never had to modelEach was found by a fixture and each is pinned by one:
\@parboxrestore(Context::parbox):\parindentand\parskipzero, and
\sloppy—\tolerance 9999,\emergencystretch 3em— thesame values
\@startpboxalready gave ap{}cell.\@floatboxreset's\@setminipage:\addvspacedoes nothing while\if@minipageholds, so a list opening the body adds no\topsepaboveit, and (TeX §1091) the first paragraph of an empty vertical list adds
no
\parskip. Without this anitemizein a float sat 10pt low.\centeringis a declaration, not\begin{center}. Theadapter decides that from the bytes before the block, which in an
isolated run are the preamble the isolation kept — so
\begin{document}read as an environment opening and added
\topsep + \partopsepbeforethe body and again after it: every centred float was 10pt low and its
caption 20pt low. Cleared when the run's own bytes hold no
paragraph-shape environment.
\endtrivlist's closing\addvspace\@topsepadd, whichadaptgivesto the block after the list. A float body's last run has no block
after it —
\captionis set by\@makecaptionand the box then ends —so
adapter::list_end_skipanswers it instead of a second copy of thelist parameters re-deriving it.
The declarations' own bytes stay in the run that holds them and are
carried into every later run of the same float, so
\centeringstillreaches a
tabularthat a\captionbetween them separates — thecaption-first shape of six of the ten corpus floats.
New gate:
tests/float_body_oracle.rs19 hand-written fixtures in
fixtures/float-body/: a ruled multi-columntabularin atableand in afigure, with and without\centering,caption above and below; booktabs; prose; two centred paragraphs; an
itemize; a centreditemize; a display; a display opening a paragraphunder a 6pt
\parskip; a bare\centeringbeside a realquote; ap{}column;\labelintabularcells;\multicolumn+\clineat12pt; a picture and a table in one float;
[t]and[b]bodies on onepage; and an
[h]float the page must break around.19 fixtures, 2,834 words, 114 rule and image rectangles: all match,
worst deviation 0.024bp. Words within 0.5bp, rules and images within
0.1bp/1bp, and the test fails on any font-failure, dropped-float or
dropped-content diagnostic.
The first 15 of them against
origin/main'scrates/render-pipeline/src(checked out into this tree, same test, same expected data): 1,204 of
2,377 words — the surrounding prose and nothing else — 1 of 105
rectangles, and 16
float_content_unsupporteddiagnostics. Everyfixture fails.
Reference data generated by
tools/float-body-oracle/generate.pyonpdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025/nixos.org), this host,
as
fixtures/float-notes/already does;reference_engineis recorded ineach file. The MacTeX 2026 data under
fixtures/footnotes/andfixtures/floats/is untouched and neither generator was run.Two reader bugs the new content exposed, fixed rather than worked around:
a
\hlineand booktabs'\topruleare horizontal strokes, whichpage-frame-oracle's scan (vertical strokes andrerectangles) missedentirely, so a ruled table read as no rules at all; and with a scaled
\includegraphicspdfTeX nests onecminside another, so a regularexpression over the bytes placed the image — and a translated rule — in
the wrong place.
extras_on_pagetracks theq/cmstack like the wordreader does.
Gates
tabular_oraclefloat_body_oraclefloat_notes_oraclefootnotes_oraclefloat_content_unsupported10 → 0; page counts unchanged; 0 font diagnosticscargo test --release -p flashtex-render-pipelineOne new corpus warning, and what it is
plain-articlegains oneoverfull_vbox(page 2, 11.83pt). It is not anew defect and the branch is closer to pdflatex than the control: on
page 2 pdflatex sets 230 words,
origin/mainset 266, this branch sets253. The table is on page 2 in both engines. That document's
abstractenvironment is unimplemented (
compilerwarns and sets the body as plaintext), so its page-2 line budget already differed; with the float finally
taking its true height the column now reports the overflow instead of
silently carrying extra lines. pdflatex's own log for it has two overfull
\hboxes and no overfull\vbox. The clean case is pinned:15-here-float-page-breakputs an[h]float with a real body in themiddle of a two-page document and matches pdflatex on 710/710 words.
Review round: five more defects, five more fixtures
A code review of the branch (Opus,
engine-engineer) confirmed theBlock::Paragraphextraction is byte-identical to the arm it replaced(
diff -wempty over 198 lines) and found five real defects the first 15fixtures could not reach. All five are fixed in
6cfa95c1, and each ispinned by a fixture that fails without its fix:
\label/\includegraphicsin atabularcell cut the run into fragments18-table-commands-in-cells56/102 → 102/102\@parboxrestorereached only 2 of 5 block builders —display_opener_blockandpicture_blockkept the page's\parskip/\parindent\setlength{\parskip}{6pt}19-figure-display-first-parskip79/123 → 123/123box_blocksbuilt into the page's block list, so\addvspacecompared against an unrelated block\topsepcould be swallowed by the page's last blocklist_end_skiptested the run's first\beginfor vertical mode and counted\centeringas material\centering\begin{itemize}lost\partopsep16-figure-centered-itemize82/116 → 116/116\centeringbeside a realquotekept ~13pt of phantom\topsep17-figure-centering-and-quote63/116 → 116/116And one silent-loss case the review caught that no fixture can pass yet: a
\footnoteinside a float body is raised afterfootnotes::preparehas run, so its mark was set and its text never placed, with nothing said.
It now reports
float_footnote_unplacedand the orphaned note is droppedrather than left dangling.
What a float body still cannot contain
\includegraphicsanywhere but on a line of its own. A pictureinside a paragraph, a tabular cell or a list item is dropped — not by
this route but by
adapter.rs, whoseInline::Graphicarm pushes noitem anywhere in the document. That is render-pipeline: \includegraphics sets a box in running text; \includegraphics* and the two-bracket form on the rendering route #325's subject; when it lands the
standalone-
\includegraphicsspecial case here can go with it, and thefloat route loses its last recognised command. (render-pipeline: \includegraphics sets a box in running text; \includegraphics* and the two-bracket form on the rendering route #325 is open, not
merged:
origin/mainhas neitheradapter::Item::Graphicnor the\includegraphics*/two-bracket handling its description describes, sothis branch is based on plain
origin/mainand does not depend on it.)by a
\captionor a\label.\centering,\raggedrightand\raggedleftare carried across;{\small ...}before the caption doesnot reach a tabular after it. In the same run —
\centering\small\begin {tabular}— it works.\chapter,\part,\maketitle,\clearpage, a page-style command, a contents list or alongtablein a float body is reported (float_content_unsupported,now naming the construct) and omitted. LaTeX forbids or breaks on all of
them there.
\columnwidth—figure*in atwo-column document, or a
minipageof0.45\linewidth— is still setat
\columnwidth. Width isStylesheet::text_width_ptthroughoutline_paramsandtable_measure; threading a box width is a separatechange and
minipageis not implemented at all yet(
footnotes::MinipageNotesdocuments the same gap).\@makecaption's two-line form under a\hsizethat is not the textwidth, for the same reason.
\footnote: reported (float_footnote_unplaced), not placed —footnotes::prepareruns before the float boxes are set.\labelinside the body's own content (atabularcell): it doesnot resolve. A
\labelat the float's level does, and takes thecaption's number.
Scope
crates/render-pipeline/vendor/*untouched; no re-pin is needed.No MacTeX reference data was regenerated.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu