Skip to content

render-pipeline: sectioning headings from class-geometry's \@startsection specs (oracle 38/41 exact) - #151

Closed
GoKubar wants to merge 5 commits into
mainfrom
agent/kabir-claude/heading-fidelity
Closed

GoKubar wants to merge 5 commits into
mainfrom
agent/kabir-claude/heading-fidelity

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Sectioning heading layout in crates/render-pipeline, transcribed from latex.ltx \@startsection/\@sect/\@ssect/\@xsect (lines 17231-17330) and report/book \@chapter, using crates/class-geometry's resolved \@startsection specs.

Stacked on #141 (toc-followups, which includes #133), merged at the coordinator's request because both touch \part/chapter code. Merges cleanly with current main (git merge-tree). Commits after d7995c8 are this lane's.

What changed

  • Heading fonts, skips and indents for all five levels come from class-geometry (Stylesheet::from_resolved). Latin Modern and Computer Modern share ex; Times keeps its own TFM ex.
  • Run-in \paragraph/\subparagraph: the heading starts the next paragraph (bold title, \quad in the bold font, \hskip 1em, \clubpenalty 10000). With no plain paragraph to start, it forms a paragraph of its own. Before it: \addpenalty\@secpenalty, \addvspace.
  • \@hangfrom: a wrapped numbered title hangs under the title text.
  • secnumdepth: the class default (article 3, report/book 2; before, 2 was used everywhere) and \setcounter{secnumdepth} in the body, taking effect from that point. The compiler used to set the {n} argument as a text line. Deep levels are numbered (\thesubsubsection.\arabic{paragraph}).
  • \@nbitem right after a heading: the negative \addvspace is summed with the heading's after-skip (\@xaddvskip, line 9307), so \parsep no longer remains. Lecture-notes \subsection*{Exercises} followed by enumerate now matches pdflatex (20.59 bp; before, 25.07 bp).
  • Math in titles: a \section..\subparagraph title holding $ is re-read as body text (the compiler set $x^2$ as text and dropped \alpha). Math set at a heading's size uses \DeclareMathSizes and the lmodern designs for that size (TexMathMetrics::for_text_size).
  • Two-column \chapter: \@topnewpage[\@makechapterhead] is a \textwidth box at the top of the page, and the columns of that page are shortened (pagebuild::break_pages_tops). This path is not used with floats, contents lists (\onecolumn) or an openright \cleardoublepage after other material; those keep the previous layout.

Oracle

tools/headings-oracle/generate.py (MacTeX 2026 pdflatex, oracle only) writes 41 fixtures and expected word positions. tests/headings_oracle.rs aligns words and gates 38 fixtures at 100% (every word within 0.5 bp, same pages). They cover every level at 10/11/12pt in article, report and book; run-in headings; headings at page top and bottom; consecutive headings; heading then list or display; long wrapped titles; secnumdepth 1, 5 and set in the body; starred forms; appendix; \part; two-column; math in titles; two-column chapters.

  • Before: 11/41 exact. After: 38/41 exact.
  • Not exact, reported only:
    • 06: list glue in the lists lane; pdflatex shrinks page 1 to fit.
    • 32: the running head spaces A. as a sentence end.
    • 33: \sum limits inside a heading (math-layout placement).

Gates

  • cargo test --release in render-pipeline: all green, including page_frame, toc_oracle, floats, tabular and class_geometry_frame.
  • HW1, HW2, lecture-notes (v2 before and after):
    • Identical line texts and pages, and no x changes.
    • HW1/HW2: at most 0.00064 bp vertical drift, from exact sp lengths. 0 overfull.
    • Lecture-notes: the Exercises list moves 4.48 bp, onto pdflatex's gap. Its 2 existing overfull warnings are unchanged.

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 5 commits September 13, 2026 07:26
…like LaTeX

The pipeline set `\tableofcontents` as its heading only. It now keeps
LaTeX's `\contentsline` records in memory and sets every list where its
command stands:

- entries: every numbered heading (`\@sect`, report/book `\@chapter`),
  `\addcontentsline{toc|lof|lot}{<level>}{[\numberline{..}]..}` and float
  captions (`\thefigure`/`\thetable`, `<chapter>.<n>` with chapters);
  `tocdepth` (article 3, report/book 2), `\numberline` up to the class
  `secnumdepth`, `\renewcommand\contentsname` (and the LOF/LOT names);
