Skip to content

render-pipeline: verbatim is typewriter, literal, and keeps its indentation - #398

Merged
GoKubar merged 1 commit into
mainfrom
lane/nixos-verbatim-face
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
lane/nixos-verbatim-face

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

\verb/\verb*, the verbatim/verbatim* environments, lstlisting and
\lstinline were set in the roman body face. The compiler already marked them
mono (Inline::Verbatim, Block::Verbatim); the pipeline re-derives NFSS by
scanning the source, and none of the three tables in style_intervals listed
them — the same bug class PR #378 fixed for \url.

pdflatex (TeX Live 2025) is an oracle only here; nothing in this diff runs TeX
in the product path. Only crates/render-pipeline/src/* is touched — no
crates/render-pipeline/vendor/*.

Two corrections to the brief, both measured

1. \langle / \rangle were already fixed before this branch started. Zero
math_limitation diagnostics at this HEAD; $\langle a,b\rangle$,
\Biggl\langle and \left\langle all paint real U+27E8/U+27E9. The evidence
the task quoted contains the deprecated U+2329 (bytes e2 8c a9), a
different character that PR #339 replaced. No change was needed and none was
made. The task's expectation that fixing this would help twelvept-plain could
not hold, because there was nothing left to fix.

2. \url only ever got the face half, so there was no literal path to route
into.
The brief said \url "correctly keeps x--y literal". It looks literal
but is not: our \url{...x--y} emitted 20 glyphs for 21 characters (gid 279
= en dash). tex_ligatures is called unconditionally (adapter.rs:4853). PR
#378 built the typewriter face and the literal-byte argument scan, but never
a ligature-suppressing path. So this PR builds that half rather than reusing it.

\url itself still ligates and is not fixed here: pdflatex gives
\url{x--y} = 25.69397 pt (4 characters + url.sty's two 0.5 pt hyphen kerns)
against our 3 characters. Out of scope, and compiler-side per #378's own note.

Three things were wrong, not one

The family alone fixes only the first.

  1. Face routing. literal_spans finds every verbatim construct and
    style_intervals gives it a Family(Tt) interval over the whole command,
    skipping its bytes rather than scanning them. The skip matters on its
    own: a % inside \verb|100%| used to start a comment and eat the styles of
    the rest of the line, and a lone { in a listing corrupted the group stack
    that decides where a declaration ends.

  2. Ligature and kern suppression. Verbatim runs under \@noligs; \texttt
    does not. So this cannot ride on the family — ectt does carry the --
    ligature and \ttfamily is right to use it. TextStyle::literal now marks
    the text and suppresses both the pipeline's source-level tex_ligatures pass
    and the font's own program (tfm::literal_run, Shaper::shape_literal, and
    ShapeOptions{ligatures,kerning,cmap_ligature_fallback} on the OpenType
    path).

  3. The \leavevmode box. A verbatim blank is \@vobeyspaces' control
    space: rigid (the typewriter families set \fontdimen3/\fontdimen4 to
    zero, so interword glue in that style is already rigid), never breakable, and
    preceded by \leavevmode. Without that empty box the glue opening an
    indented line is discardable (TeX §879) and every listing loses its
    indentation.
    This was worth 26 bp per indented line on listings-manual.

pdflatex box widths measured against

12 pt article, T1, ectt1200, every character 6.1735 pt,
\fontdimen2/3/4 = 6.1735/0/0:

measured oracle ours
\verb"ftxc --version" 86.4289 pt 86.4289
\ttfamily ftxc --version 80.2554 pt 80.2554 (ligature kept — correct)
`\verb x--y `
\ttfamily x--y 18.52048 pt = 3 chars 3 chars
verbatim body a b-c 30.86746 pt 30.8675

\showbox of \verb*"a b-c" gave the structure directly: a leading
\hbox(0.0+0.0)x0.0 (\leavevmode), a \kern 0.0 between b and -
(\@noligs), and the space as a character. At 11 pt, \verb|a b| shows
\penalty 10000 + \glue 5.65837 — rigid, unbreakable.

A four-line indented verbatim block now matches the oracle within 0.0044 bp
on every word
, baselines included.

Per-fixture before → after (all 22)

Aligned words within 0.5 bp, fixtures/real-world vs pinned pdflatex
references, via tools/visual-oracle/rank.py.

fixture dx dy both pages
article-twocolumn 88.9 → 88.9% 32.6 → 32.6% 29.6 → 29.6% 2/2
conf-paper 95.4 → 95.4% 85.5 → 85.5% 81.1 → 81.1% 4/4
cv 87.7 → 87.7% 5.5 → 5.5% 1.8 → 1.8% 1/1
enumitem-worksheet 49.5 → 49.5% 5.4 → 5.4% 5.4 → 5.4% 3/3
hw1 95.7 → 95.7% 99.8 → 99.8% 95.7 → 95.7% 3/3
hw2 88.9 → 88.9% 99.0 → 99.0% 88.9 → 88.9% 3/3
hyperref-toc 99.2 → 99.2% 69.5 → 69.5% 68.9 → 68.9% 4/4
inline-math 64.6 → 64.6% 99.2 → 99.2% 64.6 → 64.6% 2/2
input-bibliography 93.2 → 93.2% 99.6 → 99.6% 93.2 → 93.2% 2/2
lab-report 81.7 → 81.7% 94.6 → 94.6% 81.3 → 81.3% 3/3
lecture-notes 80.9 → 80.9% 10.0 → 10.0% 9.8 → 9.8% 2/2
letter 53.2 → 53.2% 0.0 → 0.0% 0.0 → 0.0% 1/1
listings-manual 42.7 → 48.4% 3.9 → 3.8% 2.2 → 2.1% 3/3
lmodern-report 95.0 → 95.0% 26.4 → 26.4% 26.4 → 26.4% 4/4
math-sheet 51.1 → 51.1% 25.6 → 25.6% 10.8 → 10.8% 2/2
natbib-review 96.6 → 96.6% 100.0 → 100.0% 96.6 → 96.6% 3/3
plain-article 83.4 → 83.4% 50.3 → 50.3% 41.2 → 41.2% 3/3
ps-calculus 66.0 → 66.0% 12.0 → 12.0% 11.9 → 11.9% 3/3
siunitx-tables 97.6 → 97.6% 100.0 → 100.0% 97.6 → 97.6% 2/2
thesis-chapter 91.9 → 91.9% 99.8 → 99.8% 91.9 → 91.9% 4/5
twelvept-plain 78.0 → 84.2% 68.3 → 82.4% 53.4 → 73.2% 4/3
unicode-accents 82.4 → 82.4% 100.0 → 100.0% 82.4 → 82.4% 1/1
TOTAL 84.5 → 85.0% 65.2 → 65.7% 58.7 → 59.5% 20/22

The other 20 fixtures are byte-identical to baseline. Nothing regressed. The
baseline reproduced the task's figures exactly (84.5 / 65.2 / 58.7, 20/22), so
the metric matches.

The next lane's starting points

1. listings-manual dy barely moved (3.9% → 3.8%) because
basicstyle=\ttfamily\small is not applied — and behind that,
\baselineskip does not follow a size declaration anywhere in the pipeline.

Indentation errors dropped from −25.97 bp to −3.4 bp, but line spacing is still
wrong: reference 11.956 bp (12 pt, i.e. \small at an 11 pt body), ours
13.550 bp (13.6 pt, the body's). This is not a listings bug: a plain
{\small\ttfamily ...} paragraph drifts +4.78 bp over two lines against
pdflatex. That general leading bug should be fixed before \lstset key parsing
(basicstyle, frame, numbers, caption) is worth attempting.

2. twelvept-plain stays at 4 pages for a third reason: list vertical
spacing, +26.58 bp cumulative across one itemize→enumerate sequence, of
which +16.2 bp lands at the boundary between the two.
Pages 1–2 are now
near-exact (median shift ~0; 234/236 words within 0.5 bp on page 2). Page 3 is
exact down to y≈392, then drifts: +3.5 bp at the first itemize \item,
~+0.53 bp per further item, +16.2 bp at the itemize→enumerate boundary,
+4.3 bp closing the list. That pushes the closing paragraph's last two lines
into the footnote, so the page builder moves them to page 4. Our page 3
otherwise ends exactly where the reference's does. Neither verbatim nor math
glyphs are involved, so the task's expectation that this PR would restore 3
pages does not hold.

Diagnostics

The \verb limitation is deleted (it claimed "the pipeline has no monospaced
face", now false). The block limitation now names what is actually missing — the
listings keys — instead of the same false claim.

Gates

  • cargo test --release --no-fail-fast on crates/render-pipeline: 258 tests
    / 54 suites, 0 failed
    (4 new tests).
  • amsmath 59/59 within 0.5 bp.
  • tabular 106/106 (words 0.5 bp, rules 0.1 bp).
  • HW1 3 pages / 0 errors, HW2 3 pages / 0 errors.
  • Zero font-FAILURE diagnostics in all 22 fixtures.

Worth flagging for anyone re-running these: the first suite run showed 25
failures purely because the font env was unset. The lm_available() guard turns
that into a loud failure rather than the silent skip the harness used to give.
Every number above is from runs with FLASHTEX_FONT_DIRS / FLASHTEX_TFM_DIRS
set.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…tation

`\verb`/`\verb*`, the `verbatim`/`verbatim*` environments, `lstlisting` and
`\lstinline` were set in the roman body face. The compiler already marked
them mono (`Inline::Verbatim`, `Block::Verbatim`), but the pipeline
re-derives NFSS by scanning the source and none of the three tables in
`style_intervals` listed them -- the same bug class PR #378 fixed for
`\url`.

Three things were wrong, not one, and the family alone fixes only the first.

1. **Face.** `literal_spans` finds every verbatim construct and
   `style_intervals` gives it a `Family(Tt)` interval over the whole
   command, skipping its bytes rather than scanning them. The skip matters
   on its own: a `%` inside `\verb|100%|` used to start a comment and eat
   the styles of the rest of the line, and a lone `{` in a listing
   corrupted the group stack that decides where a declaration ends.

2. **Ligatures and kerns.** Verbatim runs under `\@noligs`, `\texttt` does
   not, so this cannot ride on the family. `TextStyle::literal` now marks
   the text; it suppresses the pipeline's source-level `tex_ligatures` pass
   *and* the font's own program (`tfm::literal_run`, `Shaper::shape_literal`,
   `ShapeOptions` for the OpenType path). `ectt` does carry the `--`
   ligature, and `\ttfamily` is right to use it.

3. **Blanks.** A verbatim blank is `\@vobeyspaces`' control space: rigid
   (the typewriter families set `\fontdimen3`/`\fontdimen4` to zero, so
   interword glue in that style is already rigid), never breakable, and
   preceded by `\leavevmode` -- without that empty box the glue opening an
   indented line is discardable (TeX §879) and every listing lost its
   indentation.

Measured against pdflatex (TeX Live 2025, oracle only), 12pt article, T1,
`ectt1200`, every character 6.1735pt:

    \verb"ftxc --version"        86.4289 pt   ours 86.4289
    \ttfamily ftxc --version     80.2554 pt   ours 80.2554   (ligature kept)
    \verb|x--y|                  24.69397pt = 4 characters
    \ttfamily x--y               18.52048pt = 3 characters
    verbatim body "a b-c"        30.86746pt   ours 30.8675

A four-line indented `verbatim` block matches the oracle to 0.0044 bp on
every word, baselines included.

Real-world corpus (22 documents, aligned words within 0.5 bp):
dx 84.5% -> 85.0%, dy 65.2% -> 65.7%, both 58.7% -> 59.5%.
twelvept-plain dx 78.0 -> 84.2%, dy 68.3 -> 82.4%, both 53.4 -> 73.2%;
listings-manual dx 42.7 -> 48.4%. No fixture regressed.

The `\verb` limitation is gone and the block one now names what is actually
missing (the `listings` keys), instead of claiming there is no monospaced
face.

Gates: render-pipeline 258 tests / 54 suites green, amsmath 59/59, tabular
106/106, HW1 and HW2 3 pages 0 errors, zero font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-verbatim-face, 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
GoKubar merged commit 28332ec into main Sep 14, 2026
10 of 21 checks passed
d-q222 added a commit that referenced this pull request Sep 14, 2026
…s Item::LeaveVmode

adapter.rs and incremental.rs conflicts were two additive Item variants (and
their hash_items arms) at the same place; kept both.

Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@GoKubar
GoKubar deleted the lane/nixos-verbatim-face 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