Skip to content

render-pipeline: a float body is typeset, not re-scanned for four commands - #357

Merged
GoKubar merged 4 commits into
mainfrom
agent/nixos-floats/float-body-typeset
Sep 14, 2026
Merged

GoKubar merged 4 commits into
mainfrom
agent/nixos-floats/float-body-typeset

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

The bug

A float's body was re-scanned from the raw source for four commands.
floats::pieces matched \includegraphics, \caption, \label and
\centering; everything else became Piece::Other, which prepare
reported as float_content_unsupported — a warning — and dropped. A
tabular inside \begin{table} rendered as a caption with zero rules
and no cells
.

Measured on the real-world corpus against a control build of origin/main
@ 06007472 in this same worktree and target directory:

float_content_unsupported glyphs in the 7 documents rules
origin/main 10 (10 floats, 7 of 22 documents) 30,049 9
this branch 0 31,016 62

Per document (glyph clusters / rule rectangles, whole document):

document control branch floats recovered
siunitx-tables 3,024 / 0 3,262 / 12 3 (S columns, \multicolumn, \cmidrule)
hyperref-toc 3,814 / 1 3,987 / 21 2 (ruled 3-column and 2-column)
plain-article 3,198 / 0 3,321 / 9 1 (ruled 2-column)
lmodern-report 6,472 / 1 6,601 / 4 1 (booktabs)
lab-report 2,813 / 7 2,928 / 10 1 (siunitx S, booktabs)
conf-paper 7,650 / 0 7,750 / 3 1 (booktabs, math in cells)
article-twocolumn 3,078 / 0 3,167 / 3 1 (booktabs)
total 30,049 / 9 31,016 / 62 10

+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 holds
only \centering, \includegraphics and \caption and never lost
anything. Ten floats, seven documents, is what the diagnostic counts say
on both sides.)

Why the suites did not catch it

The tabular suite 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 figure with a bare \caption. The
suite 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 to
the float's number and page), the alignment declarations, and — until
\includegraphics sets a box in running text, which is #325's subject —
a standalone \includegraphics. Everything else is one maximal
Piece::Content run
, and a blank line inside a run no longer cuts 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::Blocks (the run's
own diagnostics come with them; the rest of the document's do not).
Context::box_blocks sets those blocks through Context::build_paragraph,
which is the Block::Paragraph arm of build_with_floats extracted
unchanged
. 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_box no longer walks a private vertical list of its own. 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, in the
model #343 reconciled.

Four rules of \@xfloat's box the four-command scan never had to model

Each was found by a fixture and each is pinned by one:

  • \@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 opening the body adds no \topsep above
    it, and (TeX §1091) the first paragraph of an empty vertical list adds
    no \parskip. 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: 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, 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 instead of a second copy of the
    list 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 \centering still
reaches a tabular that a \caption between them separates — the
caption-first shape of six of the ten corpus floats.

New gate: tests/float_body_oracle.rs

19 hand-written fixtures in fixtures/float-body/: a ruled multi-column
tabular in a table and in a figure, with and without \centering,
caption above and below; booktabs; prose; two centred paragraphs; an
itemize; a centred itemize; a display; a display opening a paragraph
under a 6pt \parskip; a bare \centering beside a real quote; a
p{} column; \label in tabular cells; \multicolumn + \cline at
12pt; a picture and a table in one float; [t] and [b] bodies on one
page; 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's crates/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_unsupported diagnostics
. Every
fixture fails.

Reference data generated by tools/float-body-oracle/generate.py on
pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025/nixos.org), this host,
as fixtures/float-notes/ already does; reference_engine is recorded in
each file. The MacTeX 2026 data under fixtures/footnotes/ and
fixtures/floats/ is untouched and neither generator was run.

Two reader bugs the new content exposed, fixed rather than worked around:
a \hline and booktabs' \toprule are horizontal strokes, which
page-frame-oracle's scan (vertical strokes and re rectangles) missed
entirely, so a ruled table read as no rules at all; and with a scaled
\includegraphics pdfTeX nests one cm inside another, so a regular
expression over the bytes placed the image — and a translated rule — in
the wrong place. extras_on_page tracks the q/cm stack like the word
reader does.