- geometry (typeset/toc.rs): latex.ltx `\@dottedtocline` (leftskip
  indent+numwidth, `\rightskip\@tocrmarg`, `\parfillskip -\rightskip`,
  hanging wrap), article `\l@section` / report+book `\l@chapter` (bold,
  `\@pnumwidth`, `\addpenalty`, `1.0em plus 1pt`), `\leaders` dot boxes
  (`\mkern4.5mu . \mkern4.5mu`) aligned to the line's left edge as in
  tex.web §626, page numbers flush right; list headings as `\section*`
  (article) or `\chapter*` (report/book), `\@mkboth` under `headings`;
- page numbers: each entry carries a synthetic label; `render` reruns the
  layout (as for `\pageref`) until the formatted `\thepage` of every entry
  settles, so roman front matter shows `i`, `ii`;
- `\appendix`: `\thesection` `\Alph` (article), `\thechapter` `\Alph` and
  `\appendixname` chapter heads (report/book).

The compiler's errors for the commands the pipeline now sets
(`\listoffigures`, `\listoftables`, `\addcontentsline`, `\appendix`, the
list-name redefinitions, `\setcounter{tocdepth}`) are superseded. No
compiler or vendor changes.

Oracle: tools/toc-oracle/generate.py writes 23 fixtures
(fixtures/toc) and pdflatex's word and leader-dot positions (three runs,
MacTeX 2026); tests/toc_oracle.rs gates every word before a list-end
marker within 0.5bp. All 23 pass (worst 0.010bp, 3,392 leader dots).
Two entry page numbers follow body pagination the pipeline places
differently (12pt subsection skips; `\clearpage` in two-column mode ends
the column) and are position-gated only.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude toc layout, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…tries, two-column lists

