Skip to content

render-pipeline: a paragraph's leading follows the size declaration its \par ran under - #437

Merged
GoKubar merged 1 commit into
mainfrom
agent/nixos-leading/par-leading-pipeline
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/nixos-leading/par-leading-pipeline

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What

A paragraph's \baselineskip now follows the size declaration in force when
its \par ran, instead of always being the body's. This is the
render-pipeline half of a two-PR split; the compiler half (#436)
supplies Parsed::block_par_leading.

Blocked on a vendor re-pin. It builds against
crates/render-pipeline/vendor/compiler, pinned at e44d5917, which predates
that field, so the read is behind an off-by-default par-leading feature —
the pattern amsmath-inline, request-date and compiler-package-gating
already use. With the feature off the crate builds against the current pin and
every paragraph keeps the body leading exactly as before (275 tests pass, the
9 new ones compile out). After the re-pin, turning it on is a one-line
default-feature edit.

Mechanism

Block::Paragraph gains leading_pt: Option<f64>, fed from the compiler
through lower_blocks → UnitKind::Paragraph → paragraph_block. It is
deliberately narrower than the existing SizedPara, which resizes a whole
paragraph: only \baselineskip moves, for the paragraph's lines and the
glue above its first one (post_line_break appends them all under one
register). The runs keep the sizes they were typed at — §679 never looks at
the boxes it stacks — which is why {\small ...} whose } precedes the blank
line keeps the body's 13.6 pt even though every glyph on those lines is
\small, and why reading the paragraph's run sizes would be the wrong fix.

§679 itself was already right (linebreak.rs, pagebuild.rs, pages.rs
all implement prev_depth/lineskiplimit/lineskip identically); only the
scalar handed to it was wrong.

Oracle

pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025), article 11 pt,
baseline-to-baseline in bp:

probe before after pdflatex
body text 13.549 13.549 13.549
{\small ...} + blank line 13.549 13.549 13.549
{\small ...\par} 13.549 11.955 11.955
{\large ...\par} 13.549 13.948 13.948
{\footnotesize ...\par} 13.549 10.959 10.959
words {\small more} words 13.549 13.549 13.549
\begin{quote}\small ... 13.550 11.955 11.955
\begin{itemize}\small \item ... 13.549 11.955 11.955

On a probe holding all of these, every baseline now matches the reference PDF
exactly down to the \parbox case, which is a separate unimplemented command.

The narrower leading makes §679's other branch reachable, so the rule is
checked too, not just the number: a \Huge box on one line of a
\footnotesize paragraph drives \baselineskip - \prevdepth - height below
\lineskiplimit, and that one gap opens to \lineskip's 19.674 bp while
its neighbours stay at 10.959. pdflatex's baselines for that probe are
82.959 / 102.633 / 113.592 / 124.551; ours are
82.959 / 102.634 / 113.592 / 124.551.

The \maketitle fallback in lower_blocks (used when the class frame is
absent) got the same treatment, and the oracle corrected the obvious guess:
\@maketitle puts a \par inside the title's and authors' groups but not the
date's — {\LARGE \@title \par}, {\large ...\par}, then {\large \@date}
and only then \end{center}. On a wrapping \date, pdflatex sets the title
21.918 bp apart and the date 13.549, the body's, not \large's 13.948.

Gates

With the feature on and vendor/compiler locally synced to the compiler PR
(not committed here) so the path could be measured end to end:

  • cargo test --release --no-fail-fast: 283 passed, 0 failed, 2 ignored
    (275 / 0 / 2 with the feature off, against the untouched pin)
  • amsmath 59/59, tabular 106/106
  • HW1 and HW2: 3 pages, 0 errors
  • all 22 real-world fixtures match pdflatex's page count; zero
    font-FAILURE diagnostics
  • tools/visual-oracle/rank.py output is byte-identical to the unpatched
    build's apart from the timestamp: dx 85.59 %, dy 75.08 %, both 69.02 %

