Skip to content

compiler: listings setup commands set nothing; verbatim carries the size declaration - #261

Closed
GoKubar wants to merge 3 commits into
mainfrom
agent/linux-listings-setup/lstset-consumes-arguments
Closed

GoKubar wants to merge 3 commits into
mainfrom
agent/linux-listings-setup/lstset-consumes-arguments

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Two separate commits, both compiler-only. crates/render-pipeline/ (vendored mirror included) has no diff in either.


1 — \lstset and its siblings consume their arguments and set nothing

\lstset had no dispatch arm, so it reached P::unsupported. That recovery policy deliberately leaves a following brace group alone unless its contents look like a parameter; {basicstyle=\ttfamily} does not, so the group fell through to the paragraph and did two wrong things at once — it typeset the literal basicstyle=, and the \ttfamily inside it switched the body font for the rest of the group. pdflatex sets nothing for \lstset.

Measured with the compiler binary on the fixtures/verbatim/28-lstinline.tex source, counting non-space characters in the emitted page items:

control (git archive origin/main, 9a82257) this branch pdflatex TL2025
body glyphs 125 114 114 (+1 page number, which this compiler does not render)
diagnostics \lstset is not supported by this compiler version; unrestricted TeX math mode is not implemented none beyond the pre-existing listings package warning —
the three \lstinlines x = a + b; / int y; / s -- t unchanged unchanged

The 11-glyph delta is exactly basicstyle=. Oracle counted with tools/visual-oracle/pdftext.py on an uncompressed pdflatex run of the same source (115 glyphs = 114 body + the page number).

A second case, the same setup in the preamble with nested braces:

\lstset{basicstyle={\ttfamily\small},literate={x}{y}1,morekeywords={a,b,c}}
\lstdefinestyle{mine}{basicstyle={\ttfamily\small},numbers=left}
\lstdefinelanguage[R]{Mine}[ANSI]{C}{morekeywords={a,b}}

control raises 8 errors (\lstset is not supported in the document preamble, then \ttfamily/\small leaking out of the arguments, ...); this branch raises none.

What is consumed

Placed beside the \graphicspath arm and, like it, before the preamble catch-all, because every one of these is ordinary preamble material as well as body material.

command behaviour
\lstset{<keys>} consumed, silent
\lstdefinestyle / \lstdefinelanguage consumed, silent
\lstinputlisting[<keys>]{<file>} consumed, warns
\lstMakeShortInline[<keys>]{<char>} consumed, warns
\lstDeleteShortInline{<char>} consumed, silent (real no-op)
\lstnewenvironment left alone — see below

\lstdefinestyle and \lstdefinelanguage share one argument grammar, so one helper covers both: lstmisc.sty defines them as \lst@DefStyle/\lst@DefLang = \lst@DefDriver{...}...\lstset, and \lst@DefDriver (listings.sty 294-319) reads

[<dialect>]{<name>}([<base dialect>]{<base>})?{<key=value list>}[<aspects>]

Each optional part is an \@ifnextchar[ lookahead in the package and is a lookahead here too.

Why \lstnewenvironment is left

It defines an environment whose body listings reads under verbatim catcodes. Consuming the definition would leave the environment it names unknown to the lexer, so the listing body would be tokenized as ordinary LaTeX — macros expanded, % starting a comment, braces grouping — with no diagnostic at all. That is a worse and quieter failure than the one it replaces. It needs the lexer to learn a new verbatim environment first, which is a separate change. It is now listed in vocabulary.rs as known-but-unimplemented, so it is at least classified as real LaTeX rather than as a typo.

The diagnostic decision

\lstset, \lstdefinestyle and \lstdefinelanguage are silent.

  1. It is what the sibling that landed in compiler: lex listings' \lstinline as a raw delimited argument #188 already does. lexer.rs on \lstinline[<keys>] says "The keys are not read here: they set no text, and the renderer scans them from the source", and its test asserts \lstinline[language=C]!int z! produces no diagnostics. listings.sty defines \lstinline as \lstset{flexiblecolumns,#1} — the same key list in a different place — so warning about one and not the other would be the inconsistency.
  2. It is what \graphicspath does, for the same reason (graphics.rs: "consumed without a diagnostic; its search list is re-read from the source by a consumer that loads files"). The render pipeline re-reads \lstset/\lstdefinestyle from the source bytes, so nothing is dropped.

The existing \begin{lstlisting}[<opts>] warning — "lstlisting options are not implemented; typeset as plain verbatim" — stays, and is not inconsistent with this. It is attached to a body this compiler does typeset itself and typesets wrongly under those options: it reports a wrong rendering that has already happened at that spot, not the mere presence of a setting. \lstinputlisting and \lstMakeShortInline warn for exactly that reason — content really is missing from the page where they stand.

Information kept

No parse-tree record is added for the argument spans, following \graphicspath: the commands occupy their source span and emit nothing, and the consumer that needs the keys re-reads them from the source. The spans themselves are untouched.

Brace / nesting cases covered

required_group counts brace depth rather than scanning to the first }, so these are each one argument (all pinned by tests):

  • basicstyle={\ttfamily\small} — a group inside a value
  • literate={x}{y}1 — adjacent groups in one value
  • morekeywords={a,b,c} — a comma inside braces
  • \lstdefinelanguage[R]{Mine}[ANSI]{C}{...} — the base-dialect/base-language form
  • \lstdefinelanguage{Mine}{...}[keywords,comments]Body. — the trailing aspect list followed immediately by prose