Follow-ups to the contents-list work (PR #133):

- `\part` (article.cls lines 268-301, report.cls 278-328, book.cls
  299-349): `BodyKind::Part`/`Block::Part` from class-geometry's `PartSpec`
  — article in the flow (`\addvspace{4ex}`, `\Large` "Part I", `\huge`
  title, `\vskip 3ex`, `\@afterheading`), report/book on a page of its own
  (`\null\vfil` ... `\vfil\newpage`, centred, `\thispagestyle{plain}`,
  book's empty page after under openright). Its `\addcontentsline{toc}
  {part}{\thepart\hspace{1em}#1}` entry is set as `\l@part` (article lines
  509-527, report 595-611, book 601-617): `\large\bfseries`, number inline,
  `\addpenalty`, `\addvspace{2.25em plus 1pt}`, `\nobreak`, and
  report/book's `\global\@nobreaktrue`; `tocdepth > -2`.
- `\caption[<short>]{<long>}`: the float scan keeps the optional argument
  and the list shows it (latex.ltx `\@caption#1[#2]#3`, `\@dblarg`).
- Entry titles taken from source bytes (`\addcontentsline`, `\chapter`,
  `\part`, captions) are parsed once per render like body text
  (`toc::entry_items`, the caption route's isolate-and-parse), so `\emph`,
  `\textbf`, math and user macros come out as in a paragraph.
- report/book lists in a two-column document are set at `\textwidth` on
  pages of their own (`\if@twocolumn \@restonecoltrue\onecolumn` ...
  `\twocolumn`, report.cls lines 583-594/634-658).
- Two-column page builder: `\clearpage`/`\cleardoublepage` (and `\chapter`,
  `\part`, the class `\clearpage`s) end the page, `\newpage` only the
  column (latex.ltx `\clearpage` lines 20414-20425); `\cleardoublepage`'s
  empty page is a whole page (`\if@twocolumn\hbox{}\newpage\fi`). Done after
  column breaking by inserting empty columns (`align_columns`), mapped for
  floats like the existing openright pages; one-column documents are
  untouched.

Oracle: 10 new pdflatex fixtures (24-33, MacTeX 2026, three runs); all 33
pass within 0.5bp: 5,321/5,321 words, 4,321/4,321 leader dots (929 new),
worst 0.357bp (a math `x` in fixture 29). `11-article-twocolumn`'s
page numbers are gated again. The generator tolerates font-less blank
pages.

Not addressed (outside the contents code): an inline `$x^2$` superscript
sets ~1.6bp wider and `$\alpha$` is dropped in headings, in the body as in
the list (fixture 29 avoids both); two-column `\chapter` heads
(`\@topnewpage`) sit ~20.7bp lower than pdflatex; the 12pt article
subsection skips (fixture 14) still move one entry's page.

Gates: render-pipeline `cargo test --release` green; HW1/HW2 and 5 more
real-world fixtures byte-identical to main; input-bibliography and
lecture-notes differ from main only by #133's superseded diagnostics.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude toc followups, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…tion specs (oracle 36/41)

Run-in \paragraph/\subparagraph, \@hangfrom hang indents, the class
secnumdepth default and body \setcounter{secnumdepth}, numbered deep
levels with the bold \quad, and \@nbitem's negative \addvspace after a
heading. Oracle: tools/headings-oracle (41 pdflatex fixtures).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude heading fidelity, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Titles holding $...$ are re-read as body text (the compiler sets their
math as plain text and drops \alpha); math set at a heading's size uses
\DeclareMathSizes and the lmodern designs for that size
(TexMathMetrics::for_text_size). Run-in titles keep their math.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude heading fidelity, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…e 38 heading fixtures

report/book \@chapter in two-column mode sets \@makechapterhead in a
\textwidth box at the top of the page and lowers \@ColhT by its height
plus \dbltextfloatsep (latex.ltx \@topnewpage); pagebuild::break_pages_tops
shortens the columns of any page that starts with such a box. Not with
floats, contents lists (\onecolumn) or an openright \cleardoublepage after
other material (kept as before). Heading oracle: 38/41 fixtures gated exact.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude heading fidelity, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
Two feature overlaps with #154 resolved in favour of the more general side: #151's for_text_size/math_fonts_at supersede #154's at_text_size (removed, with its duplicate field and math_box arity restored to #151's wrapper plus math_box_sized). break_pages_inserts and break_pages_tops remain separate page builders; footnotes win and the combination now warns. layout_blocks gained has_floats and Flow gained chapter_tops, as #135's split requires.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
Took #152's list refactor (class_seps/apply_sep_keys/is_key_list, env_shape, three-tuple list_stack_at) over main's inline loop, but kept main's outer_parskip default and #135's hsize() for paragraphs inside float and minipage boxes; style.rs keeps #151's five headings and the class labelsep alongside #152's em_pt.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
#171 predates #151/#152 in every conflicting region; its three residual fixes were grafted onto the newer structure: parse_dimen_in/ec_em_ex threaded through #152's apply_sep_keys and list_labelsep, and the item-label protrusion kern plus label_recs bookkeeping added to #152's multi-word label box.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
No conflicts: #168 is an oracle and its fixtures, with no pipeline source
changes. The compiler side it needs (siunitx) came in with #159 in stage 1,
so the vendored compiler already satisfies it.

One change was needed. #168 carries a `PENDING` list of fixtures that must
*still* differ from pdfLaTeX, each naming the work it waits on, so the entry
is removed when that work lands. `39-heading.tex` waited on heading math --
"the pipeline sets a `$...$` formula in \section at the heading size but an
Inline::Math whose span starts at a command at the body size". That landed on
this branch with #151, so the fixture now matches and the test failed with
"39-heading.tex now matches: remove it from PENDING", exactly as designed.
Removed; the oracle passes.

siunitx is now 36/39 exact against the committed MacTeX references, up from
the 35/39 the PR reports. The three still pending are unrelated to siunitx
and name their own dependencies: 34-paragraph (math glue stretch in line
justification, PR #148), 37-ang-minutes (`\prime` drawn from Latin Modern
Math at 2.169pt where pdfLaTeX's cmsy7 prime is 2.306pt), 38-power-on-letter
(no upright fam0 Latin math character, so a power on a one-letter unit sits
0.78 bp high).

`cargo test --release` in render-pipeline: the same 11 known failures, no
more. Zero font diagnostics on every gate.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Superseded — the content landed piecemeal via other branches, not this one.

Verified on origin/main (de1bbdf): per-class secnumdepth defaults at adapter.rs:1290-1302 (comment matches this PR verbatim); run-in headings via #404 (a63537ff); @nbitem/@xaddvskip absorption at adapter.rs:2827-2894; math_fonts_at (typeset.rs:840); Stylesheet::from_resolved (style.rs:277); test run_in_headings.rs present.

Residuals tracked, not lost: \hangfrom and a dedicated headings oracle test never landed → #768.


Closed by the Commander after a stale-draft screening pass that required evidence in both directions — a landing SHA to close, an empty grep to keep open. If this verdict is wrong, say so on issue #2 and I will reopen: an asymmetric bar has produced wrong calls here in both directions before.

@d-q222 d-q222 closed this Sep 16, 2026
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