Skip to content

render-pipeline: longtable regions through footnote and float pagination - #184

Closed
GoKubar wants to merge 3 commits into
agent/kabir-claude/table-packagesfrom
agent/kabir-claude/longtable-inserts
Closed

GoKubar wants to merge 3 commits into
agent/kabir-claude/table-packagesfrom
agent/kabir-claude/longtable-inserts

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Follow-up to draft #176, which named this as the clear next task: a longtable
was set correctly on a page with footnotes or in a document with floats, but its
region was not carried through break_pages_inserts / floatpage::paginate, so
a break inside such a table lost \endhead/\endfoot. Both diagnostics are now
gone and the region goes through all three page builders.

SHAs

Machine note. NixOS PC, TeX Live 2025, not MacTeX. No committed reference was
regenerated; the eight new fixtures carry TeX Live 2025 in reference_engine.
Every gate ran against the repository's bundled symlink-free font tree
(apps/mac/Fonts plus its three TFM directories) and is asserted free of
font_unavailable / required_metrics_unavailable / ec_metrics_unavailable —
all 106 tabular rows carry zero. cargo test for this crate ran with no
FLASHTEX_* in the environment, as its four without-NewCM control tests require.

Done

Footnotes — break_pages_inserts_regions (34997b8a)

\pagegoal carries both charges at once: \LT@start takes \ht\LT@foot off it
(longtable.sty 229) and TeX's insertion machinery takes \skip\footins and the
notes (§1009), so a note and a continuation foot compete for the same page. The
insertion's own fit-or-split test (§1010) sees the reserved foot too. The head
and foot are materialised as vertical-list items of the page's body rather than
appended afterwards, which is what puts them through \@makecol's natural-size
and glue-setting passes with the rest.

Two behaviours the no-footnote path never needed, both measured, not derived:

  • longtable.sty 223 ends \LT@start with
    \ifdim\pageshrink>\z@\pageshrink\z@\fi: the glue already on the page
    (\parskip, \LTpre's own minus 4pt, \skip\footins's minus 2pt) may no
    longer be shrunk to buy the table one more row. Without it the builder squeezed
    r41 onto the first page of 99-longtable-footnote where pdflatex stops at r40,
    and \@makecol then shrank \LTpre by 1.98 bp to pay for it, lifting the
    whole table.
  • \LT@output's \vss. It builds \box\@cclv as \vbox{\unvbox\@cclv \copy\LT@foot \vss} and only then calls \@makecol (487-517), so the \vss
    sits inside the body ahead of \skip\footins. It takes the column's whole
    slack and pushes the note block to the foot of the page, leaving every finite
    glue natural. Without it the footnote rule sat 11.49 bp too high.

Floats — floatpage::paginate (6f1a89b6)

Same region contract. A node the float machinery splices in reports the list
index of the last real item, so \@specialoutput's own penalties are charged
inside the region like any other.

One behaviour only this path has: \LT@output runs \@makecol\@outputpage \global\vsize\@colroom \copy\LT@head and never \@opcol/\@startcolumn
(513-516), so a page continuing a longtable gets no float page tried and no
deferred float added — the whole column is the table's. With three [t] figures
ahead of a two-page table, topnumber keeps the third off page 1 and pdflatex
does not put it at the top of page 2 either; it stays deferred until
\end{document}'s \clearpage sets it on a float page of its own. Without
start_longtable_column it landed on page 2 and pushed the continuation head
down 40.45 bp.

longtable.sty 489-491 makes a float or marginpar inside the table a LaTeX
error; that is now a targeted table_limitation naming the float, replacing the
blanket "in a document with floats" one.

\LTchunksize — scoped out, with the reason in the code (46dae865)

Explicitly not modelled, documented in longtable.rs. Chunking only ever
narrows a chunk to the widest cell seen so far; longtable writes the final
widths to the .aux (253-259) and warns Column widths have changed, so the
next run sets every chunk at the maximum — which is what measuring the whole
table once already produces. Verified on two shapes: 260 rows with the widest
cell past the default 200-row boundary, and 30 rows with \LTchunksize=5 and the
widest cell in the sixth chunk. Both warn on pass 1, are silent on pass 2, and
their two-pass references match this module's single measurement to the last
decimal. Modelling chunking would only reproduce the unconverged first pass,
which is not what a document renders as.

Three longtable bugs those two fixtures exposed (46dae865)