The last one is why the optional brackets go through bracket_argument rather than optional_bracket_argument: [keywords,comments]Body. is a single lexer word, and only bracket_argument splits it at the ] instead of swallowing Body. with it.

\lstinline lexing is untouched — src/lexer.rs has no diff, and the \lstinline tests from #188 still pass unchanged.

Generated artefacts

crates/compiler/supported/supported-latex.json, the generated section of docs/user/compiler.md and the Mac app's byte-identical bundled copy are regenerated outputs of the inventory (crates/compiler/scripts/render_supported_latex.sh, apps/mac/scripts/sync-supported-latex.sh). tests/supported_latex.rs requires the first two and the CI sync-supported-latex.sh --check step requires the third; the Mac file is a generated byte-copy, not hand-written product code. supported/coverage.md is unchanged — none of these names is in the canonical denominator.


2 — verbatim carries the size declaration in force

Inline::Verbatim had only { text, span, space_before } and Block::Verbatim only { lines, span }, so the declaration in force where a \verb or a \begin{verbatim} was read never left the parser. A consumer that reads TextStyle::size off the compiler's inlines — rather than re-scanning the source for size declarations, which the render pipeline deliberately stopped doing (pin b38e1884) — had no way to know that {\small \verb|x|} is CMTT9, not CMTT10.

Both variants now carry style: TextStyle, not a narrower size: Option<FontSizeLevel>: every other inline that has a style at all (Text, Logo, Rule, Kern, Tabular) carries the whole TextStyle through one group/environment stack, and a size-only channel would be a second mechanism for the same scoping rule. The scoping rule is not new either — self.style at the construction site, restored by style_stack at a closing brace and by env_styles at an \end, exactly what bold and italic already do, \normalsize included.

\begin{small} needed one more thing. latex.ltx's \begin opens a group and runs the macro its argument names; \end runs \end<name>, undefined for a font declaration and so \relax, then closes the group — so \begin{small} is \small, scoped like {\small ...}. This compiler had no such rule and reported environment 'small' is not implemented instead. One branch in P::environment now applies apply_style for any style_declaration name, after env_styles has recorded the style to restore, so the two spellings agree and \begin{bfseries} works for the same reason. It deliberately adds no environment-inventory entry: the name is not an environment of its own but a declaration already in the command inventory reached through the kernel's generic rule, so tests/supported_latex.rs's arm-to-inventory gate stays exact.

layout.rs reads the size off both, with the same one-line map_or Inline::Text and Inline::Tabular already use — a size on the wire that the compiler's own layout ignored would be a new inconsistency. For a Block::Verbatim the declaration sets the body's baseline-to-baseline distance too. The vertical gap before the block (VERBATIM_TOPSEP_PT) still uses the document body size; scaling \topsep with the declaration is a separate change.

Evidence — fixtures/verbatim/15-verbatim-small.tex's source

pdflatex TL2025 (tools/visual-oracle/pdftext.py on an uncompressed run) sets the two inline \verbs at 8.9664 and 7.9701 bp and the environment body at 8.9664, against a 9.9626 bp body — 0.9 and 0.8 of the body size.

