Skip to content

render-pipeline: a verbatim body inside a list is a trivlist inside that list (14/17) - #268

Closed
GoKubar wants to merge 2 commits into
agent/kabir-claude/verbatim-listings-relandingfrom
agent/kabir-claude/verbatim-trivlist-in-list
Closed

GoKubar wants to merge 2 commits into
agent/kabir-claude/verbatim-listings-relandingfrom
agent/kabir-claude/verbatim-trivlist-in-list

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Stacked on #262 (agent/kabir-claude/verbatim-listings-relanding) — review that one first; this PR's own diff is the last commit, 3 files, +77/−14. crates/render-pipeline only; no vendor edits, no compiler changes.

Fixture 10-verbatim-itemize matches pdfLaTeX exactly. 13 of 17 → 14 of 17, worst 0.006 bp.

What pdfTeX actually does

\@verbatim is \trivlist \item\relax … \leftskip\@totalleftmargin, so a verbatim inside an enumerate item is a trivlist inside that list. Dumped with \showboxbreadth=200 \showboxdepth=10 \showoutput, the fixture's page has this between the item's line and the first verbatim line:

\glue 12.0 plus 4.0 minus 5.0
\glue -12.0 plus -4.0 minus -5.0
\glue 8.0 plus 2.0 minus 4.0
\glue 4.0 plus 2.0 minus 1.0
\glue(\parskip) 0.0
\glue(\parskip) 0.0
\glue(\baselineskip) 5.88889
\hbox(6.11111+0.0)x345.0 … \glue(\leftskip) 25.00003

Net 12 pt above, and \leftskip 25.00003 on every verbatim line. Between the last verbatim line and the next \item:

\glue 8.0 plus 2.0 minus 4.0
\glue -8.0 plus -2.0 minus -4.0
\glue 8.0 plus 2.0 minus 4.0
\glue(\parskip) 4.0 plus 2.0 minus 1.0
\glue(\parskip) 0.0

net 12 pt again — but built differently: 8 pt from \@endparenv plus 4 pt of the next item's own \parskip.

That asymmetry is the whole point of this change:

  • \@trivlist sets \@topsepadd \topsep, then \@topsep \@topsepadd, then \advance\@topsep \parskip. Inside a list \parskip is \parsep (\list sets \parskip\parsep), which article's \@listi puts at 4 pt at 10 pt — so 8 + 4 = 12 above.
  • \@endparenv adds \@topsepadd, fixed at \topsep before that \advance — so the closing skip carries no \parskip: 8, not 12.

I had it symmetric on the first attempt and fixture 10 then failed the other way: the verbatim lines landed exactly right and everything after them sat 4 pt low. The \showoutput dump is what settled it.

Before / after, measured

pdfLaTeX before after
verbatim line 1 baseline 158.675 154.690 158.675
verbatim line 1 x 158.675 133.768 158.675
verbatim line 2 x (2 leading spaces) 169.136 144.229 169.136
item 2 baseline 194.541 190.555 194.541
following paragraph baseline 216.458 212.473 216.458

The change

  • EnvOpen gains outer_parskip — the \parskip in force where \begin was read: zero at the outer level, the enclosing list's \parsep inside one, read from the source with the existing list_stack_at + list_seps_with.
  • env_skip adds it to the natural amount; env_after passes zero, which is what \@endparenv does.
  • A verbatim-family block opening inside a list gets a ListGeom with the enclosing margins, no label and no \parsep, so paragraph_block's existing \@totalleftmargin hang applies. \@verbatim sets \parskip\z@, which is why the parsep here is zero and not the list's.

Deliberately scoped to the verbatim family

verbatim_env_after_begin restricts this to verbatim, verbatim* and lstlisting.

center/quote inside a list have the same shape of bug but not the same size, and nothing in this lane pins them. Measured on a scratch center inside an enumerate item: pdfLaTeX centres it within the indented measure, first glyph at x 276.663, and sets it 24.0 pt below the item's baseline; this pipeline sets it flush left at 158.675, 16.0 pt down. That is 8 pt short, not 4 — so the \parskip term alone would not fix it, and applying it would move center, quote and quotation with no fixture to catch the result. Left exactly as it was; recorded here so the next lane starts from a measurement rather than a hunch.

Gates — control-compared

