Skip to content

render-pipeline: a heading after an empty contents list takes its \addvspace; no page break between two heads - #580

Merged
GoKubar merged 2 commits into
mainfrom
agent/daniel-parent/heading-after-heading
Sep 15, 2026
Merged

GoKubar merged 2 commits into
mainfrom
agent/daniel-parent/heading-after-heading

Conversation

@d-q222

@d-q222 d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What

  • Heading after an empty contents list. \@starttoc ends with \@nobreakfalse. crate::toc::list_blocks now ends every \tableofcontents/\listoffigures/\listoftables with a new Block::NoBreakFalse, which clears the typesetter's after_heading. A heading right after an empty list takes \@startsection's \addpenalty/\addvspace branch again. That gives the larger of its before-skip and the list head's after-skip (\@xaddvskip). A paragraph there gets its normal \clubpenalty.
  • No break between two heads. Under \if@nobreak, \@startsection skips \addpenalty\@secpenalty as well as \addvspace. The pipeline already dropped the skip but still placed a -300 penalty, so two heads at the foot of a page could split. It now drops the penalty too, unless an explicit page-break command stands before the head.
  • tests/heading_after_heading.rs pins the pdflatex numbers (4 tests).

Why

The AUX-lists lane (#543, "Not done") reported that \section*{A}\section*{B} puts B 5.15bp too high. Measured against pdflatex, plain heading-after-heading is already exact on main: 196/196 pairs. The mismatch appears only when the first head is a contents list's \section*, as in the lane's empty \listoffigures followed by \listoftables. \@starttoc's \@nobreakfalse means the second head is not under \@nobreak. Its \addvspace{3.5ex} tops the list head's 2.3ex after-skip up by 1.2ex:

probe (article) pdflatex before after
10pt \listoffigures\listoftables 32.9422 27.7984 (-5.144) 32.9457
11pt \listoffigures\listoftables 34.3681 28.7356 (-5.633) 34.3719
12pt \tableofcontents\section* 39.9292 33.7568 (-6.172) 39.9336
10pt \listoffigures\subsection 27.8851 23.8134 (-4.072) 27.8883
10pt \section*{A}\section*{B} (control) 27.7961 27.7984 27.7984
report 10pt \chapter\section (control) 57.7833 57.7833 57.7833

In report the list head is a \chapter*. Its \vskip 40\p@ already beats every before-skip, so nothing moves there (verified).

Oracle method. pdfTeX 3.141592653-2.6-1.40.29 (TeX Live 2026), T1, geometry margin=1in. The \zsavepos markers go after each anchor word (the vspace-triage method), and positions are compared baseline to baseline in bp.

Coverage. 262 pairs: article 10/11/12pt and report 10/11pt; section/subsection/subsubsection pairs, starred and unstarred, mixed starred/unstarred; \chapter/\chapter* followed by \section/\section*/\subsection; each list followed by every level. Before: 241/262 within 0.01bp. After: 262/262. The commit message says 256/235 because it miscounted; 262/241 is correct.

Page foot. 44-54 one-line paragraphs, then \section*{Alpha}\section*{Bravo} and body text. pdflatex never separates the heads. Before, 7/11 placements matched (47-50 lines split Alpha on p1 from Bravo on p2). After, 11/11.

Overlap check

Test results

cargo test --no-fail-fast in crates/render-pipeline (CARGO_BUILD_JOBS=4), after the change:

tests/heading_after_heading.rs: test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.30s
tests/align_after_heading.rs: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.27s
tests/heading_macros.rs: test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.10s
tests/run_in_headings.rs: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s
tests/toc_oracle.rs: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 3.58s
tests/par_leading_oracle.rs: test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s
tests/twocolumn_title_oracle.rs: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.30s
tests/multicol_oracle.rs: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.81s
tests/page_frame.rs: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.18s
unittests: test result: ok. 137 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.11s
whole crate: 367 passed, 12 failed

The 12 failures are pre-existing: the same result on origin/main 36fe7ec with this PR's src reverted. They all come from debug_assert_eq!(leadings.len(), parsed.blocks.len()) at src/adapter.rs:1268.

letter_class_geometry: test result: FAILED. 0 passed; 5 failed
uline:                 test result: FAILED. 0 passed; 2 failed
underline_sout:        test result: FAILED. 0 passed; 4 failed
xcolor_oracle:         test result: FAILED. 0 passed; 1 failed

Without the src change, heading_after_heading: test result: FAILED. 2 passed; 2 failed (off by -5.1438; 47 lines of filler: pages of Alpha/Bravo/Charlie).

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

…dvspace; no break between two heads

What changed:
- `\@starttoc` ends with `\@nobreakfalse`. The contents lists now end with a
  `Block::NoBreakFalse`, which clears `after_heading` in the typesetter. A
  heading right after an empty `\listoffigures`/`\listoftables`/
  `\tableofcontents` takes `\@startsection`'s `\addvspace` branch again: the
  larger of its before-skip and the list head's after-skip. Before, the
  second head sat 1.2ex too high (5.144bp at 10pt, 5.633bp at 11pt, 6.172bp
  at 12pt). A paragraph there also gets its normal `\clubpenalty`.
- Under `\@nobreak`, a heading drops its `\addpenalty\@secpenalty` as well as
  its before-skip. Two heads at the foot of a page no longer break apart.
- tests/heading_after_heading.rs pins pdflatex numbers from zref-savepos
  markers placed after the anchor words.

What was run:
- 256 baseline-to-baseline pairs against pdflatex (article 10/11/12pt, report
  10/11pt; section/subsection/subsubsection pairs starred and unstarred;
  chapter then section; lists then every level): before 235/256 exact, after
  256/256 within 0.003bp. Page-foot probe with 44-54 lines of filler: before
  7/11 page placements matched, after 11/11.
- cargo test --test heading_after_heading: test result: ok. 4 passed; 0 failed
  (without the src change: 2 passed; 2 failed)

Next step: run the heading, TOC and baseline oracle suites and open the PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
… 1.40.29

What changed:
- Corrects the pair count (262, not 256) and the pdfTeX version in the test module doc.

What was run:
- cargo test --no-fail-fast (render-pipeline): 367 passed, 12 failed; the 12 fail identically on origin/main (adapter.rs:1268 debug_assert).

Next step: open the PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent independent review (subagent)
Verdict: APPROVE

What was run

All from crates/render-pipeline (this repo has no root/workspace Cargo.toml; the package is flashtex-render-pipeline, not render-pipeline, so -p render-pipeline from the repo root doesn't resolve — ran directly inside the crate instead), with CARGO_BUILD_JOBS=4 and a scratch CARGO_TARGET_DIR.

  • cargo test --no-fail-fast --test heading_after_heading → 4 passed; 0 failed (a_heading_after_an_empty_list_takes_its_addvspace, report_list_heads_already_leave_the_larger_skip, a_heading_after_a_heading_has_no_before_skip, no_page_break_between_two_heads)
  • cargo test --no-fail-fast --test toc_oracle --test multicol_oracle → 2 passed; 0 failed (contents_lists_match_pdflatex, multicol_fixtures_against_pdflatex)
  • cargo test --no-fail-fast --lib -- toc → 0 passed (139 filtered out — no toc-named unit tests in src/)
  • cargo test --no-fail-fast --lib -- multicol → 4 passed; 0 failed (135 filtered out)
  • cargo test --no-fail-fast --lib adapter → 27 passed; 2 ignored; 0 failed (covers the Block classification test the diff extends with the "B" tag for NoBreakFalse)
  • cargo test --no-fail-fast --test review_580_scenarios (new ad hoc fixture I added under crates/render-pipeline/tests/, not part of the PR, for the 3 scenarios below) → 3 passed; 0 failed

pdflatex oracle: /Library/TeX/texbin/pdflatex (pdfTeX 3.141592653-2.6-1.40.29, TeX Live 2026), -interaction=nonstopmode -halt-on-error, 2-3 passes where \tableofcontents/\label needed a rerun. Page numbers via zref-abspage; sub-bp gaps via zref-savepos (with \@dottedtocline/\l@section locally patched to drop a \zsavepos right at the start of each toc entry's title, landing on the same baseline the render-pipeline harness's words_of finds), sp→bp as /65536/1.00375 — same convention heading_after_heading.rs's own doc comment already documents.

Findings

  1. \section* right after a non-empty \tableofcontents (3 entries from \section/\subsection) — input: \tableofcontents\n\section*{Zulu}\nYankee follows.\n\section{Uno}\nFiller after Uno.\n\subsection{UnoSub}\nFiller after UnoSub.\n\section{Dos}\nFiller after Dos. (11pt) → pdflatex: last-entry ("Dos") baseline to "Zulu" baseline is 34.3681bp, one page (independently reproduced with the entry-producing sections placed in a different source order relative to Zulu, same 34.3681bp both times, confirming the gap depends only on the toc entry's near-zero trailing skip and Zulu's own before-skip, not source order) → actual: render-pipeline gives 34.3719bp, same page (off by +0.004bp) — matches, not a regression. This is expected from the code: toc.rs's EntryStyle::nobreak_after is false for plain \l@section/\l@subsection (only true for report/book's \l@part), so the very first ordinary Block::TocEntry already clears after_heading well before the trailing Block::NoBreakFalse this PR adds is even reached — the PR's new if !*eject_before { penalty_before = None } line is dead code on this path.

  2. A heading, \label, then another heading immediately after — input: N one-line filler paragraphs + \section*{Alpha}\label{sec:a} + \section*{Bravo} + Charlie one.\par Delta two.\par (10pt), N=47 and 48 → pdflatex: 47 lines keeps Alpha/Bravo/Charlie all on page 1, 48 lines moves all three to page 2 — identical to the label-free boundary already pinned in this PR's own no_page_break_between_two_heads → actual: render-pipeline reproduces the same 47→page 1 / 48→page 2 boundary exactly — matches, not a regression. adapter.rs folds a heading-adjacent \label into that heading's own Item list (Some(Block::Heading {..} | ..) if after_heading => items.push(Item::Label {..})) rather than emitting a separate Block, so the two headings stay adjacent Blocks with nothing between them either way; no stray \@secpenalty reappears.

  3. A single heading immediately followed by body text, placed at the foot of a page — input: N one-line filler paragraphs + \section*{Alpha} + Charlie one.\par Delta two.\par (10pt), N=48 and 49 → pdflatex: 48 lines keeps Alpha and "Charlie one." both on page 1, 49 lines pushes both together to page 2 — no filler count in between orphans Alpha alone at the foot with its body text stranded on the next page → actual: render-pipeline reproduces the same 48→page 1 / 49→page 2 boundary exactly — matches, not a regression. The kernel's orphan-heading guard is \clubpenalty\@M from \@afterheading's one-shot \everypar, a different mechanism from the \@secpenalty this PR removes between two adjacent headings; the pipeline's equivalent (club_penalty: if after_heading { INF_PENALTY } else { CLUB_PENALTY } in typeset.rs's ParaState) is in an untouched code path.

Side observation (out of scope, not a regression from this PR)

While building fixture 1 I found that render() only resolves \tableofcontents entries for headings placed after the \tableofcontents call in the source; a heading placed before it silently drops out of v2.pages instead of erroring (every existing fixture in this crate already only places headings after \tableofcontents, which is presumably why this hasn't surfaced). The diff here doesn't touch heading/toc-entry collection at all, so this predates and is unrelated to PR #580 — flagging in case it's worth its own issue, not as a blocker here.

Overall

Small, well-targeted diff (184 insertions, 0 deletions, no logic removed). It matches the \@startsection/\@starttoc/\@xsect kernel semantics precisely, the existing 262-pair oracle suite plus the new tests here (heading_after_heading, toc_oracle, multicol_oracle, plus the 3 ad hoc scenarios above) all pass, and I found no regression in the two specific risk areas this review was asked to probe (non-empty-toc case, and the orphan-heading protection being a distinct mechanism from the removed penalty).

@GoKubar
GoKubar merged commit 64550d7 into main Sep 15, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/daniel-parent/heading-after-heading branch September 16, 2026 04:16
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.

2 participants