item control this branch ratio to body pdflatex ratio
{\small \verb|small inline|} 12 pt (body) 10.95 pt 0.9125 0.9000
{\footnotesize\verb|fn|} 12 pt (body) 10 pt 0.8333 0.8000
\begin{small} verbatim body 12 pt (body) 10.95 pt 0.9125 0.9000

control also raised environment 'small' is not implemented; this branch raises nothing.

The ratios differ from pdflatex's because this Core-14 layout's body size is the fixed layout::BODY_SIZE_PT = 12 — an article with no size option is set at 12 pt here, not 10 — so size_declaration_pt reads the 12 pt class table. That body-size model is pre-existing and untouched: \verb now takes exactly the size an Inline::Text in the same place takes (normal 12 / {\small small} 10.95 / {\footnotesize fn} 10 / {\small \verb|sv|} 10.95). The declaration level on the wire — Small, FootnoteSize — is what a consumer with the real class size reads.

Parser-level tests pin all three fixture-15 cases plus \verb|plain|, {\small x}\verb|after| (declaration ends with the group), {\small \normalsize\verb|reset|}, and both spellings across verbatim, verbatim* and lstlisting.

Call sites updated

incremental.rs's shift_block/shift_inlines exhaustive patterns (a style carries no span) and the two layout.rs arms. No crate outside crates/compiler matches or builds these variants — crates/render-pipeline builds against vendor/compiler, untouched.


Gates

cargo test --release in crates/compiler, against a git archive origin/main control of the same base:

Measured twice, each time against a git archive control of the branch's own base.

base control branch delta
9a82257 (where the work was written) 469 / 0 / 4 478 / 0 / 4 +9
b5dcc8c (main after the merge commit below) 481 / 0 / 4 490 / 0 / 4 +9

(passed / failed / ignored). The +9 are this branch's nine new tests — 6 for the listings commit, 3 for the verbatim one. No other delta in either run, and the ignored set is unchanged.

main moved while this was in flight, so the branch carries a third commit merging origin/main in. Its only conflict was docs/user/compiler.md, a generated artefact, resolved by re-running render_supported_latex.sh; the resolved file is main's content plus this PR's six rows. Every number above was re-measured after that merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…thing

`\lstset` had no dispatch arm, so it reached `P::unsupported`, whose recovery
policy deliberately leaves a brace group alone when its contents do not look
like a parameter. `{basicstyle=\ttfamily}` does not, so the group fell through
to the paragraph and did two wrong things at once: it typeset the literal
`basicstyle=`, and the `\ttfamily` inside it switched the body font for the
rest of the group. pdflatex of course sets nothing for `\lstset`.

Measured on fixtures/verbatim/28-lstinline.tex's source, this compiler's own
page items (non-space characters):

| | control (origin/main 9a82257) | this branch | pdflatex TL2025 |
|---|---|---|---|
| body glyphs | 125 | 114 | 114 (+1 page number) |
| diagnostics | `\lstset is not supported by this compiler version` | none beyond the `listings` package warning | — |

The 11-glyph delta is exactly `basicstyle=`.

Consumed here, in the same shape as the `\graphicspath` arm above them — and
placed before the preamble catch-all, because every one of these is ordinary
preamble material:

  \lstset{<keys>}
  \lstdefinestyle / \lstdefinelanguage, which share one argument grammar:
      [<dialect>]{<name>}([<base dialect>]{<base>})?{<keys>}[<aspects>]
    lstmisc.sty defines both as `\lst@DefDriver ... \lstset` (`\lst@DefStyle`,
    `\lst@DefLang`) and listings.sty 294-319 reads exactly that; the optional
    parts are `\@ifnextchar[` lookaheads in the package and lookaheads here.
  \lstinputlisting[<keys>]{<file>} — consumed and reported: there is no
    listing renderer, but the file name is a parameter and must not become
    prose.
  \lstMakeShortInline[<keys>]{<char>} — consumed and reported: the catcode
    shorthand is not modelled (this compiler tokenizes once), so text between
    the shorthand characters stays ordinary prose.
  \lstDeleteShortInline{<char>} — a real no-op: it restores the state this
    compiler is already in.

`\lstnewenvironment` is deliberately left out and is now listed in
`vocabulary.rs` as known-but-unimplemented instead of being misreported as a
typo. Consuming its definition would leave the environment it names unknown
to the lexer, so the listing body would be tokenized as ordinary LaTeX —
macros expanded, `%` starting a comment, braces grouping — with no diagnostic
at all. That needs the lexer to learn a new verbatim environment first.

