Skip to content

visual-oracle: group candidate words with the reference's own rule (fixes the #331 "regression") - #415

Merged
GoKubar merged 1 commit into
mainfrom
lane/nixos-gfxsec/rank-word-grouping
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
lane/nixos-gfxsec/rank-word-grouping

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What

The two halves of this tool disagreed about what a word is.

  • pdftext.py builds reference words from glyphs: break on a space, a new baseline, a new text object, or a gap wider than 0.16 em — and explicitly not on a font change.
  • rank.py built candidate words from glyph_run items: split only on space clusters within a run, never join across runs.

But a glyph_run is a typesetting artefact, not a word — the pipeline starts a new run at every face change. So one siunitx S cell arrived as three candidate words (1, ., 234) against the reference's one (1.234), because pdfTeX sets that cell as three Tf-switched runs inside one text object and the reference's rule joins them. difflib then aligned the two sequences against each other and reported the disagreement as geometry.

That is what made #331 (siunitx S/s columns) read as a regression it was not: lab-report page 2 went 78 → 118 candidate words and 70 → 50 aligned, with the ink unchanged and correctly placed.

The fix is to feed the candidate's glyphs through pdftext.words_from_glyphs. There is now one definition of a word in this tool, in one function, used by both sides — the disagreement cannot recur.

words_from_glyphs gains glyph_index; a word's glyphs are always contiguous in its input, so rank.py carries math and the source span across the grouping without the grouper knowing about them. The reference path is otherwise untouched.

The two siunitx fixtures land exactly on the reference

candidate words aligned
lab-report p2 118 → 70 (ref 71) 50 → 70
siunitx-tables p1 388 → 353 (ref 353) 322 → 345
siunitx-tables p2 297 → 275 (ref 275) 257 → 272

lab-report p2's worst delta drops from 91.75 bp to 0.01 bp.

All 22 fixtures, both directions

One producer binary (31b84428); the harness is the only variable. Sorted by change in aligned words.

fixture aligned dx % dy % both %
inline-math 793 → 1001 (+208) 64.56 → 69.03 +4.47 99.24 → 99.40 +0.16 64.56 → 69.03 +4.47
ps-calculus 615 → 744 (+129) 66.02 → 67.34 +1.32 12.03 → 10.89 −1.15 11.87 → 10.89 −0.98
lecture-notes 419 → 539 (+120) 80.91 → 77.74 −3.17 10.02 → 9.65 −0.38 9.79 → 9.28 −0.51
math-sheet 223 → 329 (+106) 51.12 → 46.20 −4.92 25.56 → 26.14 +0.58 10.76 → 10.03 −0.73
hw2 522 → 602 (+80) 88.89 → 86.05 −2.84 99.04 → 100.00 +0.96 88.89 → 86.05 −2.84
lab-report 541 → 609 (+68) 81.70 → 84.24 +2.54 94.64 → 96.06 +1.42 81.33 → 83.91 +2.58
enumitem-worksheet 279 → 332 (+53) 51.25 → 47.29 −3.97 5.38 → 4.52 −0.86 5.38 → 4.52 −0.86
twelvept-plain 623 → 666 (+43) 84.59 → 83.18 −1.41 76.89 → 76.58 −0.31 73.84 → 72.37 −1.46
hw1 563 → 605 (+42) 95.74 → 95.87 +0.13 99.82 → 99.83 +0.01 95.74 → 95.87 +0.13
siunitx-tables 579 → 617 (+38) 97.58 → 99.84 +2.26 100.00 → 100.00 97.58 → 99.84 +2.26
conf-paper 1337 → 1346 (+9) 95.44 → 95.62 +0.18 99.85 → 99.85 95.44 → 95.62 +0.18
hyperref-toc 1038 → 1043 (+5) 99.42 → 98.95 −0.48 69.56 → 69.70 +0.15 69.08 → 68.74 −0.33
article-twocolumn 628 → 631 (+3) 88.85 → 89.22 +0.37 32.64 → 32.65 29.62 → 29.64 +0.02
input-bibliography 500 → 503 (+3) 93.20 → 93.44 +0.24 99.60 → 99.80 +0.20 93.20 → 93.44 +0.24
listings-manual 704 → 705 (+1) 49.29 → 49.36 +0.07 3.84 → 3.83 −0.01 2.13 → 2.13
natbib-review 865 → 866 (+1) 96.65 → 96.77 +0.12 100.00 → 100.00 96.65 → 96.77 +0.12
cv 220 → 220 (0) 87.73 → 87.73 5.45 → 5.45 1.82 → 1.82
letter 218 → 218 (0) 53.21 → 53.21 0.00 → 0.00 0.00 → 0.00
lmodern-report 1311 → 1311 (0) 99.24 → 99.62 +0.38 100.00 → 100.00 99.24 → 99.62 +0.38
thesis-chapter 1356 → 1356 (0) 92.33 → 93.36 +1.03 99.85 → 99.93 +0.07 92.33 → 93.36 +1.03
unicode-accents 159 → 158 (−1) 82.39 → 82.28 −0.11 100.00 → 100.00 82.39 → 82.28 −0.11
plain-article 642 → 639 (−3) 90.65 → 91.24 +0.58 99.69 → 99.69 90.65 → 91.24 +0.58

