Skip to content

render-pipeline: secnumdepth, description, \baselinestretch and run-in headings - #292

Closed
GoKubar wants to merge 3 commits into
mainfrom
agent/linux-engine-layout/sectioning-pipeline
Closed

GoKubar wants to merge 3 commits into
mainfrom
agent/linux-engine-layout/sectioning-pipeline

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Three of the corpus lane's ranked layout divergences (#258), all fixed by
reading what the class file says instead of a constant, plus the pipeline
half of a fourth that needs the compiler PR and a vendor re-pin.

Split as the lane convention requires: this is the pipeline PR; the
compiler PR is #291.

What changed

\subsubsection was never numbered (#258 rank 6, heading text 35.00 bp
too far left). adapt_cached had two readings of one counter: the body
heading used options.default_secnumdepth, a flat 2 for every class, while
the contents list already resolved article.cls line 255
\setcounter{secnumdepth}{3} against report/book.cls {2}. So an article
numbered its \subsubsection in the ToC and not in the body. Both now read
ResolvedDocument::secnumdepth; an explicit \setcounter still wins.

description was invisible to the list geometry (#258 rank 9, dx −24.91
bp, the list 11.96 bp short). list_stack_at, gap_has_list_end and
list_env_after_begin matched only itemize/enumerate/thebibliography,
so a description item fell through to the enumerate defaults. article.cls
lines 360-365 are now transcribed — \labelwidth\z@,
\itemindent-\leftmargin and \descriptionlabel's
\hspace\labelsep\normalfont\bfseries — as a new ListGeom::label_style.
While there: a multi-word \item[...] label was shaped as one run, so its
interword spaces took the font's space advance instead of TeX's
\fontdimen2 (1.91 bp per space too wide in Latin Modern Bold at 10 pt);
label_items now sets each word as its own box, which is what an \hbox
packed at natural width does.