The corpus does not move because no fixture writes a size declaration that
spans a \par. listings-manual's does — \lstset{basicstyle=\ttfamily \small} — but \lstset keys are still unparsed, and the existing
unsupported_block limitation still names basicstyle, frame, numbers
and caption.

New tests/par_leading_oracle.rs, 9 tests, also behind the feature; every
constant in it was read out of the reference PDF pdflatex produced for the
probe quoted in that test.

pdflatex is an oracle only and never runs in the product path.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…ts `\par` ran under

`\small` and friends are not font changes: `\@setfontsize` sets a size *and*
a `\baselineskip`. The pipeline applied the size (`TextStyle::size_cpt`) and
kept the body's leading for every paragraph but `abstract`'s, so
`\begin{quote}\small ...\end{quote}` came out 13.6 pt apart where pdflatex
sets 12 pt.

`Block::Paragraph` gains `leading_pt`, fed from the compiler's
`Parsed::block_par_leading` through `lower_blocks` and
`UnitKind::Paragraph`, and `paragraph_block` takes it as `leading`. It is
deliberately narrower than the existing `SizedPara`: only `\baselineskip`
moves, for the paragraph's lines *and* for the glue above its first one
(`post_line_break` appends them all under one register). The runs keep the
sizes they were typed at, because TeX's §679 never looks at the boxes it is
stacking — which is why `{\small ...}` whose `}` precedes the blank line
keeps the body's leading even though every glyph on those lines is small,
and why reading the paragraph's run sizes instead would be wrong.

Baseline-to-baseline against pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025),
`article` 11pt, in bp — before / after / reference:

  body text                            13.549 / 13.549 / 13.549
  {\small ...}<blank>                  13.549 / 13.549 / 13.549
  {\small ...\par}                     13.549 / 11.955 / 11.955
  {\large ...\par}                     13.549 / 13.948 / 13.948
  {\footnotesize ...\par}              13.549 / 10.959 / 10.959
  words {\small more} words            13.549 / 13.549 / 13.549
  \begin{quote}\small ...              13.550 / 11.955 / 11.955
  \begin{itemize}\small \item ...      13.549 / 11.955 / 11.955

`lower_blocks`' `\maketitle` fallback (the path taken when the class frame is
absent, so `Block::Title` does not run) gets the same treatment, and the
oracle corrected the obvious guess there: `\@maketitle` closes the title's and
the authors' groups with a `\par` inside but the date's without one
(`{\LARGE \@title \par}`, `{\large ...\par}`, then `{\large \@Date}` and only
then `\end{center}`), so on a `\date` long enough to wrap pdflatex sets the
title 21.918 bp apart and the date **13.549** — the body's, not `\large`'s
13.948. The date carries no leading of its own here.

Behind the `par-leading` feature, off by default: it needs a
`vendor/compiler` carrying `Parsed::block_par_leading` (the compiler PR).
With the feature off every paragraph keeps the body leading exactly as
before, so this builds and behaves identically against the current pin;
turning it on after the re-pin is a one-line default-feature edit, like
`amsmath-inline` was.

Gates, with the feature on and `vendor/compiler` locally synced to the
compiler PR for the measurement: `cargo test --release --no-fail-fast` 283
passed / 0 failed / 2 ignored; amsmath 59/59, tabular 106/106; HW1 and HW2 3
pages / 0 errors; all 22 real-world fixtures match pdflatex's page count; zero
font-FAILURE diagnostics. The visual-oracle report is byte-identical to the
one from the unpatched build apart from its timestamp (dx 85.59%, dy 75.08%,
both 69.02%): no corpus fixture writes a size declaration that spans a `\par`.
`listings-manual` is unmoved for that reason — its `\lstset{basicstyle=
\ttfamily\small}` is still unparsed, and the existing `unsupported_block`
limitation still names `basicstyle`, `frame`, `numbers` and `caption`.