Diagnostics: `\lstset`, `\lstdefinestyle` and `\lstdefinelanguage` are silent.
That is what the sibling that landed in #188 already does — `lexer.rs` on
`\lstinline[<keys>]` says "The keys are not read here: they set no text, and
the renderer scans them from the source", and listings.sty defines
`\lstinline` as `\lstset{flexiblecolumns,#1}`, so the two are the same key
list in different places. It is also what `\graphicspath` does, for the same
reason: the value is re-read from the source by the consumer that needs it.
The existing `\begin{lstlisting}[<opts>]` warning stays and is not
inconsistent with this: it is attached to a body this compiler does typeset
itself, and typesets wrongly under those options. It reports a wrong
rendering that has already happened, not the mere presence of a setting.
`\lstinputlisting` and `\lstMakeShortInline` warn for that same reason —
content really is missing from the page where they stand.

No parse-tree record is added for the argument spans. `\graphicspath` is the
precedent (`graphics.rs`: "consumed without a diagnostic; its search list is
re-read from the source by a consumer that loads files"), and the render
pipeline already re-reads `\lstset`/`\lstdefinestyle` from the source bytes,
so the commands only need to occupy their span and emit nothing.

Brace nesting is `required_group`'s depth counter, not a scan to the first
`}`, so `basicstyle={\ttfamily\small}`, `literate={x}{y}1` and
`morekeywords={a,b,c}` are one argument each. The optional brackets go
through `bracket_argument`, which splits `[a]text` (one lexer word) instead of
swallowing the text after the `]`.

`\lstinline` lexing is untouched: `src/lexer.rs` has no diff.

cargo test --release in crates/compiler, against a `git archive origin/main`
control of the same base: 469 passed / 0 failed / 4 ignored (control) ->
475 passed / 0 failed / 4 ignored (branch). The +6 are the six new tests here.

`crates/compiler/supported/`, `docs/user/compiler.md` and the Mac app's
bundled byte-copy are regenerated artefacts of the inventory
(`scripts/render_supported_latex.sh`, `apps/mac/scripts/sync-supported-latex.sh`),
required by `tests/supported_latex.rs` and the CI sync gate.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
`Inline::Verbatim` had only `{ text, span, space_before }` and
`Block::Verbatim` only `{ lines, span }`, so the declaration in force where
a `\verb` or a `\begin{verbatim}` was read never left the parser. A consumer
that reads `TextStyle::size` off the compiler's inlines — rather than
re-scanning the source for size declarations, which the render pipeline
deliberately stopped doing (pin b38e188) — therefore had no way to know that
`{\small \verb|x|}` is CMTT9, not CMTT10.

Both variants now carry `style: TextStyle`, not a narrower
`size: Option<FontSizeLevel>`. Every other inline that has a style at all
(`Text`, `Logo`, `Rule`, `Kern`, `Tabular`) carries the whole `TextStyle`
through one group/environment stack; a parallel size-only channel would be a
second mechanism for the same scoping rule. The scoping rule itself is not
new: `self.style` at the construction site, restored by `style_stack` at a
closing brace and by `env_styles` at an `\end` — exactly what bold and italic
already do, `\normalsize` included.

`\begin{small}` needed one more thing to work. latex.ltx's `\begin` opens a
group and runs the macro its argument names; `\end` runs `\end<name>`, which
is undefined for a font declaration and so `\relax`, then closes the group.
So `\begin{small}` IS `\small`, scoped like `{\small ...}`. This compiler had
no such rule, and reported `environment 'small' is not implemented; its body
is typeset as plain text` instead. One branch in `P::environment` applies
`apply_style` for any `style_declaration` name, after `env_styles` has
recorded the style to restore. The two spellings now agree, and a face
declaration (`\begin{bfseries}`) works for the same reason. It adds no
environment-inventory entry on purpose: the name is not an environment of its
own but a declaration already in the command inventory, reached through the
kernel's generic rule, so `tests/supported_latex.rs`'s arm-to-inventory gate
stays exact.

`layout.rs` now reads the size off both, the same one-line `map_or` that
`Inline::Text` and `Inline::Tabular` already use — a size on the wire that
the compiler's own layout ignored would be a new inconsistency. For a
`Block::Verbatim` the declaration also sets the body's baseline-to-baseline
distance, as in real LaTeX. The vertical gap *before* the block
(`VERBATIM_TOPSEP_PT`) still uses the document body size; scaling `\topsep`
with the declaration is a separate change.

Evidence, `fixtures/verbatim/15-verbatim-small.tex`'s source through the
compiler binary. pdflatex TL2025 (`tools/visual-oracle/pdftext.py` on an
uncompressed run) sets the two inline `\verb`s at 8.9664 and 7.9701 bp and
the environment body at 8.9664 against a 9.9626 bp body — 0.9 and 0.8 of the
body size:

| item | control | this branch | ratio to body | pdflatex ratio |
|---|---|---|---|---|
| `{\small \verb\|small inline\|}` | 12 pt (body) | 10.95 pt | 0.9125 | 0.9000 |
| `{\footnotesize\verb\|fn\|}` | 12 pt (body) | 10 pt | 0.8333 | 0.8000 |
| `\begin{small}` verbatim body | 12 pt (body) | 10.95 pt | 0.9125 | 0.9000 |

control also raised `environment 'small' is not implemented`; this branch
raises nothing. The ratios differ from pdflatex's because this Core-14
layout's body size is the fixed `layout::BODY_SIZE_PT` = 12 (an article with
no size option is set at 12 pt here, not 10), so `size_declaration_pt` reads
the 12 pt class table. That is the pre-existing body-size model, untouched
here: `\verb` now takes exactly the size an `Inline::Text` in the same place
takes (`normal` 12 / `{\small small}` 10.95 / `{\footnotesize fn}` 10 /
`{\small \verb|sv|}` 10.95). The declaration *level* on the wire —
`Small`, `FootnoteSize` — is what a consumer with the real class size reads.