All measured against pdflatex. None is reachable from #176's own fixtures, which
is why they survived 98/98.

  • \maxdepth\z@ does reach the page a table opens. \LT@start sets it (230)
    on the outer vertical list after \LT@echunk has closed the first chunk but
    before \unvbox\z@ contributes any row, so §987 freeze_page_specs copies the
    zero into page_max_depth exactly when the table's first row is also the
    page's first box. A table under existing material finds it already frozen at
    \@maxdepth, and every later page gets \@maxdepth back from \@makecol — so
    only the page a table opens is affected. render-pipeline: longtable, multirow, cmidrule trims and colortbl fills #176's note that the zero "never
    reaches the page" holds for its own fixtures, all of which have a paragraph
    above the table; 104-longtable-chunk-boundary begins with the table and loses
    one row on page 1.
  • \copy\LT@head, not \box. Without \endfirsthead the opening head is
    \LT@head (239), and without \endlastfoot the closing foot is \LT@foot
    (506), so the same cells are set twice. The piece builder removed each cell's
    block from the map, so the repeated box kept its rules and lost its text: the
    repeated head and foot of every table written with only \endhead and
    \endfoot — a very common shape — were blank.
  • The closing foot does not set \prevdepth. \box\ifvoid\LT@lastfoot \LT@foot\else\LT@lastfoot\fi is inside \LT@output, and the output routine
    builds its own vertical list (§1025 push_nest) whose prev_depth §1026
    discards when it hands the material back to the contribution list. Only
    \LT@start's opening head runs on the outer list, so that is what the table
    leaves behind; with no head at all the value is unchanged, as render-pipeline: longtable, multirow, cmidrule trims and colortbl fills #176 measured. A
    probe running the same table after a paragraph with and without a descender
    puts the following paragraph at the same distance both times — so the value is
    fixed rather than inherited — and 4.34 pt below where \dp\LT@foot would put
    it. render-pipeline: longtable, multirow, cmidrule trims and colortbl fills #176's fixtures all end in \hline\hline, whose depth is zero, so
    Fixed(closing) and Fixed(opening) agreed on every one of them.

Gates

Baseline is #176 @ 18e442f7 with the same vendored compiler, built into a
scratch tree so both sides differ only in this branch's commits.