Corpus totals:

before after
aligned words 14135 15040 (+905, +6.4%)
dx 85.89% 85.33%
dy 76.07% 75.08%
both 70.03% 69.02%
page counts 22/22 22/22

Read the totals carefully

The percentages fall while the measurement gets better, and both facts are real. 905 more words now pair up, and they are disproportionately the hard ones — math and table material that previously could not align at all and so sat outside the denominator. Coverage rises; the average over a harder population falls. Sixteen fixtures gain aligned words, four are unchanged, two lose a handful.

Anything quoted from this tool before today was measured against a smaller, easier sample than it appeared to be. The parity numbers in #395, #399, #404 and #409 are all deltas measured with one harness on both sides, so their direction and size stand; their absolute levels shift once this lands.

plain-article is the clean illustration: candidate word counts now match the reference exactly on all three pages (220/227/206), the 6 spurious words are gone, and dx rises 0.58 pp — but three pairs are lost to a different difflib path, so aligned reads −3.

It also stops hiding stray ink

unicode-accents loses one aligned word for a good reason. That fixture has a run, ellipsis\dots;, whose last five glyphs sit at x = −12321 bp — about 12.3k bp left of the page:

run text='ellipsis…;'  font_size=10.9091
    4 'p'    x=  301.5755 adv=6.0258
    5 's'    x=-12321.2532 adv=4.2982  gap -12628.8545

Grouping by run put all ten glyphs in one word whose x came from the first glyph, so the tool called it fine. Grouping geometrically splits at the backwards jump, the fragment keeps its own origin, and unicode-accents page 1 is now the corpus's top-ranked item at dx −12640.53.

The defect is in the producer's display list, is present on main independently of this change (byte-identical in both runs), and is not touched here — this commit only stops concealing it. Worth its own lane.

Files touched

  • tools/visual-oracle/rank.py (v2_words)
  • tools/visual-oracle/pdftext.py (glyph_index, additive)
  • tools/visual-oracle/test_rank.py (new WordGroupingTests, 5 tests)
  • tools/visual-oracle/README.md (step 4 and the honest-limits section now describe what the code does)