Call sites updated: `incremental.rs`'s `shift_block`/`shift_inlines` exhaustive
patterns (a style carries no span) and the two `layout.rs` arms above. No
crate outside `crates/compiler` matches or builds these variants —
`crates/render-pipeline` builds against `vendor/compiler`, which is untouched.

cargo test --release in crates/compiler: 478 passed / 0 failed / 4 ignored,
against 469 / 0 / 4 on a `git archive origin/main` control of the same base.
The +9 are this branch's two commits (6 + 3); no other delta.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar GoKubar changed the title compiler: listings' setup commands consume their arguments and set nothing compiler: listings setup commands set nothing; verbatim carries the size declaration Sep 14, 2026
…setup/lstset-consumes-arguments

# Conflicts:
#	docs/user/compiler.md
GoKubar added a commit that referenced this pull request Sep 14, 2026
…guessed

Both remaining `NOT_YET` entries were checked against PR #261's compiler
rather than reasoned about: its `crates/compiler` was exported into
`vendor/compiler` **uncommitted**, measured, and the tree restored (`git
status` clean; the committed pin is untouched, and re-pinning is not this
lane's to do).

Four pipeline arms are needed for the new `style` field on
`Inline::Verbatim`/`Block::Verbatim` — two patterns, one initializer that
threads the block's style down to each line, and the lowered `Inline::Text`
taking `..*vstyle` instead of `CStyle::default()`. (A fifth, unrelated error
comes from `text_builtins::text_kern` having gained an `amsmath` argument on
main since the pin; a re-pin carries that too.)

With that in place:

* **28-lstinline matches**: 115 glyphs, worst 0.005 bp. The 11 stray
  `basicstyle=` characters are gone.
* **15-verbatim-small is left exactly 1.0 pt low, and nothing else.** Its
  horizontal geometry becomes exact — the body sets in CMTT9 and the line's
  last glyph lands at 194.964 against pdfTeX's 194.964. `\showoutput` names
  the residue: pdfTeX's skip above the block is `\glue 10.0 plus 4.0 minus
  5.0` (`\topsep` 8+2−4, `\partopsep` 2+1−1, `\parskip` 0+1 — which this
  pipeline already computes), and its `\glue(\baselineskip) 3.55557` is
  `\small`'s **11 pt** baselineskip minus the previous line's depth 1.94444
  and this line's height 5.49998. The pipeline sets the block at the body's
  12 pt. That one difference is the whole remaining pound, and it is the
  block's baselineskip following its size declaration — the same field the
  re-pin delivers.

Recorded in `NOT_YET` so the lane that does the re-pin starts from the
numbers instead of rediscovering them.

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