\baselinestretch was not read at all (#258 rank 8, max |dy| 11.96 bp),
so a document asking for one-and-a-half or double spacing was set single.
It is not a length applied once: \@setfontsize ends with
\baselineskip\baselinestretch\baselineskip, so every size selection
multiplies that size's own leading. Implemented where sizes are selected —
Stylesheet::set_baselinestretch for the body and the headings, and
Stylesheet::stretched at the three sites with size tables of their own
(footnotes, \chapter/\part/\maketitle, p{} cells).
\linespread{f}, the unbraced \renewcommand form and \def are the same
command; a non-numeric argument is ignored.

Run-in headings (#258 rank 4, not bold, +14.94 bp indented, 13.94 bp of
space missing). Stylesheet knew three levels and mapped
SectionAfter::RunInEm to Skip::ZERO; it now carries the class's five with
\@startsection's #3 and its non-positive #5. adapter::RunInHeading
holds such a heading until the paragraph its \everypar fires on, drops that
paragraph's \parindent box, sets the heading in the compiler's own bold
weight and follows it with \hskip -#5 evaluated in the paragraph's font.

Measured, against the reproducers

tools/visual-oracle/rank.py over fixtures/divergence-probes, candidate vs
the pinned TeX Live 2025 reference, word-origin deltas in bp. Geometry
only
: linux-primary has no pdftoppm and no Ghostscript, so no pixel
comparison was run.

probe before after
min-description max |dx| 24.91 / |dy| 11.96, 6/38 words within 0.5 bp 0.01 / 0.00, 38/38
min3-baselinestretch 0.01 / 11.96, 19/42 0.01 / 0.00, 42/42
min-paragraph † 14.94 / 27.87, 27/74 0.01 / 0.01, 74/74
min2-headings 35.00 / 0.02, 37/40 0.01 / 0.02, 41/41
min3-subsubsection 35.00 / 0.01, 20/24 0.75 / 0.01, 22/24 ‡

† with vendor/compiler mirrored locally from the compiler PR; that mirror is
not part of this branch. ‡ the residual is the probe's \verb run on
substituted ec metrics — the bundle has no ectt*.tfm, so those positions
are not a line-breaking measurement. Verified: the same document with the
\verb replaced by ordinary words is exact, 27/27 words within 0.01 bp.

No probe of the 43 got worse. The regression floor is intact: min-toc,
min-chapter, min-maketitle, min-footnote, min-quote, min-twocolumn
(439/439), min-tabular, min-curly-quote and the six itemize/enumerate
probes are unchanged to 0.01 bp.

Gates

NixOS linux-primary, bundled apps/mac/Fonts, FLASHTEX_TFM_DIRS =
public/lm:jknappen/ec:public/amsfonts/symbols, CARGO_BUILD_JOBS=4. Zero
font-failure diagnostics (font_unavailable,
required_metrics_unavailable, ec_metrics_unavailable,
font_outline_substituted, tfm_missing, math_font_unavailable) — not
zero diagnostics of any kind; math_resource_profile and
math_glyph_unmapped are informational and unchanged.

gate control (this branch's base) this branch
crates/render-pipeline cargo test --release --no-fail-fast all pass all pass, 0 failed (+15 new tests)
with --features run-in-headings (needs the re-pin) n/a 4 new tests pass
amsmath oracle corpus 59/59 within 0.5 bp 59/59
HW1 / HW2 3 pages, 0 errors, 0 overfull same
the 10 pre-existing fixtures/real-world documents — rendering-v2 byte-identical
the 12 documents #258 added — 5 improve (plain-article p2 words within 0.01 bp 68 → 138; lmodern-report p2 max |dx| 38.33 → 0.01, p3 27.28 → 7.24; enumitem-worksheet p2 390.22 → 338.87; listings-manual p3 median dx −18.76 → −9.51; hyperref-toc p2 one more word aligns), 7 unchanged

Two pages that these changes move also shift vertically on constructs they do
not touch (plain-article p2 max |dy| 46.08 → 50.07, enumitem-worksheet
p2 103.40 → 105.39). Both pages are already hundreds of bp from the reference
because of unimplemented constructs above them; the horizontal geometry those
changes own improves on both.

New tests: tests/sectioning_depth.rs, tests/description_list.rs,
tests/baselinestretch.rs, tests/run_in_headings.rs. Every expected
coordinate in them is the pdflatex geometry of the matching reproducer, read
with tools/visual-oracle/pdftext.py; the oracle is never run from a test.

Provenance

pdflatex is an oracle only and is never in the product path. No committed
MacTeX-generated reference or sidecar was regenerated or overwritten. The one
new reference produced for this work (a local \subparagraph probe) was made
with TeX Live 2025 (pdfTeX 3.141592653-2.6-1.40.27,
SOURCE_DATE_EPOCH=0 FORCE_SOURCE_DATE=1, two passes), is labelled as such
and is not committed.

Not in this PR

abstract (#258 rank 1, the highest-frequency of the lot) is not fixed
here. It needs a capability paragraph_block does not have — a paragraph set
at a size other than \normalsize with that size's own leading (it
hard-codes body_size_pt/baselineskip_pt; typeset/footnotes.rs is the
only existing precedent) — plus quotation's \listparindent 1.5em
evaluated in \small's own \fontdimen6, and the center/quotation
\@list<i> skips as \small redefines them. pdflatex's own vertical list
for min-abstract (\showoutput, TeX Live 2025) gives the exact targets:

\glue 10.0 plus 4.0 minus 5.0        <- \topsep + \partopsep at \normalsize
\glue(\parskip) 0.0 plus 1.0
\glue(\baselineskip) 4.78902
\hbox(6.21098+0.0)x469.75502          <- centred \small\bfseries \abstractname,
                                        at the FULL measure
\glue 10.0 plus 3.0 minus 5.0 / -10.0 ... / 10.0 ...   <- \@endparenv vs the
                                        quotation's own \addvspace
\glue(\baselineskip) 4.25165
\hbox(6.74835+2.24945)x419.75496, shifted 25.00003     <- \leftmargini both sides
.\hbox(0.0+0.0)x13.87161                               <- \listparindent = 1.5 em
                                                          of \small
\glue(\baselineskip) 2.55206          <- \small's 11 pt leading throughout
\glue 6.0 plus 3.0 minus 3.0         <- \topsep + \partopsep as \small
                                        redefines \@listi (4 pt, not 8 pt)

crates/title-layout/src/abstract_block.rs already models most of this
(layout_abstract), but that crate is not a dependency of this one and its
own docs note that \listparindent is not measured there. Wiring it in (or
transcribing its arithmetic against the vendored document-style, which
already exposes list_level, font_size and Skip::addvspace) is the
bounded next step.

GoKubar and others added 3 commits September 13, 2026 22:08
… geometry

Two of the corpus lane's ranked divergences (#258), both entirely inside
this crate, both fixed by reading what the class file says instead of a
constant.

**`\subsubsection` was never numbered** (#258 rank 6, `min3-subsubsection`,
heading text 35.00 bp too far left). `adapt_cached` had two readings of one
counter: the body heading used `options.default_secnumdepth`, a flat `2` for
every class, while the contents list already resolved article.cls line 255
`\setcounter{secnumdepth}{3}` vs report/book.cls `{2}`. So an `article`
numbered its `\subsubsection` in the ToC and not in the body. The heading now
reads `ResolvedDocument::secnumdepth` (class-geometry's transcription of the
class's own `\setcounter`) and `toc_secnumdepth` is that same value -- one
counter, one reading. An explicit `\setcounter{secnumdepth}{n}` still wins,
and a document with no `\documentclass` still keeps the caller's default.

**`description` was invisible to the list geometry** (#258 rank 9,
`min-description`, dx -24.91 bp and the list 11.96 bp short). `list_stack_at`,
`gap_has_list_end` and `list_env_after_begin` matched only
`itemize`/`enumerate`/`thebibliography`, so a `description` item fell through
to the `enumerate` defaults. article.cls lines 360-365 are now transcribed:

    \list{}{\labelwidth\z@ \itemindent-\leftmargin
            \let\makelabel\descriptionlabel}
    \newcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\bfseries #1}

`ListGeom` gains `label_style: ItemLabel` (`Llap` = latex.ltx's
`\makelabel##1{\hss\llap{##1}}`, `Description` = the above). For
`Description`, `\@item`'s `\hskip\itemindent \hskip-\labelwidth
\hskip-\labelsep` with `\labelwidth\z@` and `\itemindent-\leftmargin`, plus
the label box's own leading `\hspace\labelsep`, cancel to a single
`-\leftmargin`: the term is set flush on the left margin in the bold body
face and the item text follows one `\labelsep` after it, while the wrapped
lines still hang at `\@totalleftmargin`. `\topsep`/`\itemsep`/`\parsep` come
from the existing `\@list<i>` path, which was already environment-agnostic.

**A multi-word `\item[...]` label was one shaped run**, so its interword
spaces took the *font's* `space` advance rather than TeX's `\fontdimen2` --
1.91 bp per space too wide in Latin Modern Bold at 10 pt, which is what was
left of `min-description` after the geometry was right. `label_items` now
sets each word as its own box with `\fontdimen2` between them, which is what
an `\hbox` packed at natural width does. Single-word labels (every bullet,
every `\labelenum<i>`, every `thebibliography` tag) are unchanged.

Measured against the corpus lane's reproducers (#258 @ c051d56, TeX Live
2025 references, geometry only -- this host has no rasterizer), candidate vs
reference word origins in bp:

| probe | before | after |
|---|---|---|
| `min3-subsubsection` | max \|dx\| 35.00, 20/24 words within 0.5 bp | max \|dx\| **0.75**, 22/24 (the residual is the `\verb` run on substituted `ectt` metrics) |
| `min2-headings` | max \|dx\| 35.00, 37/40 within 0.5 bp | max \|dx\| **0.01**, **41/41** |
| `min-description` | max \|dx\| 24.91 / \|dy\| 11.96, 6/38 within 0.5 bp | **0.01 / 0.00**, **38/38** |
| `min-toc`, `min-chapter` | exact | unchanged |
| `min2-itemize`, `min2-nested-lists`, `min3-itemize-only`, `min3-enumerate-only`, `min3-itemize-multipar`, `min4-itemize-wrap` | — | unchanged to 0.01 bp |

New tests: `tests/sectioning_depth.rs` (article numbers `\subsubsection`,
report does not, an explicit `\setcounter` still wins) and
`tests/description_list.rs` (term at 72.000, second term word at 99.894, item
text at 128.843, wrapped line at 96.907 -- the pdflatex coordinates of
`min-description` -- and the term in the bold face, the body not).

Implementation-Agent: Claude Opus 5 (engine layout lane, linux-primary / NixOS)
Commit-Executor: Claude Opus 5 via Claude Code (direct-agent Git execution
under the observed-Cursor-limit user override)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
#258 rank 8 (`min3-baselinestretch`, max |dy| 11.96 bp): the macro was not
read at all, so a document that asks for one-and-a-half or double spacing was
set at single spacing throughout.

`\baselinestretch` is not a length the body applies once. latex.ltx defines
`\def\baselinestretch{1}` and `\@setfontsize` ends with

    \baselineskip\baselinestretch\baselineskip

so *every* `\@setfontsize` -- `\normalsize`, `\small`, `\footnotesize`, the
`\Large` of a `\section`, the `\LARGE` of `\@maketitle`, the `\huge` of
`\chapter` -- multiplies the leading of the size it selects. It does not
touch `\lineskip`/`\lineskiplimit` (the `.clo`s' `\normallineskip`) or the
fixed `\setlength`s such as `\footnotesep` and `\skip\footins`. So this is
implemented where sizes are selected, not at one site:

- `Stylesheet` gains `baselinestretch` and `set_baselinestretch`, which
  scales the leadings it already holds (the body's and all three headings');
- `FootnoteParams::of`, the three `class_geometry::FontSize::metrics`
  closures (`\chapter`, `\part` in flow and on its own page, `\maketitle`)
  and `table_box`'s non-body-size `\strutbox` scale their own table's value
  through `Stylesheet::stretched`;
- everything else already reads `Stylesheet::baselineskip_pt` and follows.

`adapter::baselinestretch` reads the factor from the source the way
`\setlength{\parskip}` is already read: `\renewcommand{\baselinestretch}{f}`
with a braced or unbraced first argument, the `*`-form, `\def`,
`\newcommand`/`\providecommand`, and `\linespread{f}`, which latex.ltx
defines as exactly `\renewcommand{\baselinestretch}{f}\@currsize`. The last
setting in source order wins, as for `\setlength`. A non-numeric or
non-positive argument is ignored rather than guessed at.

Measured against the corpus lane's reproducers (#258 @ c051d56, TeX Live
2025 references, geometry only), candidate vs reference word origins in bp:

| probe | before | after |
|---|---|---|
| `min3-baselinestretch` | max \|dy\| 11.96, 19/42 words within 0.5 bp | **0.01 / 0.00**, **42/42** |
| `min-footnote`, `min-maketitle`, `min-chapter` | exact | unchanged |

The 10 pre-existing real-world fixtures produce a **byte-identical**
rendering-v2 display list against a control build of this branch's base
(`hw1`, `hw2`, `cv`, `letter`, `lecture-notes`, `math-sheet`, `inline-math`,
`input-bibliography`, `article-twocolumn`, `unicode-accents`): none of them
sets the macro, and with the factor at 1 every multiplication is the
identity.

New `tests/baselinestretch.rs`: 1.5 gives the probe's measured 17.932 bp body
pitch with the first baseline still where `\topskip` puts it; `\linespread`,
the unbraced form and the last-wins rule agree exactly; a `\section` heading's
and a footnote's own leadings scale by the same 1.5; and
`\renewcommand{\arraystretch}` is not mistaken for it.

Implementation-Agent: Claude Opus 5 (engine layout lane, linux-primary / NixOS)
Commit-Executor: Claude Opus 5 via Claude Code (direct-agent Git execution
under the observed-Cursor-limit user override)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
#258 rank 4 (`fixtures/divergence-probes/min-paragraph`): the heading was not
bold, sat `\parindent` in (+14.94 bp) and was missing 13.94 bp of space above
it, per occurrence.

`Stylesheet` knew only three heading levels -- `section_spec(level).expect(
"levels 1..=3")`, `headings: [HeadingStyle; 3]`, `heading()` clamping to 3 --
and threw the one thing that distinguishes levels 4 and 5 away:
`SectionAfter::RunInEm` was mapped to `Skip::ZERO`, so even if a level-4
heading had arrived it would have been set as a display `\subsubsection`.
The table is now the class's five (article.cls lines 302-321) and
`HeadingStyle` carries `\@startsection`'s `#3` (`indent_pt`,
`\subparagraph`'s `\parindent`) and its `#5` when non-positive
(`run_in_em`).

A run-in heading is not a vertical block at all. `\@sect` stores it in
`\@svsechd` instead of setting it, and `\@xsect` installs an `\everypar`
that fires on the *next* paragraph: it drops that paragraph's `\parindent`
box (`{\setbox\z@\lastbox}`), unboxes the heading and adds `\hskip -#5`.
`adapter::RunInHeading` holds the heading for exactly that long --

- the items are built with the compiler's own weights
  (`items_for_weighted`), because unlike `heading_block` the paragraph they
  land in is not bold at its base, so `\bfseries` has to reach them;
- `#3` goes in front as an `Item::HSpace` and `\hskip -#5` after as
  `Item::Quad`, which is evaluated in the paragraph's own font, as
  `\everypar` is;
- `\addvspace{#4}` (`3.25ex`) rides along as the paragraph's
  `addvspace_before`, so it still collapses against a preceding skip the way
  `\addvspace` does;
- the paragraph is not indented and is not joined onto the previous one;
- a heading with nothing to run into (a heading, rule, picture or the end of
  the document follows) is flushed as an unindented paragraph of its own.

**Depends on the compiler-side PR and a vendor re-pin.** `vendor/compiler`
does not emit `Block::Heading` above level 3 yet, so this arm is inert
against the current pin -- the code builds and every existing test is
unchanged either way. `tests/run_in_headings.rs` is therefore behind the
`run-in-headings` feature (off by default, documented in `Cargo.toml` exactly
as `amsmath-inline` and `request-date` were before their re-pins); turn it on
in `default` when vendor/compiler carries the levels.

Measured with `vendor/compiler` mirrored locally from the compiler PR (that
mirror is **not** part of this commit), against the reproducer's TeX Live
2025 reference, geometry only -- this host has no rasterizer:

| probe | before | after |
|---|---|---|
| `min-paragraph` | max \|dx\| 14.94 / \|dy\| 27.87 bp, 27/74 words within 0.5 bp | **0.01 / 0.01**, **74/74** |
| a local `\paragraph` + `\subparagraph` + trailing-`\paragraph` probe (90 words) | — | max \|dx\| 0.01 / \|dy\| 0.01, **90/90** |

`cargo test --release --features run-in-headings`: 4 new tests pass (the
heading opens the next paragraph's first line at x 72.000 / baseline 141.629
with the body resuming at 171.438; it is bold and `\normalsize`;
`\subparagraph` starts at 86.944 = one `\parindent` in; a trailing
`\paragraph` is still set). Without the feature the whole suite is unchanged,
0 failed.

Against a control build of this branch's base, with the re-pin *absent*, the
rendering-v2 display list of all 22 `fixtures/real-world` documents is
byte-identical, and amsmath is 59/59 within 0.5 bp with HW1/HW2 at 3 pages,
0 errors, 0 overfull.

Implementation-Agent: Claude Opus 5 (engine layout lane, linux-primary / NixOS)
Commit-Executor: Claude Opus 5 via Claude Code (direct-agent Git execution
under the observed-Cursor-limit user override)
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 14, 2026
…ion`

#258 rank 1, the highest-frequency layout divergence in the corpus: the
`abstract` body was set at `\normalsize` and the full measure with no head
at all, so everything below it sat 24.58 bp too high.

The blocker the previous lane named (#292) was a missing capability, not a
constant: `paragraph_block` hard-coded `body_size_pt`/`baselineskip_pt`, so
nothing could be set at a size other than `\normalsize` *with that size's
own leading*. `adapter::SizedPara` now carries what `\@setfontsize` changes
for one paragraph — the size, that size's `\baselineskip`, a `\parindent`
in the new size's own `em`, a trailing `\vspace` in `em` of the font its
last word is set in, and the closing `\@endparenv` skip of a list opened
while the size was in force.

article.cls 377-387 / report.cls 452-462, transcribed against the vendored
`document-style` (wiring `crates/title-layout` in was the alternative: it
depends on the *sibling* `document-style`, so its `Skip`/`Pt`/`Stylesheet`
are different types from the vendor mirror this crate builds against, and
adding it would break the `git archive` property the Cargo.toml documents.
It also models `gap_before_heading` as `\topsep + \parskip` with no
`\partopsep`, and its article.cls quote predates the `\vspace{-.5em}`):

* the head is `\begin{center}{\bfseries \abstractname\vspace{-.5em}
  \vspace{\z@}}\end{center}` at `\small`, centred at the FULL measure
  (`center` is a `\trivlist`, `\leftmargin` 0);
* the body is `\quotation`: `\leftmargini` both sides, `\listparindent
  1.5em` resolved in `\small`'s own `\fontdimen6` (13.87161 pt, not the
  `\normalsize` quad), `\small`'s 11 pt leading throughout;
* the opening glue is `\normalsize`'s `\topsep + \partopsep + \parskip`
  (10 pt plus 4 minus 5): `\small` only `\def`s `\@listi`, it never
  executes it;
* the closing glue is 6 pt plus 3 minus 3 — `\small`'s own `\@listi`
  `\topsep` of 4 pt plus `\partopsep`, not `\normalsize`'s 8 pt;
* the `quotation`'s own opening `\addvspace\@topsep` is absorbed whole by
  the `\end{center}` skip already on the list at every class size.

Every number above is read off pdfTeX's own vertical list for
`fixtures/divergence-probes/min-abstract` (`\showoutput`, TeX Live 2025),
quoted in `abstractenv.rs`.

The compiler has no model for the environment (it reports it and sets the
body as plain text), so the pipeline reads it from the source bytes, the way
it already reads `tikzpicture`, a list's `\begin` keys and a paragraph's
`\newpage`; its now-superseded diagnostic is dropped the way
`toc::superseded_commands` drops the contents-list ones. No compiler change
and no vendor re-pin, so the fix is live rather than feature-gated.

Not set here, reported as limitations instead of approximated: the
`\if@twocolumn` branch (`\section*{\abstractname}`) and the `titlepage`
branch (a page of its own between `\null\vfil`s). `book.cls` defines no
`abstract`, so it keeps the compiler's warning.

Measured, `tools/visual-oracle/rank.py` against the pinned TeX Live 2025
reference, geometry only (no rasterizer on this host):

  min-abstract p1  median dy -24.584 -> -0.000, max |dy| 35.54 -> 0.00,
                   words aligned 92/93 -> 93/93, reflowed 1 -> 0.

The residual max |dx| 1.30 is the probe's `\verb` on substituted `ec`
metrics (the bundle has no `ectt*.tfm`), the same caveat #292 recorded.

Corpus gates are still running; this is committed early so the work is not
held locally.

Implementation-Agent: linux-abstract lane (Claude Opus 5)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30

@GoKubar GoKubar closed this Sep 30, 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.

1 participant