Skip to content

render-pipeline: \paragraph/\subparagraph are run-in headings - #404

Merged
GoKubar merged 1 commit into
mainfrom
lane/nixos-gfxsec/paragraph-headings
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
lane/nixos-gfxsec/paragraph-headings

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What

\paragraph and \subparagraph are \@startsection with a negative after-skip (article.cls lines 406-414). \@xsect's negative-#5 branch never sets the head as a vertical block: it arms \everypar, which throws away the following paragraph's \parindent box ({\setbox\z@\lastbox}), sets \hskip #3 <head> in its place and then \hskip -#5. The head is the first words of that paragraph.

That is what makes this a pipeline-only change. The compiler does not parse the command — it reports it and sets the braced argument as ordinary body text, which lands at the front of exactly the paragraph LaTeX runs the head into. The title words are already in the right place with the right spans; what was missing was the weight, the indent, the 1 em and the skip above.

Before: the head was set at \parindent in the body face with an ordinary interword space after it and no skip above — dx +14.94 bp, dy −13.94 bp per occurrence.

Four things the oracle pinned down

Each measured against pdflatex (TeX Live 2025):

  1. #3 differs by level. \z@ for \paragraph, \parindent for \subparagraph — 72.000 against 86.944 at 10 pt.
  2. The interword glue inside the head is the head font's \fontdimen2, not the body's. ecbx1000 is 0.47 bp wider per space at 10 pt; this showed as −0.93 bp on the head's third word until the Item::Space style was switched too.
  3. \addvspace takes the max, not the sum (\@xaddvskip). Every \paragraph{Solution.} in ps-calculus follows \end{enumerate}, whose \endtrivlist already contributed \addvspace\@topsepadd. Summing them put each head ~1.5 bp low and dragged the rest of the page down — it cost that fixture 9 pp of dy before the max went in.
  4. \paragraph*: the compiler does not consume the star, so it arrived as the first character of the title and pushed the line 5.73 bp right.

Oracle evidence

fixtures/divergence-probes/min-paragraph, words within 0.5 bp in x and y: 20/74 → 74/74. A probe with all three forms, and one with a head after a list, are exact too — every word within 0.01 bp.

probe before after
\paragraph head x / baseline +14.94 / −13.94 0.000 / 0.003
\subparagraph head x +14.94 0.000 (at \parindent, 86.944)
\paragraph* head x +14.94 (plus a literal *) 0.000, no star
head after \end{enumerate} (11 pt) — baseline within 0.004 bp

Corpus

22 real documents vs pdflatex, tolerance 0.5 bp:

before after
dx 84.47% 84.67%
dy 65.21% 65.21%
both 58.67% 58.67%
page counts 20/22 20/22

ps-calculus is the only fixture that moves, and only in x: dx 66.02 → 70.57.

The vertical drift in ps-calculus is not these heads

It was attributed to "four missing \paragraph head skips" (−21.4 / −62.6 / −101.3 bp down pages 1–3). With the heads correct the drift is still −21 / −44..−83 / −98 bp: the four heads account for about 3.3 bp in total, because \addvspace absorbs the rest into the list's own skip. That residual has another cause and is not touched here — worth its own lane.

Files touched

  • crates/render-pipeline/src/adapter.rs (RunIn, run_in_heading_at, apply_run_in_heading, the UnitKind::Paragraph arm)
  • crates/render-pipeline/src/style.rs (HeadingStyle::run_in_after_em; the heading table now carries all five \@startsection levels, removing the expect("levels 1..=3"))
  • crates/render-pipeline/tests/run_in_headings.rs (new, 3 tests)