Gates

gate result
tabular_oracle 106/106
new float_body_oracle 19/19, worst 0.024bp
float_notes_oracle 10/10, worst 0.005bp, 0 diagnostics
footnotes_oracle 35/39, per-fixture numbers identical to the control
amsmath corpus 59/59 within 0.5bp
HW1 / HW2 3 pages each, 0 overfull, 0 errors
real-world corpus, 22 documents float_content_unsupported 10 → 0; page counts unchanged; 0 font diagnostics
cargo test --release -p flashtex-render-pipeline 49 binaries, 229 passed, 0 failed

One new corpus warning, and what it is

plain-article gains one overfull_vbox (page 2, 11.83pt). It is not a
new defect and the branch is closer to pdflatex than the control: on
page 2 pdflatex sets 230 words, origin/main set 266, this branch sets
253. The table is on page 2 in both engines. That document's abstract
environment is unimplemented (compiler warns and sets the body as plain
text), 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-break puts an [h] float with a real body in the
middle 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 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. All five are fixed in 6cfa95c1, and each is
pinned by a fixture that fails without its fix:

defect why it mattered fixture, without → with
A float-level command was matched at any depth, so \label/\includegraphics in a tabular cell cut the run into fragments silent nonsense where the old code at least warned 18-table-commands-in-cells 56/102 → 102/102
\@parboxrestore reached only 2 of 5 block builders — display_opener_block and picture_block kept the page's \parskip/\parindent 0pt under article's defaults, 6pt per block under \setlength{\parskip}{6pt} 19-figure-display-first-parskip 79/123 → 123/123
box_blocks built into the page's block list, so \addvspace compared against an unrelated block a float's \topsep could be swallowed by the page's last block covered by the suite; no fixture reaches the swallow
list_end_skip tested the run's first \begin for vertical mode and counted \centering as material \centering\begin{itemize} lost \partopsep 16-figure-centered-itemize 82/116 → 116/116
the environment-skip strip was all-or-nothing per run a bare \centering beside a real quote kept ~13pt of phantom \topsep 17-figure-centering-and-quote 63/116 → 116/116

And one silent-loss case the review caught that no fixture can pass yet: a
\footnote inside a float body is raised after footnotes::prepare
has run, so its mark was set and its text never placed, with nothing said.
It now reports float_footnote_unplaced and the orphaned note is dropped
rather than left dangling.

What a float body still cannot contain

  • \includegraphics anywhere but on a line of its own. A picture
    inside a paragraph, a tabular cell or a list item is dropped — not by
    this route but by adapter.rs, whose Inline::Graphic arm pushes no
    item 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-\includegraphics special case here can go with it, and the
    float 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/main has neither adapter::Item::Graphic nor the
    \includegraphics*/two-bracket handling its description describes, so
    this branch is based on plain origin/main and does not depend on it.)
  • A declaration other than the alignment ones separated from its content
    by a \caption or a \label.
    \centering, \raggedright and
    \raggedleft are carried across; {\small ...} before the caption does
    not reach a tabular after it. In the same run — \centering\small\begin {tabular} — it works.
  • Page-level material: a sectioning command, \chapter, \part,
    \maketitle, \clearpage, a page-style command, a contents list or a
    longtable in a float body is reported (float_content_unsupported,
    now naming the construct) and omitted. LaTeX forbids or breaks on all of
    them there.
  • A float body narrower than \columnwidth — figure* in a
    two-column document, or a minipage of 0.45\linewidth — is still set
    at \columnwidth. Width is Stylesheet::text_width_pt throughout
    line_params and table_measure; threading a box width is a separate
    change and minipage is not implemented at all yet
    (footnotes::MinipageNotes documents the same gap).
  • \@makecaption's two-line form under a \hsize that is not the text
    width
    , for the same reason.
  • A \footnote: reported (float_footnote_unplaced), not placed —
    footnotes::prepare runs before the float boxes are set.
  • A \label inside the body's own content (a tabular cell): it does
    not resolve. A \label at the float's level does, and takes the
    caption'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

GoKubar and others added 3 commits September 14, 2026 04:10
…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
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