Skip to content

render-pipeline: \tableofcontents, \listoffigures, \listoftables like LaTeX - #133

Merged
jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/toc-layout-fidelity
Sep 13, 2026
Merged

jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/toc-layout-fidelity

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Base: main 85ec30c. Commit: f99a920. This PR changes only render-pipeline, with no compiler or vendor edits and no re-pin needed.

Before this, the pipeline set \tableofcontents as its heading only. It now sets \tableofcontents, \listoffigures and \listoftables the way LaTeX does, matching pdflatex.

Overlap check

  • FT-034 (daniel-contents) owns crates/toc-layout. That machine is paused, the branch is unmerged, and nothing consumes the crate.
  • I did not use toc-layout here. Its leader model measures character widths and does not reproduce TeX's aligned \leaders, so the entry lines are set in the pipeline's own line breaker instead.
  • No other open PR touches the contents lists.
  • hyperref link annotations on entries are left to the hyperref lane.

What

Records. src/toc.rs keeps LaTeX's \contentsline records in memory:

  • every numbered heading (\@sect, report/book \@chapter)
  • \addcontentsline{toc|lof|lot}{level}{[\numberline{..}]text}
  • float captions, numbered <chapter>.<n> in report/book
  • tocdepth: article 3, report/book 2
  • \numberline up to the class secnumdepth
  • \renewcommand\contentsname, \listfigurename and \listtablename

Geometry. src/typeset/toc.rs lays out each entry as one pdfTeX paragraph:

  • \@dottedtocline: \leftskip = indent + numwidth, \rightskip\@tocrmarg, \parfillskip -\rightskip, and a hanging wrap for long titles
  • article \l@section and report/book \l@chapter: bold, \@pnumwidth, \addpenalty, \addvspace/\vskip 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

Headings. A list's heading is \section* in article and \chapter* in report/book. Under headings, \@mkboth sets the marks.

Page numbers. Each entry carries a synthetic label. render reruns the layout, as it already does for \pageref, until every entry's formatted \thepage settles. Roman front matter therefore shows i, ii. In practice this takes two passes.

\appendix. Article sections become \Alph. In report/book, chapters become \Alph and their heads use Appendix.

Diagnostics. The compiler still reports \listoffigures, \listoftables, \addcontentsline, \appendix, the list-name \renewcommands and \setcounter{tocdepth} as errors. The pipeline sets these commands now, so it drops those diagnostics.

Oracle

  • tools/toc-oracle/generate.py reuses the page-frame PDF reader. It writes 23 fixtures and pdflatex's word and leader-dot positions from three runs on MacTeX 2026, plus a \pdfsavepos list-end marker.
  • tests/toc_oracle.rs gates every word before that marker within 0.5bp. Cargo never runs TeX.
Fixture Words Dots Worst
01 article basic 293/293 256/256 0.007bp
02 tocdepth 1 13/13 0/0 0.004bp
03 tocdepth 2 112/112 93/93 0.007bp
04 tocdepth 3 406/406 354/354 0.007bp
05 long titles 123/123 36/36 0.005bp
06 starred + \addcontentsline 107/107 89/89 0.009bp
07 LOF 105/105 89/89 0.009bp
08 LOT 69/69 58/58 0.009bp
09 TOC+LOF+LOT 224/224 190/190 0.010bp
10 appendix 151/151 126/126 0.010bp
11 twocolumn 216/216 170/170 0.007bp
12 \contentsname 114/114 93/93 0.007bp
13 11pt 277/277 240/240 0.007bp
14 12pt 281/281 244/244 0.006bp
15 many pages 445/445 372/372 0.007bp
16 wide numbers 445/445 393/393 0.008bp
17 report 149/149 128/128 0.007bp
18 report tocdepth 1 + LOF 109/109 91/91 0.009bp
19 report long chapter 90/90 24/24 0.005bp
20 report appendix 81/81 68/68 0.009bp
21 book 77/77 62/62 0.007bp
22 roman front matter 149/149 123/123 0.008bp
23 same page as body 112/112 93/93 0.007bp

Two fixtures gate positions only for page-number text, because the page an entry lands on is decided by body pagination the pipeline places differently:

  • 14 (12pt): the subsection skips add up 0.7bp short of pdflatex's, so 4 Results moves from page 3 to page 4.
  • 11 (twocolumn): \clearpage in two-column mode ends the column rather than the page.

Gates

All measured on mac-m5pro-kabir with release builds.

  • render-pipeline cargo test --release: every test binary is green, including the new toc_oracle.
  • clippy: clean for the new files.
  • Byte-identical PDF and v2 JSON against main 85ec30c (same working directory, --font-dir apps/mac/Fonts): HW1, HW2, article-twocolumn, cv, letter, math-sheet, unicode-accents.
  • input-bibliography: the appendix section now reads A instead of 3, as in LaTeX, and its \appendix compiler error is gone. Nothing else changed.
  • lecture-notes: the TOC matches pdflatex on 14/14 words, against 1/14 on main where only the heading was set. This comparison removes the page's pre-existing 2.09bp vertical offset, which starts in the title block.
  • No supported-inventory change: the compiler inventory is untouched.

Known limits

  • Titles are the source words: macros inside a \caption or \addcontentsline argument are not expanded.
  • \caption[short]{long}: the LOF uses the long argument.
  • \part entries are not set.
  • twocolumn report/book does not switch to \onecolumn for the list.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…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
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