Skip to content

compiler: a paragraph records the \baselineskip its \par read - #436

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

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

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What

Parsed records, per block, the \baselineskip TeX's \par would have read
for it: block_par_leading: Vec<ParLeading>, where ParLeading is
Option<FontSizeLevel> and None is \normalsize.

This is the compiler half of a two-PR split. The
render-pipeline half (agent/nixos-leading/par-leading-pipeline) consumes it and cannot land until
crates/render-pipeline/vendor/compiler is re-pinned past this commit
(vendor/VENDORING.md); it is written behind an off-by-default par-leading
feature so it builds and behaves identically against the current pin in the
meantime.

The rule, and why the obvious version of it is wrong

\small and friends are not font changes — each calls \@setfontsize with a
size and a \baselineskip. But TeX reads \baselineskip in
append_to_vlist (§679), which post_line_break (§877) calls once per line
at \par time. One value governs every line of a paragraph, and it is the
register's value when the paragraph ended.

So the leading does not follow "the size the words were typed at". Measured
with pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025) on
\documentclass[11pt]{article}, baseline-to-baseline in the shipped page:

probe pdflatex
body text 13.549 bp (13.6 pt)
{\small ...} then a blank line 13.549 bp — the } restores it before the \par
{\small ...\par} 11.955 bp (12 pt)
{\large ...\par} 13.948 bp (14 pt)
{\footnotesize ...\par} 10.959 bp (11 pt)
words {\small more} words 13.549 bp — a mid-paragraph switch never moves it
\begin{quote}\small ...\end{quote} 11.955 bp
\begin{itemize}\small \item ... 11.955 bp
\begin{minipage}{3in}\small ... 11.955 bp

Row 2 is the one that matters: a fix that read the paragraph's run sizes
("every glyph is \small, so use \small's leading") would get it wrong, and
it is a case the engine already handled correctly.

The one behaviour change

Rows 7–9 needed \end{...} to stop restoring the text style from
env_styles before the flushes that close the environment's last
paragraph — \endtrivlist runs \ifhmode\unskip\par\fi before \end's
\endgroup, so that \par is still inside the declaration. The restore now
sits next to the \centering/\raggedright one that was already deferred for
exactly this reason, under the comment that already said so:

// Restored only after the flushes above: environments that end their
// paragraph do so while their own declarations are still in force.

Everything else is additive: no block gains or loses a field, and nothing
existing reads the new vector.

Tests

New crates/compiler/tests/par_leading.rs, 7 tests, one per row above plus an
invariant test that block_par_leading stays one-entry-per-block across
headings, tabular, verbatim, displays and footnotes.

On main before this change, the two \end-ordering tests report

left:  [("Alpha", None),             ("Epsilon", None)]
right: [("Alpha", Some(Small)),      ("Epsilon", None)]
left:  [("Alpha", Some(FootnoteSize)), ("Gamma", None),                 ("Epsilon.", None)]
right: [("Alpha", Some(FootnoteSize)), ("Gamma", Some(FootnoteSize)),   ("Epsilon.", None)]

cargo test --release --no-fail-fast on crates/compiler: 0 failed.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

TeX reads `\baselineskip` in `append_to_vlist` (§679), which `post_line_break`
(§877) calls once per line at `\par` time. One value therefore governs every
line of a paragraph, and it is the register's value when the paragraph
*ended* — not the one in force where its words were typed. `Parsed` now
carries that value per block as `block_par_leading`, a `ParLeading`
(`Option<FontSizeLevel>`, `None` = `\normalsize`), read from the parser's own
style at the moment it flushes the paragraph.

Measured with pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025) on
`\documentclass[11pt]{article}`, baseline-to-baseline in the shipped page
(`\normalsize` 13.549 bp, `\small` 11.955 bp, `\footnotesize` 10.959 bp,
`\large` 13.948 bp):

  {\small ...}<blank line>                13.549   the `}` restores it first
  {\small ...\par}                        11.955   `\par` is inside the group
  words {\small more} words               13.549   a switch mid-paragraph
                                                   never moves the leading
  \begin{quote}\small ...\end{quote}      11.955   `\endtrivlist` pars before
  \begin{itemize}\small \item ...         11.955   `\end` closes the group
  \begin{minipage}{3in}\small ...         11.955

The last three needed one more change: `\end{...}` restored the text style
from `env_styles` *before* the flushes that close the environment's last
paragraph, so that `\par` saw the outer size. It now restores after them,
next to — and for exactly the same reason as — the `\centering`/`\raggedright`
restore that already sat there ("environments that end their paragraph do so
while their own declarations are still in force").

No block gains or loses a field and nothing existing reads the new vector, so
this is additive: `crates/render-pipeline`, which builds against a pinned
`vendor/compiler`, is unaffected until that mirror is re-pinned. The pipeline
half is a separate PR.

`crates/compiler`: `cargo test --release --no-fail-fast` 0 failed (327 in the
lib plus every integration binary). New `tests/par_leading.rs`, 7 tests; on
main before this change two of them report
`left: [("Alpha", None), ("Epsilon", None)]` against
`right: [("Alpha", Some(Small)), ...]` — the `\end`-ordering cases.

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 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Pipeline half: #437. It is blocked on re-pinning crates/render-pipeline/vendor/compiler past this commit (vendor/VENDORING.md); until then its par-leading feature stays off and the crate behaves exactly as it does today.

@GoKubar
GoKubar merged commit e2da682 into main Sep 14, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/nixos-leading/par-leading-compiler branch September 14, 2026 18:45
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]>
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