Control is a git archive checkout of eea975c3 (this stack's base), built and measured the same way with the same bundled fonts configured.

gate control this branch
crates/render-pipeline cargo test --release --no-fail-fast 202 / 0 / 1 206 / 0 / 1
amsmath oracle corpus — 59 / 59 within 0.5 bp
real-world corpus: status, pages and diagnostics per fixture/producer — identical, entry for entry
real-world corpus total diagnostics 203 203
real-world corpus font-substitution diagnostics 0 0
HW1 / HW2 render pages 3 / 3 3 / 3, 0 errors, 0 overfull
verbatim fixtures matching pdfLaTeX 13 of 17 (#262) 14 of 17

The +4 over the control are #262's tests; no test changed state in either direction.

The three that remain

  • 15-verbatim-small — the size declaration; the compiler's Inline::Verbatim/Block::Verbatim carry no style, and declared_size forbids re-deriving sizes from the source (pin b38e1884). Compiler change plus a vendor re-pin.
  • 28-lstinline — the compiler typesets \lstset's argument as prose (11 stray glyphs). Compiler change plus a vendor re-pin.
  • 32-verbatim-microtype — protrusion on the surrounding roman text; the verbatim lines are already excluded.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…hat list

Fixture `10-verbatim-itemize` matches pdfLaTeX exactly; 13 of 17 verbatim
fixtures become **14 of 17**, worst 0.006 bp.

## What pdfTeX does, read off `\showoutput`

`\@verbatim` is `\trivlist \item\relax … \leftskip\@totalleftmargin`, so a
`verbatim` inside an `enumerate` item is a trivlist *inside that list*. The
fixture's page, dumped with `\showboxbreadth=200 \showboxdepth=10
\showoutput`, gives this between the item's line and the first verbatim line:

```
\glue 12.0 plus 4.0 minus 5.0
\glue -12.0 plus -4.0 minus -5.0
\glue 8.0 plus 2.0 minus 4.0
\glue 4.0 plus 2.0 minus 1.0
\glue(\parskip) 0.0
\glue(\parskip) 0.0
\glue(\baselineskip) 5.88889
\hbox(6.11111+0.0)x345.0 … \glue(\leftskip) 25.00003
```

Net **12 pt** above, and `\leftskip 25.00003` on every verbatim line. And
between the last verbatim line and the next `\item`:

```
\glue 8.0 plus 2.0 minus 4.0
\glue -8.0 plus -2.0 minus -4.0
\glue 8.0 plus 2.0 minus 4.0
\glue(\parskip) 4.0 plus 2.0 minus 1.0
\glue(\parskip) 0.0
```

net 12 pt again, but **built differently**: 8 pt from `\@endparenv` and 4 pt
of the *next item's* own `\parskip`.

Two rules follow, and the asymmetry between them is the whole point:

* `\@trivlist` sets `\@topsepadd \topsep`, then `\@topsep \@topsepadd`, then
  **`\advance\@topsep \parskip`**. Inside a list `\parskip` is `\parsep`
  (`\list` sets `\parskip\parsep`), which article's `\@listi` puts at 4 pt at
  10 pt — hence 8 + 4 = 12 above.
* `\@endparenv` adds `\@topsepadd`, which was fixed at `\topsep` **before**
  that `\advance` — so the closing skip carries no `\parskip`: 8, not 12.

The pipeline had `env_skip` = `\topsep` (+ `\partopsep`) on both sides, with
no `\parskip` term, and lowered verbatim to a *top-level* flush-left
paragraph. Measured before: the verbatim lines sat at the page margin
(133.768 against pdfTeX's 158.675) and 4 pt too high, with everything after
them carrying that 4 pt.

## The change

* `EnvOpen` gains `outer_parskip`, the `\parskip` in force where `\begin` was
  read: zero at the outer level, the enclosing list's `\parsep` inside one,
  read with the existing `list_stack_at` + `list_seps_with` from the source.
* `env_skip` takes it and adds it to the natural amount; `env_after` passes
  zero, which is what `\@endparenv` does.
* A verbatim-family block opening inside a list gets a `ListGeom` with the
  enclosing margins, no label and no `\parsep`, so `paragraph_block`'s
  existing `\@totalleftmargin` hang applies to it. The environment sets
  `\parskip\z@`, which is why `parsep` is zero here and not the list's.

## Scoped to the verbatim family on purpose

`verbatim_env_after_begin` restricts this to `verbatim`, `verbatim*` and
`lstlisting`. `center`/`quote` inside a list have the same shape of bug and
are **worse**, but differently, and nothing in this lane pins them: measured
on a scratch `center` inside an `enumerate` item, pdfTeX centres it within
the *indented* measure at x 276.663 and sets it 24.0 pt below the item's
baseline, while this pipeline sets it flush left at 158.675, 16.0 pt down —
8 pt short, not 4, so the `\parskip` term alone would not fix it and would
move it without a fixture to catch the result. Left exactly as it was, and
recorded rather than guessed at.

## Gates, control-compared

Control is a `git archive` checkout of `eea975c3` measured the same way.

| gate | control | this branch |
|---|---|---|
| `crates/render-pipeline` `cargo test --release --no-fail-fast` | 202 / 0 / 1 | 206 / 0 / 1 |
| amsmath oracle corpus | — | 59/59 within 0.5 bp |
| real-world corpus: status, pages, diagnostics per fixture/producer | — | identical, entry for entry |
| real-world corpus total / font-substitution diagnostics | 203 / 0 | 203 / 0 |
| HW1 / HW2 render pages, errors, overfull | — | 3 / 3, 0, 0 |
| verbatim fixtures matching pdfLaTeX | 13 of 17 | **14 of 17** |

The three left are `15-verbatim-small` and `28-lstinline` (both a compiler
change plus a vendor re-pin, which this crate cannot do) and
`32-verbatim-microtype` (protrusion on the surrounding roman text).

Implementation-Agent: engine-engineer (linux-primary, NixOS PC)
Commit-Executor: engine-engineer via git (Cursor usage limit fallback)
Co-authored-by: GoKubar <[email protected]>
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
The listings engine branched from PR #262 and so did not carry #268
(`\@verbatim`'s `\trivlist` inside a list) or #271 (microtype's verbatim
patch, and `\frenchspacing` inside `\verb`). Merging them makes the stack
linear -- #262 -> #268 -> #271 -> this -- and moves both of their fixtures
into `GATED` alongside the seventeen listings ones.

The only conflict is `tests/verbatim_oracle.rs`'s three lists, resolved by
taking every name both sides gate:

* `GATED` 32 = the 15 verbatim/`\verb` fixtures (`10-verbatim-itemize` and
  `32-verbatim-microtype` from this merge) plus the 17 listings ones.
* `NOT_YET` 2: `15-verbatim-small` keeps the `\showoutput` measurement from
  #271, `25-lst-java-roman` keeps the OT1-slot measurement from the listings
  lane.
* `LISTINGS_NOT_YET`, added in #262 so `main`'s freshly merged #248 fixtures
  were accounted for rather than failing the accounting test, is gone: every
  name in it is now either gated or in `NOT_YET`.

One fixture got better from the merge rather than from either side alone.
**`28-lstinline` goes from 0.062 bp to 0.005 bp**: #271 carries the fix for
the interword space that was being dropped after an inline `\verb` or
`\lstinline` (`after_control_word` stayed set even though `prev_end` had
already advanced past the closing delimiter), and that space is in this
fixture's first line.

Gates, control-compared against a `git archive` checkout of the listings
branch's own base `b7a1e530`, built and measured identically:

| gate | control | merged |
|---|---|---|
| `crates/render-pipeline` `cargo test --release --no-fail-fast` | 217 / 0 / 1 | 229 / 0 / 1 |
| amsmath oracle corpus | -- | 59/59 within 0.5 bp |
| real-world corpus, 22 fixtures x 2 producers | 739 diagnostics | 724 |
| real-world corpus status and page count | -- | identical, every entry |
| real-world corpus font-substitution diagnostics | 0 | 0 |
| HW1 / HW2 render | -- | 3 / 3 pages, 0 errors, 0 overfull |
| verbatim + listings fixtures matching pdfLaTeX | 30 of 34 | **32 of 34** |

The +12 are the listings lane's unit tests. The two corpus entries that
differ are the ones #271 already documents (`twelvept-plain` and
`listings-manual`, both losing `unsupported_block` limitations; the three
`overfull_hbox` in `listings-manual` are pdfLaTeX's own behaviour minus
`breaklines` inside `\lstinline`). The listings engine itself adds no corpus
diagnostic in either direction.

Implementation-Agent: engine-engineer (linux-primary, NixOS PC)
Commit-Executor: engine-engineer via git (Cursor usage limit fallback)
Co-authored-by: GoKubar <[email protected]>
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