No crates/render-pipeline/vendor/* change; no compiler-side change; no vendor re-pin required.

Known follow-up (not this PR): the compiler still emits unsupported_feature: \paragraph is not supported by this compiler version. The layout is now correct, so that diagnostic is stale noise in the Problems panel. Removing it is a crates/compiler change and therefore a separate PR plus a vendor re-pin — filed separately rather than bundled here.

Gates

cargo test --release --no-fail-fast with FLASHTEX_FONT_DIRS/FLASHTEX_TFM_DIRS set:

  • crates/render-pipeline 257 passed / 0 failed / 2 ignored
  • crates/class-geometry 4 passed / 0 failed
  • crates/compiler 577 passed / 0 failed / 4 ignored
  • amsmath 59/59, tabular 106/106
  • HW1 and HW2: 3 pages, 0 errors, 0 font-FAILURE diagnostics

Coordination

Touches adapter.rs, style.rs and one new test file. Independent of #395, #396 and #399. Does not touch the per-page vertical constant in lmodern-report/plain-article; neither fixture moves at all here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

@GoKubar

GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (fb79c646, now carrying #405 and #400) and re-measured. One real conflict, resolved rather than taken from either side: #405 turned the list skips into glue (addvspace_flex), so \@startsection's \addvspace now has to keep the whole larger glue — stretch and shrink with it — not just compare natural sizes. \paragraph's skip is 3.25ex \@plus1ex \@minus.2ex, and that \@plus1ex now reaches the page builder.

Corpus, 22 documents vs pdflatex, tolerance 0.5 bp:

before after
dx 85.74% 85.94%
dy 75.93% 75.93%
both 69.79% 69.79%
page counts 21/22 21/22

ps-calculus is still the only fixture that moves, and only in x: dx 66.02 → 70.57. fixtures/divergence-probes/min-paragraph is exact — all 74 words within 0.5 bp in x and y.

Gates on the rebase: render-pipeline 270 passed / 0 failed / 2 ignored, class-geometry 4/0, compiler 581/0/4; amsmath 59/59, tabular 106/106, HW1 and HW2 3 pages / 0 errors / 0 font-FAILURE diagnostics.

The ps-calculus vertical drift survives #405 and #400 too

Worth recording, since this fixture was assigned to me on the theory that the drift was the four missing \paragraph head skips (−21.4 / −62.6 / −101.3 bp down pages 1–3). It is not, and it is not the list-glue or \brokenpenalty work either: on current main with this PR applied, ps-calculus dy is 12.03%, exactly what it is without it. The four heads account for about 3.3 bp in total, because \addvspace absorbs the rest into the \endtrivlist skip each head follows. Something else owns that residual — it is the largest single dy hole left in the corpus and deserves its own lane.

@GoKubar
GoKubar force-pushed the lane/nixos-gfxsec/paragraph-headings branch from 19ada19 to c1e5dd4 Compare September 14, 2026 16:38
`\paragraph` and `\subparagraph` are `\@startsection` with a *negative*
after-skip (article.cls lines 406-414). `\@xsect`'s negative-`#5` branch
never sets the head as a vertical block: it arms `\everypar`, which throws
away the following paragraph's `\parindent` box
(`{\setbox\z@\lastbox}`), sets `\hskip #3 <head>` in its place and then
`\hskip -#5`. The head *is* the first words of that paragraph.

That is what makes this a pipeline-only change. The compiler does not parse
the command — it reports it and sets the braced argument as ordinary body
text, which lands at the front of exactly the paragraph LaTeX runs the head
into. The title words are already in the right place with the right spans;
what was missing was the weight, the indent, the 1 em and the skip above.
So: no new block type, no compiler change, no vendor re-pin.

Before, the head was set at `\parindent` in the body face with an ordinary
interword space after it and no skip above: dx **+14.94 bp**, dy
**-13.94 bp** per occurrence.

Four things the oracle pinned down, each measured against pdflatex
(TeX Live 2025):

* `#3` is `\z@` for `\paragraph` and `\parindent` for `\subparagraph`, so
  one head is flush and the other is not (72.000 against 86.944 at 10 pt).
* The interword glue *inside* the head is the head font's `\fontdimen2`,
  not the body's: `ecbx1000` is 0.47 bp wider per space at 10 pt, which
  showed up as -0.93 bp on the head's third word.
* `\addvspace` keeps whichever of the new skip and `\lastskip` is larger
  (`\@xaddvskip`); it does not add to it. Every `\paragraph{Solution.}` in
  `fixtures/real-world/ps-calculus` follows `\end{enumerate}`, whose
  `\endtrivlist` already contributed `\addvspace\@topsepadd`. Summing the
  two put each head ~1.5 bp low and dragged the rest of the page down —
  it cost that fixture 9 pp of `dy` before the `max` went in.
* `\paragraph*`: the compiler does not consume the star, so it arrived as
  the first character of the title and pushed the line 5.73 bp right.

`fixtures/divergence-probes/min-paragraph` is now exact: all 74 words
within 0.5 bp in x and y (was 20 of 74). A probe with all three forms and
one with a head after a list are exact too — every word within 0.01 bp.

Corpus (22 real documents vs pdflatex, tolerance 0.5 bp):
dx 84.47% -> 84.67%, dy 65.21% (unchanged), both 58.67% (unchanged), page
counts 20/22 unchanged. `ps-calculus` is the only fixture that moves, and
only in x: dx 66.02 -> 70.57.

**The vertical drift in `ps-calculus` is not these heads.** It was
attributed to "four missing `\paragraph` head skips" (-21.4 / -62.6 /
-101.3 bp down pages 1-3). With the heads correct the drift is still
-21 / -44..-83 / -98 bp: the four heads account for about 3.3 bp of it in
total, because `\addvspace` absorbs the rest into the list's own skip. That
residual has some other cause and is not touched here.

Also removes the `expect("levels 1..=3")` in the heading table: the
stylesheet now carries all five `\@startsection` levels, and
`HeadingStyle` gains `run_in_after_em` for the negative after-skip.

Gates: `cargo test --release --no-fail-fast` on render-pipeline 257 passed
/ 0 failed / 2 ignored (three new `run_in_headings` tests), class-geometry
4/0, compiler 577/0/4; amsmath 59/59, tabular 106/106, HW1 and HW2 3 pages
/ 0 errors / 0 font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-graphics-sectioning, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar force-pushed the lane/nixos-gfxsec/paragraph-headings branch from c1e5dd4 to ce05ce0 Compare September 14, 2026 16:49
@GoKubar

GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 31b84428 and re-measured. One conflict, from #399 and this PR both inserting helpers ahead of command_words in adapter.rs — both are additions, so both are kept; nothing was dropped from either side. (The earlier rebase onto #405 had a substantive conflict, resolved then: \@startsection's \addvspace now keeps the whole larger glue, stretch and shrink included, so \paragraph's 3.25ex \@plus1ex \@minus.2ex reaches the page builder as glue rather than a bare natural width.)

Corpus, 22 documents vs pdflatex, tolerance 0.5 bp, baseline measured at 31b84428 itself:

before after
dx 85.89% 86.09%
dy 76.07% 76.07%
both 70.03% 70.03%
page counts 22/22 22/22
aligned words 14135 14135

ps-calculus is still the only fixture that moves, and only in x: dx 66.02 → 70.57. Every other fixture is identical. fixtures/divergence-probes/min-paragraph is exact — all 74 words within 0.5 bp in x and y.

Gates: render-pipeline 274 passed / 0 failed / 2 ignored, class-geometry 4/0, compiler 581/0/4; amsmath 59/59, tabular 106/106, HW1 and HW2 3 pages / 0 errors / 0 font-FAILURE diagnostics.

GitHub now reports the PR MERGEABLE.

@GoKubar
GoKubar merged commit a63537f into main Sep 14, 2026
10 of 21 checks passed
@GoKubar
GoKubar deleted the lane/nixos-gfxsec/paragraph-headings branch September 14, 2026 16:58
d-q222 added a commit that referenced this pull request Sep 14, 2026
TeX Live 2026: with geometry, \pdfpagewidth=361.34999pt after
\setlength{\paperwidth}{5in}; without geometry \pdfpagewidth=614.295pt
(US Letter) while \paperwidth is 5in.

cargo test compiler --lib: ok. 327 passed; preamble_lengths: 9 passed;
supported_latex: 8 passed; full compiler suite green (4 ignored).
render-pipeline --lib: ok. 119 passed; 2 ignored; preamble_lengths_oracle:
5 passed; full pipeline suite green.
Next: git merge origin/main (#404 adapter.rs).

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged origin/main with ort; no conflicts. #404 auto-merged into adapter.rs
(run-in paragraph/subparagraph headings). class-geometry was not edited.

Commands and test result: lines:
- cargo test --manifest-path crates/compiler/Cargo.toml --lib dimen_parsing
  test result: ok. 1 passed; 0 failed; 0 ignored
- cargo test --manifest-path crates/compiler/Cargo.toml --test preamble_lengths
  test result: ok. 9 passed; 0 failed; 0 ignored
- cargo test --manifest-path crates/render-pipeline/Cargo.toml --lib adapter::tests
  test result: ok. 25 passed; 0 failed; 2 ignored
- cargo test --manifest-path crates/render-pipeline/Cargo.toml --lib
  test result: ok. 119 passed; 0 failed; 2 ignored
- cargo test --manifest-path crates/render-pipeline/Cargo.toml --test run_in_headings
  test result: ok. 3 passed; 0 failed; 0 ignored
- cargo test --manifest-path crates/render-pipeline/Cargo.toml --test preamble_lengths_oracle
  test result: ok. 5 passed; 0 failed; 0 ignored

The two ignored adapter tests are known limits (\input preambles; \@setlength).

Next step: push this lane branch. No further code changes.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[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