The narrower leading also makes §679's other branch reachable, so the rule is
checked, not just the number: a `\Huge` box on one line of a `\footnotesize`
paragraph drives `\baselineskip - \prevdepth - height` below `\lineskiplimit`
and that gap opens to `\lineskip`'s 19.674 bp while its neighbours stay at
10.959 — pdflatex 82.959/102.633/113.592/124.551, ours
82.959/102.634/113.592/124.551.

New `tests/par_leading_oracle.rs` (9 tests, also behind the feature).

Implementation-Agent: Claude Opus 5 (lane nixos-leading, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
@GoKubar
GoKubar merged commit faa7d48 into main Sep 14, 2026
21 checks passed
GoKubar added a commit that referenced this pull request Sep 14, 2026
…n `par-leading` on

`vendor/compiler` is re-pinned to `faa7d484` (WIP commit df05f74); this makes
the pipeline compile against what it finds there and switches `par-leading` on.

`par-leading` was inert: #437's `Block::Paragraph::leading_pt` needs #436's
`Parsed::block_par_leading`, which the old pin did not carry. Measured end to
end from a clean checkout, not inferred from a green build: `{\small ...\par}`
in an 11pt article now sets baselines 11.955 bp apart, exactly pdflatex's
11.955 bp (`\small` = 12pt in size11.clo); the old pin gave 13.549 bp, i.e.
`\normalsize`, wrong by 1.594 bp per line.

Three moved compiler APIs, none swallowed by a wildcard arm:

* `Inline::HFill { leader }` (#320). The glue is set exactly — `\hrulefill`
  and `\dotfill` are `\leavevmode\leaders<box>\hfill\kern\z@`, so all three
  parts are emitted. Both extras are load-bearing: `\leavevmode` keeps a lone
  `\hrulefill` paragraph from being dropped along with the `\vspace` before it
  (that took `enumitem-worksheet` from 3 pages to 2), and `\kern\z@` stops
  TeX's end-of-paragraph final-glue deletion (tex.web §816) from eating a
  trailing fill. The leader box is *not* painted — this pipeline has no
  leaders outside `typeset/toc.rs`, and paragraph-layout reports no per-glue
  set width — so every occurrence is lowered with a typed `unsupported_inline`
  warning naming the command. `fixtures/divergence-probes/min-hrulefill`, which
  recorded `Date:` 198.51 bp left of pdflatex, is now 0.55 bp from the oracle.
* `Diagnostic.labels`/`.notes`/`.help` (#346/#389). display-list-v2's
  diagnostic is `additionalProperties: false` over `{code, message, severity,
  sources}`, so rather than invent wire fields, `from_compiler` folds them onto
  the fields that already mean the same thing: label spans join `sources`,
  their texts plus notes and help become `[note: …]`/`[help: …]` clauses on
  `message`, and `help.replacement` back-fills `suggestion`. One line only —
  `flashtex-render --tex` prints `severity[code] message (line:col)` per line.
* `Inline::Underline` (#328/#390). PR #329 was written for this re-pin, is
  pipeline-only and applied cleanly; its only integration gap was a `VBlock`
  literal predating `broken_penalty`.

The pin itself also starts warning `unsupported_feature` for
`\usepackage{amsmath}`, which `e44d5917` did not. That line is user-visible on
every amsmath document and claims "not implemented" about constructs this
pipeline does set — a cross-crate disagreement for the owners, not something a
re-pin settles. `tests/amsmath_inline.rs` excludes that one wording by a
documented predicate and stays strict about everything else.

Gates: render-pipeline 295 passed / 0 failed / 2 ignored (254 before);
compiler 588 / 0 / 4; amsmath 59/59; tabular 106/106; HW1 and HW2 3 pages,
0 errors, 0 font-FAILURE diagnostics; corpus page counts 22/22.

Corpus geometry (rank.py, same pdf-exact, only the producer varying), before →
after: dx 85.74% → 85.61%, dy 75.04% → 75.73%, both 68.97% → 69.11%, aligned
words 15073 → 15099, reflowed 131 → 129. 21 of 22 fixtures are bit-identical;
all movement is `enumitem-worksheet` (dy +34.14 pp, aligned 332 → 357) plus one
word in `unicode-accents`. That fixture's dx percentage falls 2.75 pp while its
absolute count rises 157 → 159: 25 more words are measured, and the new ones
sit outside 0.5 bp because the leader rule is still unpainted.

No other vendor directory needed re-pinning; the four that differ from `main`
do so by their own rows' deliberate choices, and the vendored compiler
type-checks against them.

Implementation-Agent: Claude Opus 5 (lane vendor-repin-2, linux-primary)
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 added a commit that referenced this pull request Sep 14, 2026
… catch the pipeline up to it (#451)

* WIP: vendor/compiler re-pinned to faa7d48 + par-leading enabled (does not compile yet)

* render-pipeline: build against the re-pinned vendor/compiler, and turn `par-leading` on

`vendor/compiler` is re-pinned to `faa7d484` (WIP commit df05f74); this makes
the pipeline compile against what it finds there and switches `par-leading` on.

`par-leading` was inert: #437's `Block::Paragraph::leading_pt` needs #436's
`Parsed::block_par_leading`, which the old pin did not carry. Measured end to
end from a clean checkout, not inferred from a green build: `{\small ...\par}`
in an 11pt article now sets baselines 11.955 bp apart, exactly pdflatex's
11.955 bp (`\small` = 12pt in size11.clo); the old pin gave 13.549 bp, i.e.
`\normalsize`, wrong by 1.594 bp per line.

Three moved compiler APIs, none swallowed by a wildcard arm:

* `Inline::HFill { leader }` (#320). The glue is set exactly — `\hrulefill`
  and `\dotfill` are `\leavevmode\leaders<box>\hfill\kern\z@`, so all three
  parts are emitted. Both extras are load-bearing: `\leavevmode` keeps a lone
  `\hrulefill` paragraph from being dropped along with the `\vspace` before it
  (that took `enumitem-worksheet` from 3 pages to 2), and `\kern\z@` stops
  TeX's end-of-paragraph final-glue deletion (tex.web §816) from eating a
  trailing fill. The leader box is *not* painted — this pipeline has no
  leaders outside `typeset/toc.rs`, and paragraph-layout reports no per-glue
  set width — so every occurrence is lowered with a typed `unsupported_inline`
  warning naming the command. `fixtures/divergence-probes/min-hrulefill`, which
  recorded `Date:` 198.51 bp left of pdflatex, is now 0.55 bp from the oracle.
* `Diagnostic.labels`/`.notes`/`.help` (#346/#389). display-list-v2's
  diagnostic is `additionalProperties: false` over `{code, message, severity,
  sources}`, so rather than invent wire fields, `from_compiler` folds them onto
  the fields that already mean the same thing: label spans join `sources`,
  their texts plus notes and help become `[note: …]`/`[help: …]` clauses on
  `message`, and `help.replacement` back-fills `suggestion`. One line only —
  `flashtex-render --tex` prints `severity[code] message (line:col)` per line.
* `Inline::Underline` (#328/#390). PR #329 was written for this re-pin, is
  pipeline-only and applied cleanly; its only integration gap was a `VBlock`
  literal predating `broken_penalty`.

The pin itself also starts warning `unsupported_feature` for
`\usepackage{amsmath}`, which `e44d5917` did not. That line is user-visible on
every amsmath document and claims "not implemented" about constructs this
pipeline does set — a cross-crate disagreement for the owners, not something a
re-pin settles. `tests/amsmath_inline.rs` excludes that one wording by a
documented predicate and stays strict about everything else.

Gates: render-pipeline 295 passed / 0 failed / 2 ignored (254 before);
compiler 588 / 0 / 4; amsmath 59/59; tabular 106/106; HW1 and HW2 3 pages,
0 errors, 0 font-FAILURE diagnostics; corpus page counts 22/22.

Corpus geometry (rank.py, same pdf-exact, only the producer varying), before →
after: dx 85.74% → 85.61%, dy 75.04% → 75.73%, both 68.97% → 69.11%, aligned
words 15073 → 15099, reflowed 131 → 129. 21 of 22 fixtures are bit-identical;
all movement is `enumitem-worksheet` (dy +34.14 pp, aligned 332 → 357) plus one
word in `unicode-accents`. That fixture's dx percentage falls 2.75 pp while its
absolute count rises 157 → 159: 25 more words are measured, and the new ones
sit outside 0.5 bp because the leader rule is still unpainted.

No other vendor directory needed re-pinning; the four that differ from `main`
do so by their own rows' deliberate choices, and the vendored compiler
type-checks against them.

Implementation-Agent: Claude Opus 5 (lane vendor-repin-2, linux-primary)
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

* render-pipeline: an appended `[help: …]` clause must not defeat the package supersede

Regression in this branch, found in review of #451. `from_compiler` appends the
compiler's structured `help`/`notes` to `message` as ` [help: …]` clauses;
`packages::supersede_message` ends its match with

    strip_suffix(" are recognised but not implemented")

so with a clause on the end the match failed, the `else` branch returned the
message unchanged, and every superseded `\usepackage` diagnostic leaked into the
render output. Not just amsmath: every package in `implemented_by_pipeline` —
amsfonts, lmodern, microtype, geometry, graphicx, tikz — and the mixed list too,
where `packages amsmath, booktabs, …` should be trimmed to `booktabs` and was
instead shown in full, telling the reader this pipeline does not implement things
it does.

`split_clauses` now peels trailing clauses off the body before matching and
re-attaches them to whatever survives a trimmed list. It keys on the clause
*shape* — ` [<label>: <text>]` with a plain-word label, bracket-depth aware so
clause text may contain brackets and a body merely ending in `]` is not eaten —
rather than on the two labels that exist today, so a third kind appended later
needs no further fix. `preamble_command_superseded` reads the body too: `lib.rs`
calls it on the compiler's diagnostic *before* the conversion, so it was not
leaking, but it compares the whole message for equality and would the moment that
call moved.

Measured on the owner's fixtures, before → after: HW1 6 → 4 diagnostics, HW2
9 → 7, `unsupported_feature` leaks 2 → 0 in each; what remains is
`math_resource_profile`, which is informational.

This also retracts a wrong conclusion in the previous commit. I had reported the
amsmath warning as purely a consequence of the re-pin and loosened
`tests/amsmath_inline.rs` to tolerate it. The pin does newly emit it, but it never
reaches a consumer — the supersede drops it — so it was visible only because of
the bug above. That test is restored to `main`'s strict assertion and passes 11/11
on its own.

Tests: `packages` unit tests for a superseded message with a clause (each of the
eight packages), the mixed list with a clause, several clauses, clause text
holding brackets, and bodies that merely end in `]`; plus two end-to-end tests in
`compiler_diagnostic_forward` covering the real render path, which is where the
clause actually gets appended. The existing `supersede_message` tests all used
bare messages, which is why this got through.

Gates re-run: render-pipeline 303 passed / 0 failed / 2 ignored; amsmath 59/59;
tabular 106/106; HW1 and HW2 3 pages, 0 errors, 0 font-FAILURE diagnostics;
corpus page counts 22/22. Corpus geometry is unchanged by this commit (dx 85.61%,
dy 75.73%, both 69.11%, aligned 15099) — the supersede moves diagnostics, not
glyphs.

Implementation-Agent: Claude Opus 5 (lane vendor-repin-2, linux-primary)
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

---------

Co-authored-by: Claude Opus 5 <[email protected]>
@GoKubar
GoKubar deleted the agent/nixos-leading/par-leading-pipeline branch September 16, 2026 04:17
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