Skip to content

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

Merged
GoKubar merged 6 commits into
mainfrom
lane/nixos-listings/lstset-keys
Sep 14, 2026
Merged

GoKubar merged 6 commits into
mainfrom
lane/nixos-listings/lstset-keys

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

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 branch against origin/main at 9d50d31 (both binaries built
here, both runs with the same harness and font environment):

fixture            aligned          dx               dy           pages
listings-manual   705 ->   814   49.36 -> 76.04   3.83 -> 71.74    3/3
corpus total    15120 -> 15229   87.63 -> 88.78  77.52 -> 80.62   22/22

both (within 0.5 bp on both axes) is 72.28% -> 74.44% corpus-wide and
2.13% -> 51.97% on the fixture: 10929 -> 11337 words. No other fixture moves
by a single word, and every page count is unchanged. 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.

A three-variant probe against pdflatex (a listing with no keys, one framed at
\footnotesize by a body \lstset, one numbered without a frame) found two
defects the corpus cannot reach; the last commit fixes both, and its message
has the numbers. All nine of the probe's baselines now match the reference.

Gates: cargo test --release --no-fail-fast on crates/render-pipeline, 0
failed (one new suite, listings_keys, eight of whose nine tests fail on
today's main — the ninth 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)

…xed 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)
GoKubar added a commit that referenced this pull request Sep 14, 2026
`\lstset` was unknown, so it fell through to `unsupported_preamble` — and then
its argument was read as preamble material, so every declaration inside it was
reported too. `fixtures/real-world/listings-manual` has one `\lstset`, and it
produced six errors on a perfectly valid document:

    \lstset is not supported in the document preamble
    \ttfamily is not supported in the document preamble
    \small is not supported in the document preamble
    \bfseries is not supported in the document preamble
    \itshape is not supported in the document preamble
    \tiny is not supported in the document preamble

out of `basicstyle=\ttfamily\small`, `keywordstyle=\color{codekw}\bfseries`,
`commentstyle=\color{codecomment}\itshape` and `numberstyle=\tiny`.

`\lstset` sets the package's defaults and typesets nothing itself — `\lst@Init`
reads the values when a listing is set — so it is handled the way
`\hypersetup` already is: the argument is read, the key *names* are checked
against listings' own documented keys (listings.sty / lstmisc.sty v1.10c,
TeX Live 2025), nothing is contributed, and it is accepted in the preamble,
where every real document puts it, and in the body, where listings also allows
it. A name that is not a listings key at all is reported once, because that is
far more likely a typo than a key this compiler silently honours.

The *values* are deliberately not interpreted. This compiler's own layout sets
an `lstlisting` as plain verbatim lines and applies none of them, and a
diagnostic claiming otherwise would not be earned. Reading them and applying
the geometric ones is `crates/render-pipeline`'s job (PR #453, which reads the
same keys from the source bytes and does not depend on this change: that crate
builds against `vendor/compiler`, so nothing here reaches it until the pin
moves — and no re-pin is needed for either PR).

The key-name splitter nests the way listings' own parser does: entries split
at top-level commas and truncate at the first top-level `=`, so
`caption={A caption, part 2}` and `basewidth={0.6em,0.45em}` are one key each,
and a backslash skips the character after it so a style value's `\{` never
opens a group.

`docs/user/compiler.md` and `crates/compiler/supported/supported-latex.json`
are regenerated (`crates/compiler/scripts/render_supported_latex.sh`): 280 ->
281 text-mode command entries.

Gates: `cargo test --release --no-fail-fast` on `crates/compiler`, 0 failed,
three new tests. Built from a `git archive` of `origin/main:crates` at
9d50d31 with it dropped in, `lstset_is_accepted_in_the_preamble_and_typesets_nothing`
fails on main with exactly the six messages above.

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

# Conflicts:
#	crates/render-pipeline/src/adapter.rs
9d50d31

Implementation-Agent: Claude Opus 5 (lane nixos-listings, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
…h 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)
GoKubar added a commit that referenced this pull request Sep 14, 2026
)

* compiler: `\lstset` is a listings command, not six preamble errors

`\lstset` was unknown, so it fell through to `unsupported_preamble` — and then
its argument was read as preamble material, so every declaration inside it was
reported too. `fixtures/real-world/listings-manual` has one `\lstset`, and it
produced six errors on a perfectly valid document:

    \lstset is not supported in the document preamble
    \ttfamily is not supported in the document preamble
    \small is not supported in the document preamble
    \bfseries is not supported in the document preamble
    \itshape is not supported in the document preamble
    \tiny is not supported in the document preamble

out of `basicstyle=\ttfamily\small`, `keywordstyle=\color{codekw}\bfseries`,
`commentstyle=\color{codecomment}\itshape` and `numberstyle=\tiny`.

`\lstset` sets the package's defaults and typesets nothing itself — `\lst@Init`
reads the values when a listing is set — so it is handled the way
`\hypersetup` already is: the argument is read, the key *names* are checked
against listings' own documented keys (listings.sty / lstmisc.sty v1.10c,
TeX Live 2025), nothing is contributed, and it is accepted in the preamble,
where every real document puts it, and in the body, where listings also allows
it. A name that is not a listings key at all is reported once, because that is
far more likely a typo than a key this compiler silently honours.

The *values* are deliberately not interpreted. This compiler's own layout sets
an `lstlisting` as plain verbatim lines and applies none of them, and a
diagnostic claiming otherwise would not be earned. Reading them and applying
the geometric ones is `crates/render-pipeline`'s job (PR #453, which reads the
same keys from the source bytes and does not depend on this change: that crate
builds against `vendor/compiler`, so nothing here reaches it until the pin
moves — and no re-pin is needed for either PR).

The key-name splitter nests the way listings' own parser does: entries split
at top-level commas and truncate at the first top-level `=`, so
`caption={A caption, part 2}` and `basewidth={0.6em,0.45em}` are one key each,
and a backslash skips the character after it so a style value's `\{` never
opens a group.

`docs/user/compiler.md` and `crates/compiler/supported/supported-latex.json`
are regenerated (`crates/compiler/scripts/render_supported_latex.sh`): 280 ->
281 text-mode command entries.

Gates: `cargo test --release --no-fail-fast` on `crates/compiler`, 0 failed,
three new tests. Built from a `git archive` of `origin/main:crates` at
9d50d31 with it dropped in, `lstset_is_accepted_in_the_preamble_and_typesets_nothing`
fails on main with exactly the six messages above.

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

* mac: sync the bundled completion inventory with the compiler's

`apps/mac/scripts/sync-supported-latex.sh`, which CI's `bundled inventory
matches the compiler` job checks: adding `\lstset` to the compiler's
inventory drifts the copy the Mac app bundles for completion.

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

* docs: regenerate the supported-LaTeX inventory after merging main (cleveref + lstset)
# Conflicts:
#	crates/render-pipeline/src/adapter.rs
#	crates/render-pipeline/src/incremental.rs
…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.
@GoKubar
GoKubar merged commit 64cb851 into main Sep 14, 2026
21 checks passed
@GoKubar
GoKubar deleted the lane/nixos-listings/lstset-keys 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