Gate Baseline (#176 18e442f7) This branch
Tabular oracle, fixtures 1-98 98/98 98/98 (unchanged)
Tabular oracle, fixtures 99-106 0/8 8/8
Tabular oracle, total 98/106 106/106
font_unavailable / required_metrics_unavailable / ec_metrics_unavailable — 0 on all 106
table_limitation 2 shapes reported 0 on all 106
amsmath corpus 59/59 59/59
cargo test --release, crates/render-pipeline (no FLASHTEX_*) 171 171 passed, 0 failed
HW1 / HW2 rendering-v2 display lists 3 pages, 692 / 698 items byte-identical, 0 errors, 0 overfull, 0 font diagnostics
Real-world corpus (--no-oracle --no-pixels) 9 fixtures identical: same status, page count and every diagnostic

The two ec_metrics_unavailable rows in the corpus (article-twocolumn,
input-bibliography, missing ectt* in the bundled jknappen/ec tree) are
present on the baseline too — the pre-existing gap #176 reported, untouched here.

New fixtures (8)

Footnotes: 99-longtable-footnote (two-page table, note on the page the table
starts and breaks on), 100-longtable-footnote-after (note on the page the table
ends on), 101-longtable-footnotes-three-pages (notes on the first and last of
three pages, so a continuation page carries head, rows and foot between two
note-bearing pages).

Floats: 102-longtable-float-top (a [t] figure above a two-page table),
103-longtable-float-deferred (three [t] figures, the third deferred past the
continuation page onto a float page).

Chunking and shapes: 104-longtable-chunk-boundary (210 rows, widest cell past
the default chunk boundary, table opening page 1),
105-longtable-ltchunksize (\LTchunksize=5, widest cell in chunk six),
106-longtable-head-foot-only (\endhead/\endfoot and nothing else).

Known limitations (reported, not silent)

  • Footnotes in a document that also has floats are still dropped with an
    unsupported_block — footnotes::prepare returns None when floats are
    present, so floatpage::paginate never sees an Insertions. That is the
    floats lane's gap, unchanged by this PR and orthogonal to the region work; the
    region is carried through both builders independently, so wiring insertions
    into floatpage is all that is missing to combine them.
  • \LT@start's other branch — \ifdim\pagetotal<\pagegoal\else a \kern\pageshrink \penalty 9999 \kern-\pageshrink (209-212), and \vfil\break when the head,
    first row and foot cannot fit at all (221) — is not modelled. It only matters
    for a table starting on an already-full page.
  • \LT@start's \global\@colroom\@colht (225) discards a float reservation for
    later pages. Not reachable while continuation pages take no floats, but it
    would matter if a longtable ended mid-page and a float then landed on that
    page.
  • \LTchunksize as above: scoped out with evidence, not forgotten.

Next

  1. Re-pin vendor/compiler to compiler: longtable, multirow, booktabs extras and colortbl colours in tables #173 once it merges and drop the local swap.
  2. Insertions through floatpage::paginate, which would close the last combined
    case (footnotes and floats and a longtable).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 13, 2026 13:07
`break_pages_inserts` now takes the same `ResolvedRegion`s that
`break_pages_regions` does, so a longtable on a page with footnotes keeps
`\endhead`/`\endfoot` across a break. `\pagegoal` carries both charges at
once: `\LT@start` takes `\ht\LT@foot` off it (longtable.sty 229) and TeX's
insertion machinery takes `\skip\footins` and the notes (§1009), so a note
and a continuation foot compete for the same page; the insertion's own
fit-or-split test (§1010) sees the reserved foot too.

Two behaviours the no-footnote path never needed, both measured against
pdflatex on the new fixtures:

- longtable.sty 223 ends `\LT@start` with
  `\ifdim\pageshrink>\z@\pageshrink\z@\fi`: the glue already on the page
  (`\parskip`, `\LTpre`'s own `minus 4pt`, `\skip\footins`'s `minus 2pt`)
  may no longer be shrunk to buy the table one more row. Without it the
  builder squeezed r41 onto the first page of 99-longtable-footnote where
  pdflatex stops at r40, and then `\@makecol` shrank `\LTpre` by 1.98 bp to
  pay for it, lifting the whole table.
- `\LT@output` builds `\box\@cclv` as `\vbox{\unvbox\@cclv \copy\LT@foot
  \vss}` and only then calls `\@makecol` (487-517), so the `\vss` sits
  inside the body ahead of `\skip\footins`. It takes the column's whole
  slack and pushes the note block to the foot of the page, leaving every
  finite glue natural. Without it the footnote rule sat 11.49 bp too high.

The head and foot are materialised as vertical-list items of the page's
body rather than appended afterwards, which is what puts them through
`\@makecol`'s natural-size and glue-setting passes with the rest.

The `table_limitation` diagnostic for footnotes is gone; the float one
stays.

Gate: tabular oracle 101/101 with the bundled symlink-free font tree
(`apps/mac/Fonts` plus its three TFM directories), zero
font_unavailable/required_metrics_unavailable/ec_metrics_unavailable
diagnostics on every fixture. Fixtures 1-98 unchanged.

New fixtures (references from local TeX Live 2025, recorded in
`reference_engine`):
- 99-longtable-footnote: two-page table, note on the page the table starts
  and breaks on.
- 100-longtable-footnote-after: note on the page the table ends on.
- 101-longtable-footnotes-three-pages: notes on the first and last of
  three pages, so a continuation page carries head, rows and foot between
  two note-bearing pages.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
`floatpage::paginate` takes the same `ResolvedRegion`s as the other two
page builders, so a longtable in a document with floats keeps
`\endhead`/`\endfoot` across a break. Inside a region the column goal
loses `\ht\LT@foot` and `\pageshrink` is zero (longtable.sty 229, 223);
a break inside one ends the page with `\LT@foot` and opens the next with
`\copy\LT@head`. A node the float machinery spliced in reports the list
index of the last real item, so `\@specialoutput`'s own penalties are
charged inside the region like any other.

One behaviour only this path has, measured against pdflatex on
103-longtable-float-deferred: `\LT@output` runs `\@makecol\@outputpage
\global\vsize\@colroom \copy\LT@head` and never `\@opcol`/`\@startcolumn`
(longtable.sty 513-516), so a page that continues a longtable gets no
float page tried and no deferred float added — the whole column is the
table's. With three `[t]` figures ahead of a two-page table, `topnumber`
keeps the third off page 1 and pdflatex does not put it at the top of
page 2 either; it stays deferred until `\end{document}`'s `\clearpage`
sets it on a float page of its own. Without `start_longtable_column` it
landed on page 2 and pushed the continuation head down 40.45 bp.

longtable.sty 489-491 makes a float or marginpar *inside* the table a
LaTeX error; that is now a targeted `table_limitation` naming the float,
and the blanket "in a document with floats" diagnostic is gone.

Gate: tabular oracle 103/103 with the bundled symlink-free font tree,
zero font/metric fallback diagnostics on every fixture. Fixtures 1-101
unchanged. `cargo test --release` (no `FLASHTEX_*` in the environment):
171 passed, 0 failed, `floats_oracle` included.

New fixtures (references from local TeX Live 2025):
- 102-longtable-float-top: a `[t]` figure above a two-page table.
- 103-longtable-float-deferred: three `[t]` figures, the third deferred
  past the continuation page onto a float page.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…t found

`\LTchunksize` (longtable.sty 65, default 200) is deliberately not
modelled, with the reason and the measurements in `longtable.rs`. Chunking
only ever narrows a chunk to the widest cell *seen so far*; longtable
writes the final widths to the `.aux` (253-259) and warns `Column widths
have changed`, so the next run sets every chunk at the maximum — which is
what measuring the whole table once already produces. Verified on two
shapes: 260 rows with the widest cell past the default 200-row boundary,
and 30 rows with `\LTchunksize=5` and the widest cell in the sixth chunk.
Both warn on pass 1, are silent on pass 2, and their two-pass references
match this module's single measurement exactly. Modelling chunking would
only reproduce the unconverged first pass.

Building those two fixtures turned up three real mismatches, all measured
against pdflatex:

- **`\maxdepth\z@` does reach the page a table opens.** `\LT@start` sets
  it (longtable.sty 230) on the outer vertical list after `\LT@echunk` has
  closed the first chunk but before `\unvbox\z@` contributes any row, so
  §987 `freeze_page_specs` copies the zero into `page_max_depth` exactly
  when the table's first row is also the page's first box. A table under
  existing material finds it already frozen at `\@maxdepth`, and every
  later page of the table gets `\@maxdepth` back from `\@makecol`, so only
  the page a table *opens* is affected — which is why the earlier
  fixtures, all of which have a paragraph above the table, never saw it.
  104-longtable-chunk-boundary begins with the table and loses one row on
  its first page.

- **`\copy\LT@head`, not `\box`.** Without `\endfirsthead` the opening
  head *is* `\LT@head` (239), and without `\endlastfoot` the closing foot
  *is* `\LT@foot` (506), so the same cells are set twice. The piece
  builder removed each cell's block from the map, so the second use — the
  box the output routine repeats — kept its rules and lost its text. The
  repeated head and foot of every table written with only `\endhead` and
  `\endfoot`, a very common shape, were blank.

- **The closing foot does not set `\prevdepth`.** `\box\ifvoid\LT@lastfoot
  \LT@foot\else\LT@lastfoot\fi` is inside `\LT@output` (506), and the
  output routine builds its own vertical list (§1025 `push_nest`) whose
  `prev_depth` §1026 discards when it hands the material back to the
  contribution list. Only `\LT@start`'s opening head runs on the outer
  list, so that is what the table leaves behind; with no head at all the
  value is unchanged, as this lane's predecessor measured. A probe with
  the same table after a paragraph with and without a descender puts the
  following paragraph at the same distance both times, so the value is
  fixed rather than inherited, and 4.34 pt below where `\dp\LT@foot` would
  put it. The earlier fixtures all end in `\hline\hline`, whose depth is
  zero, so `Fixed(closing)` and `Fixed(opening)` agreed on every one.

Gates: tabular oracle 106/106 (all 98 pre-existing unchanged), zero
font/metric fallback diagnostics and zero `table_limitation` on every
fixture; amsmath 59/59; `cargo test --release` (no `FLASHTEX_*` in the
environment) 171 passed, 0 failed; HW1/HW2 byte-identical to the #176
baseline, 3 pages and 692/698 items each, 0 errors, 0 overfull, 0 font
diagnostics; real-world corpus identical to the baseline on all nine
fixtures.

New fixtures (references from local TeX Live 2025):
- 104-longtable-chunk-boundary: 210 rows, widest cell past the default
  chunk boundary, table opening page 1.
- 105-longtable-ltchunksize: `\LTchunksize=5`, widest cell in chunk six.
- 106-longtable-head-foot-only: `\endhead`/`\endfoot` and nothing else.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the work is already on main.

Replacement: d837c29 (PR #253)

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 GoKubar closed this Sep 15, 2026
@GoKubar
GoKubar deleted the agent/kabir-claude/longtable-inserts branch September 16, 2026 04:18
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