No crate change; no vendor/* change.

Gates

python3 -m unittest discover -s tools/visual-oracle -p 'test_*.py': 13 passed (was 8). A full rank.py --thumbs 0 run over lab-report, siunitx-tables and unicode-accents produces its report unchanged in shape.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

The two halves of this tool disagreed about what a word is. `pdftext.py`
built reference words from glyphs — breaking on a space, a new baseline, a
new text object or a gap wider than 0.16 em, and explicitly *not* on a font
change. `rank.py` built candidate words from `glyph_run` items, splitting
only on space clusters *within* a run and never joining across runs. But a
`glyph_run` is a typesetting artefact, not a word: the pipeline starts a new
run at every face change.

So one siunitx `S` cell arrived as three candidate words (`1`, `.`, `234`)
against the reference's one (`1.234`) — because pdfTeX sets that cell as
three `Tf`-switched runs inside one text object, and the reference's rule
joins them. `difflib` then aligned the two sequences against each other and
reported the disagreement as geometry.

That is what made PR #331 (siunitx `S`/`s` columns) read as a regression it
was not: `lab-report` page 2 went from 78 to 118 candidate words and 70 to
50 aligned, with the ink unchanged and correctly placed. Feeding the
candidate's glyphs through `pdftext.words_from_glyphs` removes the
disagreement by construction — there is now one definition of a word in this
tool, in one function, used by both sides.

`words_from_glyphs` gains `glyph_index`; a word's glyphs are always
contiguous in its input, so `rank.py` carries `math` and the source span
across the grouping without the grouper having to know about them. The
reference path is otherwise untouched.

Measured on all 22 real-world fixtures with one producer binary
(`31b84428`), harness the only variable:

  aligned words   14135 -> 15040   (+905, +6.4%)
  dx              85.89% -> 85.33%
  dy              76.07% -> 75.08%
  both            70.03% -> 69.02%
  page counts     22/22 unchanged

The percentages fall while the measurement gets better, and both facts are
real. 905 more words now pair up, and they are disproportionately the hard
ones — math and table material that previously could not align at all and
so sat outside the denominator. Coverage rises, the average over a harder
population falls. Sixteen fixtures gain aligned words, four are unchanged,
two lose a handful. The two siunitx fixtures, which triggered this, land
exactly on the reference:

  lab-report p2      cand 118 -> 70  (ref 71), aligned 50 -> 70
  siunitx-tables p1  cand 388 -> 353 (ref 353), aligned 322 -> 345
  siunitx-tables p2  cand 297 -> 275 (ref 275), aligned 257 -> 272

`lab-report` p2's worst delta drops from 91.75 bp to 0.01 bp.

It also stops hiding stray ink, which is why `unicode-accents` loses one
aligned word. That fixture has a run, `ellipsis\dots;`, whose last five
glyphs sit at **x = -12321 bp** — about 12.3k bp left of the page. Grouping
by run put all ten glyphs in one word whose `x` came from the first glyph,
so the tool reported it as fine. Grouping geometrically splits at the
backwards jump and the fragment keeps its own origin, and
`unicode-accents` page 1 is now the corpus's top-ranked item at
dx -12640.53. The defect is in the producer's display list, is present on
`main` independently of this change (same bytes in both runs), and is not
touched here — this commit only stops concealing it.

`python3 -m unittest discover -s tools/visual-oracle -p 'test_*.py'`:
13 passed (was 8). A full `rank.py` run over the three affected fixtures
produces its report unchanged in shape.

Implementation-Agent: Claude Opus 5 (lane nixos-graphics-sectioning, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar merged commit 7951e46 into main Sep 14, 2026
40 of 63 checks passed
@GoKubar
GoKubar deleted the lane/nixos-gfxsec/rank-word-grouping branch September 14, 2026 17:53
GoKubar added a commit that referenced this pull request Sep 14, 2026
…own units, not the whole word's (#421)

`typeset::word_items` cuts a hyphenatable word at its Liang points, shapes
each fragment on its own, and keeps the font kern the whole-word shaping had
across the point as an explicit kern after the discretionary, so an unbroken
word keeps exactly its width (TeX's reconstitution, §903-918). That kern is
whole minus parts:

    let upem = shaped.units_per_em as f64;          // the WHOLE word's
    let pt = |units: i64| size * units as f64 / upem;
    let width = |t: &str| shaper.shape(&face, t).width_units;
    ...
    let kern = pt(width(whole) - width(head) - width(tail));

but `width_units` is only meaningful next to the `units_per_em` of the
shaping that produced it, and `shape` picks the shaping per string:
`shape_tfm` runs the TFM ligature/kern program and reports 2^20 units per em,
and it bails out to `shape_otf` — the face's own units per em, 1000 for Latin
Modern — the moment one character of the string has no T1 slot. Two fragments
of the same word can therefore come back in units that differ by a factor of
1048.

`fixtures/real-world/unicode-accents` has `ellipsis\dots;`, which reaches the
shaper as `ellipsis…;`. U+2026 has no T1 slot, so the whole word and the tail
`sis…;` were measured by the font program and the head `lip` by the TFM
program, and all three were then divided by the whole word's 1000:

    HYPH word="ellipsis…;" upem=1000 size=10.95
      full="lipsis…;"/3126u/upem1000
      pre="lip"/1158757u/upem1048576
      post="sis…;"/2014u/upem1000
      kern=-12676.21275

`set_line` moves the line's x cursor by every kern, so the last five glyphs
of `ellipsis` and every word after them on that line were painted at
x = -12321.25 bp: 12300 points off the left edge of a 612 bp page, where a
reader of that document sees the `\dots` material and the rest of the line
simply vanish. It is byte-identical on every run.

The fix measures in points, the one scale the two shapings share, and keeps
the exact integer subtraction for the ordinary case where all three
measurements do agree on their units, so no same-units word moves by a
rounding bit. The pre-break hyphen's own advance had the same defect (a head
that is pure T1 under a word that is not), and is converted the same way.

This is not a `\dots` bug and not a `\dots` boundary. Any character with no
T1 slot does it, in any hyphenatable word, whenever one fragment is pure T1;
the size of the jump is the head fragment's TFM width, so it differs per word
(`typesetting\dots` gave -13954 bp, `transliteration\dots` -5682 bp).
Measured, before -> after, on the paragraph that caught it:

    \dots, \ldots, \textellipsis after a word   -12628.85 ->  0.08 bp
    \dag after a word                          -12628.85 ->  0.08
    Greek / Cyrillic / CJK after a word        -12628.85 ->  0.00
    typesetting\dots                           -13953.69 ->  0.07
    transliteration\dots                        -5681.61 ->  0.03
    \dots after a space, three literal periods,
    `é`, all-T1 words (controls)                    0.00 ->  0.00
    \cdots \vdots \ddots \dotsc \dotsb \dotsm
    in math, \dots in math (controls)               0.00 ->  0.00

Corpus effect, both sides measured with PR #415's `rank.py` (geometry only,
no raster stage; #415 is still open, so these are not comparable with numbers
taken from `main`'s grouping). On `unicode-accents` page 1 the six aligned
words after the discretionary go from dx -12635.94 / -12640.53 bp to -7.01 /
-11.60, which removes the corpus's top-ranked item; the page's worst
remaining dx is the pre-existing -39.86 bp CJK line. Fixture accuracy
82.28% -> 82.39% dx (one more word aligns); corpus-wide dx 85.59, dy 75.08,
both 69.02 over 15040 aligned words, unchanged to two decimals either side —
six words out of fifteen thousand is not a percentage, it is a visible hole
in one page.

The residual -7.01 bp is a second, independent defect that this change does
not touch and does not claim to: `\dots` reaches the pipeline as the single
character U+2026 and is painted as one 7.31 bp glyph, where pdflatex expands
`\textellipsis` to `.\kern\fontdimen3\font` three times and sets 14.3 bp of
dots (`crates/tex-text-encoding/src/typeset.rs:908` already implements that
expansion; the adapter does not use it). Fixing that would also keep such
words on the TFM path, but it is a different cause and belongs in its own PR.

Gates: `cargo test --release --no-fail-fast` on `crates/render-pipeline`,
60 test binaries, 0 failed (one new, `hyphenated_fragment_units`, which fails
on today's main with `dots: glyph 5 of run "ellipsis…;" is painted at
x = -12321.25 bp, off a 612.00 bp page`); amsmath 59/59 within 0.5 bp,
tabular 106/106 (words 0.5 bp, rules 0.1 bp), HW1 and HW2 3 pages / 0 errors
/ 0 font-FAILURE diagnostics.

No vendor file is touched and no re-pin is required.

Implementation-Agent: Claude Opus 5 (lane nixos-offpage-glyphs, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 14, 2026
…play style (#427)

`\displaystyle` is a style switch, not a command with an argument: it changes
the style for the rest of the enclosing group (TeX §1171). The pinned compiler
models none of that. All four switches, and `\nonumber`, `\notag` and
`\middle` with them, share one arm:

    // crates/compiler/src/math.rs
    "displaystyle" | "textstyle" | "scriptstyle" | "scriptscriptstyle"
    | "nonumber" | "notag" | "middle" => space(0.0, span),

— a zero-width `Nucleus::Space` atom, which the pipeline then skips. So
`$\displaystyle\sum_{n=1}^{\infty}(a_n-\tfrac25)$` was laid out in *text*
style, with the limits beside the operator as scripts.

That is a vertical defect as much as a horizontal one, and it is the largest
single cause of the drift down `fixtures/real-world/ps-calculus`. A text-style
sum is about 8 pt shorter than a display-style one, and a short box never
trips TeX's interline rule (§679: interline glue is `\baselineskip -
\prevdepth - height`, or `\lineskip` when that falls below `\lineskiplimit`),
so the following baseline stayed a plain `\baselineskip` away — and so did
every later line on the page. Measured on the `enumerate` of ps-calculus's
Problem 1 against pdflatex (TeX Live 2025, oracle only):

    baseline-to-baseline           pdflatex   before    after
    item (a) -> item (b)            35.758    22.516   30.848
    item (b) line 1 -> line 2       22.297    13.549   22.297
    accumulated by the next para   (0)       -21.99    -4.910

The switch is read back from the source at the atom's span, exactly as
`class_override_of` already reads `\mathbin`/`\mathrel` back for a pin that
keeps `MathAtom::class_override` private, and for the same reason: the
information is in the document and not in the parse tree. math-layout needs
nothing — `layout_with_report` already takes the starting `Style`.

Only a switch that is the formula's *first* atom is honoured, which is the
case where it governs the whole formula and nothing else. That is every use in
the corpus (six: five in ps-calculus, one in math-sheet, all
`$\displaystyle\int…$`-shaped). A switch in the middle of a list, or inside a
grid cell or a sub-formula, still needs the compiler to emit an atom for it;
math-layout is ready for that too (`Nucleus::Styled`, laid out at
`vendor/math-layout/src/layout.rs:345`). No vendor file is touched here and no
re-pin is required.

Corpus effect, both sides through PR #415's `rank.py` (geometry only, no
raster stage; #415 is still open, so do not compare these with numbers taken
from `main`'s word grouping):

    fixture         dx %            dy %            both %
    ps-calculus     72.58 -> 76.03  10.89 -> 13.40  10.89 -> 12.37
    math-sheet      46.20 -> 46.20  26.14 -> 24.62  10.03 -> 10.03
    corpus          85.59 -> 85.74  75.08 -> 75.04  69.02 -> 68.97

ps-calculus's page medians go -20.83 / -63.35 / -97.97 bp to -3.5 / -37.05 /
-49.02. math-sheet's *steps* improve too — the step at `Integration by parts`
goes -1.98 -> +2.90 and the one after it -1.71 -> +0.46, and the drift below
that line goes -9.99 -> -8.03 — but a band of its lines sat just inside 0.5 bp
on top of a pre-existing -25.50 bp offset near the top of the page and now
sits just outside, which is what the -1.52 pp is. The corpus dy and both
columns move by -0.04 and -0.05 pp, i.e. they do not move: the remaining error
on these pages is in the display-style boxes themselves, which is the next
cause, not this one.

What is left on ps-calculus, measured and *not* fixed here — two further
mechanisms, each its own PR:

* `\lim`, `\max`, `\min`, `\sup`, `\inf`, `\det`, `\gcd`, `\Pr` never take
  display limits, `\displaystyle` or not, because `convert_math_classed` maps
  every compiler `Nucleus::Text` to an **Ord** atom
  (`typeset.rs`, `N::Text(text) => vec![sink.atom(text)]`) where math-layout
  has `Atom::text_op` (Op class, `Limits::Limits` by default) for exactly
  this. In `\[\lim_{n\to\infty}a_n\]` pdflatex puts `n→∞` 6.546 bp below the
  baseline and this puts it 1.636 below, as a subscript. `\sum` and `\prod`
  are unaffected — they are `Nucleus::Symbol` and already stack.
* A display-style operator's box runs about 2.8 bp deeper than pdfTeX's. With
  the limits themselves landing exactly right (the `\infty` 13.637 bp above
  the baseline and the `n=1` 12.954 below, both matching pdflatex to 0.001),
  the box beneath the lower limit is still too deep, so the next line
  overshoots: pdflatex 19.738 bp, this 22.555.

An attribution control, for whoever picks those up: running local pdflatex and
this renderer on ps-calculus with every `\displaystyle` deleted from the
source gives page medians +7.65 / +1.22 / +0.06 bp and 99.7% of page 3's words
within 0.5 bp — text-style math on this document is right, and what is left
above is display-style math.

Gates: `cargo test --release --no-fail-fast` on `crates/render-pipeline`, 60
test binaries, 0 failed (one new, `displaystyle_switch`, two of whose three
tests fail on today's main); amsmath 59/59 within 0.5 bp, tabular 106/106
(words 0.5 bp, rules 0.1 bp), HW1 and HW2 3 pages / 0 errors / 0 font-FAILURE
diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-offpage-glyphs, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
d-q222 added a commit that referenced this pull request Sep 14, 2026
Merged #419 (⌥⇧↓/⌥⇧↑ duplicate) plus #420/#421/#415. Conflicts in
AccessibilityCommands and CommandPalette kept this lane's
Move/Delete/Join/Sort/Trim (and the current ⌘D duplicate table entry)
alongside main's EditorKeyHandling.duplicateLinesEdit and
CompletingTextView.duplicateLines(below:). Two duplicate implementations
are still present.

Ran: git fetch origin main && git merge origin/main. Conflicts resolved;
tests not run on this merge-only checkpoint.

Next: delete this lane's duplicate plan, hook, ⌘D table/palette/menu
entry; Editor menu Duplicate Line / Duplicate Line Up call main's
duplicateLines(below:); port review tests; hosted one-copy test.

Open questions: whether main's unterminated-last-line caret (same column,
which is EOF when the caret was at EOF) satisfies the review test that
wanted the copy start.

Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
GoKubar added a commit that referenced this pull request Sep 14, 2026
…xed columns, numbers, caption, frame space (#453)

* render-pipeline: `\lstset` and the `lstlisting` keys — basicstyle, fixed columns, numbers, caption, frame space

`fixtures/real-world/listings-manual` was the worst document in the corpus by
vertical accuracy — dy 3.83%, dx 49.36% — because `\lstinline` aside, none of
the `listings` keys existed. Its `\lstset` was not even read: the compiler
reported `\lstset` and then, having taken its argument for preamble material,
reported `\ttfamily`, `\small`, `\bfseries`, `\itshape` and `\tiny` too, six
errors for one command that typesets nothing.

The keys are read here from the source bytes, the way `abstractenv`,
`tikzpicture` and a list's `\begin` keys already are. That is not a
preference: this crate builds against `vendor/compiler`, so a key model added
to the compiler would not reach it until the vendor pin moves. A separate
compiler PR makes `\lstset` a command the compiler accepts in its own right;
this one does not depend on it and does not re-pin anything.

Every number below came out of pdfTeX (TeX Live 2025, listings v1.10c) —
`\showoutput` on a probe with the fixture's own preamble, and the content
stream of the fixture's pinned reference — never from a key's name.

**`basicstyle`.** `\lst@Init` runs the declarations before the first line, so
the block is set at that size *and at that size's own `\baselineskip`*:
`\ttfamily\small` in an 11pt article is `\fontsize{10}{12}`. We were setting
it at the 10.95 pt body size with the 13.6 pt body leading — 1.594 bp per line
over 39 lines. `\lstinline` gets the same face (listings adds only
`flexiblecolumns` to it), which is why the reference's
`\lstinline|ftxc build --watch|` is `SFTT1000`, not `SFTT1095`.

**`columns=[c]fixed`,** the default. An output token of `n` characters is set
as `\hbox to n\lst@width` with `\hss` between the characters *and* at both
ends, so each of the `n + 1` fils gets `n(W - w)/(n + 1)`. pdfTeX writes
exactly that: the fixture's `def` gets `-78`/`-79` and its 20-character
`write_default_config` `-100`. Tokens are listings' own rule — a maximal run
of letters, digits and `_`; the underscore being a letter is what makes that
identifier one token. `ec-lmtt10` and `cmtt10` both have quad 1.05 with every
character 0.525, so `W - w` is exactly `0.1em` and the whole grid is one
number; a basicstyle that is not monospaced has no single character width and
gets none, and the limitation says so.

**`numbers`.** `\llap{\normalfont \lst@numberstyle{\thelstnumber}
\kern\lst@numbersep}` — `\normalfont` is why the reference's numbers are
roman under a typewriter basicstyle, and `\llap` right-aligns them: its `1`
starts at 58.385 bp and is 3.652 wide, so its right edge plus 10 pt is the
72 bp margin, and `10` starts 3.652 further left. `\llap` is a new
`Item::Lap`, laid out in `hlist` where widths are known. Two things it had to
get right: the pull-back is a kern and a kern at the head of a line is
discarded (TeX §879), so the item opens with the same empty `\hbox`
`\leavevmode` already uses; and `hlist` ends every list it builds with TeX's
paragraph end (`\penalty10000 \parfillskip \penalty-10000`), which belongs to
a paragraph and not to this `\hbox` — left in place it broke the line after
the number, putting every numbered line one line below its own number.

**`caption` and `frame`.** `\showoutput` gives the vertical list between the
paragraph before and the first code line as `\vspace\lst@aboveskip` (6pt),
`\abovecaptionskip` (3pt), the centred `\normalsize` caption,
`\belowcaptionskip` (3pt), `\ht(frame rule box) - \baselineskip`, `\lineskip`,
the interline glue and the rule box: 22.6 pt to the caption baseline and 15.8
from there to the first code baseline, the last of which the reference
measures as 15.75 bp. At the end the bottom rule is a line of height 0 and
depth `framesep + framerule`, so the last code baseline sits 7.0 pt above the
frame's bottom edge (measured: 6.978 bp) and the next paragraph's baseline
`0.3·baselineskip + \lst@belowskip + \baselineskip` below that.

The frame's *rules* are not drawn — this block model has no rule beside a line
— so only the space they occupy is set. The per-listing limitation says that,
and names `language`, `breaklines`, `showstringspaces`, a tab against
`tabsize`, and every key given that this module does not model
(`backgroundcolor`, `keywordstyle`, `commentstyle` in this fixture). It also
lists what *was* applied, so a reader can tell the two apart.

One thing this made visible that is not about listings: the compiler lowers an
`lstlisting` to a `flushleft` paragraph, and `flushleft` is a `\trivlist`, so
the block carried `\topsep + \partopsep` — 12 pt at an 11pt base — on both
sides. `\lst@Init` opens no list at all; the body is a plain paragraph under a
`\parshape` with `\parskip\z@`. Before that was undone the probe put the first
code baseline 11.95 bp low and everything after it 23.9 bp low.

Measured with `tools/visual-oracle/rank.py` at its current revision (#415) on
both sides, this build against b529e9d:

    fixture            aligned       dx        dy      both   pages
    listings-manual   705 -> 814   49.36 ->  76.04   3.83 -> 71.74   3/3
    corpus total    15073 -> 15182 85.74 ->  86.91  75.04 -> 78.17

`both` (within 0.5 bp on both axes) is 68.97% -> 71.16% corpus-wide, 2.13% ->
51.97% on the fixture: 10396 -> 10804 words. No other fixture moves by a
single word. On the fixture's page 1 every baseline from the caption down now
matches the reference exactly; what is left is page 2's page glue (pdfTeX
shrinks 1.9 pt there and we set none) and `breaklines`, whose per-character
discretionaries we do not insert, so an over-wide `\lstinline` breaks in a
different place.

Gates: `cargo test --release --no-fail-fast` on `crates/render-pipeline`, 62
test binaries, 0 failed (one new, `listings_keys`, six of whose seven tests
fail on today's main — the seventh asserts an absence; the messages main gives
are quoted in the file header); amsmath 59/59 within 0.5 bp, tabular 106/106
(words 0.5 bp, rules 0.1 bp); HW1 and HW2 3 pages / 0 errors; page counts
22/22 across the corpus; zero font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-listings, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)

* render-pipeline tests: the listings suite is re-checked against main at 9d50d31

Implementation-Agent: Claude Opus 5 (lane nixos-listings, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)

* render-pipeline: a body `\lstset` typesets nothing, and a listing with no `basicstyle` says its grid is not set

Two defects a three-variant probe against pdflatex found, neither of which
`fixtures/real-world/listings-manual` could show (its one `\lstset` is in the
preamble and every listing names a typewriter `basicstyle`).

**A body `\lstset` was typeset.** The compiler has no `\lstset`, so a call in
the body had its argument set as ordinary text. A probe with

    \lstset{basicstyle=\ttfamily\footnotesize,frame=single}

between two paragraphs put the line `basicstyle=,frame=single` on the page and
pushed every baseline after it 13.55 bp down: pdflatex sets the paragraph
after the listing at 187.370 bp and we set it at 200.920. `\lstset`
contributes no material at all, so that material is removed, and a paragraph
that was nothing but the key list goes with it. With that undone the probe's
nine baselines all match the reference exactly, across a plain listing, a
`\footnotesize` framed one set by that body `\lstset`, and a numbered one
without a frame.

**The limitation went quiet on the commonest case.** listings sets its fixed
grid whatever the face is; only a monospaced one has a single character width,
which is what lets this module express the fill as one number. The default
(empty) `basicstyle` is the body font, and the reference spreads even
`plain listing, no keys at all` across cells of `0.6em` of `cmr10.95`, opening
at 73.506 bp where we open at 72.000. The "no fixed columns" clause tested
`basicstyle.family.is_some_and(|f| f != Tt)`, which is false when there is no
`basicstyle` at all — so a listing with no keys, the commonest listing there
is, got a limitation that named nothing. It now names the face it has.

Gates unchanged: `cargo test --release --no-fail-fast` on
`crates/render-pipeline` 0 failed (`listings_keys` is 9 tests now, eight of
which fail on main at 9d50d31); amsmath 59/59, tabular 106/106; corpus dx
88.78% / dy 80.62% / 22 of 22 page counts, identical to the previous commit —
neither defect is reachable from the corpus, which is why they needed a probe.

Implementation-Agent: Claude Opus 5 (lane nixos-listings, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)

* render-pipeline: keep both new Item variants after merging main (Lap from listings, Underline from #329)

The merge conflict spanned a closing brace: HEAD's `Item::Lap` arm in
`hash_items` ended after the `=======` marker, so a naive union of the two
sides dropped one `}` and left the function unclosed. Both variants and both
match arms are kept; the discriminants (202 Lap, 12 Underline) do not clash.

cargo test --release --no-fail-fast on crates/render-pipeline: 353 passed, 0 failed.
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