Skip to content

compiler: a verbatim tab is one space, not an 8-column stop - #235

Merged
GoKubar merged 1 commit into
mainfrom
verbatim-tab-is-one-space
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
verbatim-tab-is-one-space

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Settles the verbatim_display tab question that PR #188 flagged and deliberately left alone ("a real mismatch in this crate's own Core-14 layout"). Compiler-only; crates/render-pipeline/vendor/ untouched.

Verdict: the 8-column expansion was wrong, and the middle dot was right.

What pdflatex actually does

latex.ltx's \@vobeytabs makes TAB active and \lets it to \@xobeytab, which line 9421 \lets to \@xobeysp (= \nobreakspace = \leavevmode\nobreak\ ). verbatim* re-points both through \@setupverbvisibletab. A tab is therefore exactly whatever one space is — TeX has no tab stops, and nothing in the expansion looks at the current column.

Measured against pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025), oracle only, never in the product path.

\showbox of <TAB>one inside verbatim yields a single \glue 5.24995 (cmtt10's \fontdimen2; stretch and shrink both 0.0pt), byte-identical to the one-literal-space baseline — not the eight glues the old rule implied. The eight-literal-spaces baseline, by contrast, shows eight separate glues.

Glyph origins read back out of the generated PDF (tools/visual-oracle/pdftext.py), as offsets from the left text edge at 72.0 bp:

source line measured one-space rule old 8-column rule
<TAB>Q 5.23 bp 5.23 bp (1 cell) 41.84 bp (8)
ab<TAB>W 15.69 bp 15.69 bp (3) 41.84 bp (8)
abcdefg<TAB>E 41.84 bp 41.84 bp (8) 41.84 bp (8)
abcdefgh<TAB>R 47.07 bp 47.07 bp (9) 83.99 bp (16)
abc<TAB><TAB>T 26.15 bp 26.15 bp (5) 83.99 bp (16)
<TAB><TAB><TAB>Y 15.69 bp 15.69 bp (3) 125.99 bp (24)

verbatim* measures identically. Note the 7-column row: it is the one case where the two rules agree, which is why a single-case test could never have caught this — and the old test used exactly that kind of case.

Expectations that moved

verbatim_expands_tabs_to_the_next_stop (parser.rs) asserted

assert_eq!(lines[0].text, format!("{}a", " ".repeat(8)));

for the source \begin{verbatim}\n\ta\n\end{verbatim}. pdflatex puts that a 5.23 bp from the margin — one cmtt10 cell — so the correct expectation is " a". The old value encoded an editor convention rather than pdflatex's behaviour.

Replaced by verbatim_sets_a_tab_as_a_single_space_not_a_column_stop, which asserts [" a", "ab cd", "abcdefgh X", "abc X"] — column 0, column 2, column 8 and two consecutive tabs, i.e. the rows above that actually discriminate between the two rules (the old rule would give 8, 8, 16 and 16 cells).

Added verbatim_star_sets_a_tab_as_a_single_visible_space: the starred path had no tab coverage at all, and \@setupverbvisibletab makes a starred tab one visible space rather than eight.

No other committed expectation moved: no pinned/oracle/tabular-corpus fixture and no integration test contains a tab in a verbatim context, and every other U+00B7 in the repo belongs to math \cdot.

The middle dot is kept, and the doc comment now justifies it

On pdfTeX \verbvisiblespace is \asciispace = \char32, and cmtt10.pfb's encoding vector has dup 32 /visiblespace put — U+2423 OPEN BOX. The Core 14 Courier face this crate lays out on has no U+2423 at all (checked against the generated AFM table backing Core14::Courier), so a substitute is unavoidable.

U+00B7 is the honest choice because it is exactly width-neutral: Courier's width table has a single distinct value across all 322 entries, and periodcentered (U+00B7) and space (U+0020) both advance 600/1000 em — 6.0 pt at the 10 pt body size. The substitution moves no glyph. The stale doc comment (which implied treating a tab as a space would be "too lossy") is rewritten to record all of the above.

KNOWN_UNIMPLEMENTED_COMMANDS — deliberately left alone

PR #188's resume notes flagged verb/lstinline in vocabulary.rs's KNOWN_UNIMPLEMENTED_COMMANDS as stale. The label is indeed wrong — both are implemented, in the lexer — but removing them is not harmless, so this PR does not touch them.

Neither name is in parser::BUILT_INS (212 entries; verified), so implemented_commands() does not contain them and that list is their only route into the vocabulary. Probed directly:

is_known_command("verb")       = true
is_known_command("lstinline")  = true
suggest_command("vrb")         = Some("verb")
suggest_command("verbb")       = Some("verb")
suggest_command("verrb")       = Some("verb")
suggest_command("lstinlin")    = Some("lstinline")
suggest_command("lstinlien")   = Some("lstinline")

Deleting the entries would flip both is_known_command results to false and lose all five did-you-mean suggestions. Re-homing them into an implemented list would fix the label but change suggest_command's iteration order, and with it the tie-breaking for unrelated typos — a diagnostics behaviour change that does not belong in a verbatim-tab PR.

Tests

cargo test --release in crates/compiler, CARGO_BUILD_JOBS=8, against a control checkout of the same base (git archive origin/main at eea975c3):

passed failed ignored
control 469 0 4
this branch 470 0 4

The single delta is the one replaced test becoming two. No other test changed state.

Note: cargo fmt is not installed in this environment, so formatting was matched by hand rather than verified by the tool.

`verbatim_display` expanded a tab to the next multiple of 8 columns. That
encoded a text-editor convention, not pdflatex's behaviour, and PR #188
flagged it as a real mismatch in this crate's own Core-14 layout path.
TeX has no tab stops at all.

`latex.ltx`'s `\@vobeytabs` makes TAB active and `\let`s it to `\@xobeytab`,
which is `\let` to `\@xobeysp` (`= \nobreakspace = \leavevmode\nobreak\ `);
`verbatim*` re-points both through `\@setupverbvisibletab`. A tab is
therefore exactly whatever one space is, with no dependence on the current
column.

Measured against pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025), oracle only.
`\showbox` of `<TAB>one` in `verbatim` yields a single `\glue 5.24995`
(cmtt10 `\fontdimen2`, stretch and shrink both 0) — byte-identical to the
one-literal-space baseline, not the eight glues the old rule implied. Glyph
origins in the generated PDF, as offsets from the left text edge:

  source line          measured   one-space rule   old 8-column rule
  <TAB>Q                5.23 bp   5.23 bp (1)      41.84 bp (8)
  ab<TAB>W             15.69 bp   15.69 bp (3)     41.84 bp (8)
  abcdefg<TAB>E        41.84 bp   41.84 bp (8)     41.84 bp (8)   [agrees]
  abcdefgh<TAB>R       47.07 bp   47.07 bp (9)     83.99 bp (16)
  abc<TAB><TAB>T       26.15 bp   26.15 bp (5)     83.99 bp (16)
  <TAB><TAB><TAB>Y     15.69 bp   15.69 bp (3)     125.99 bp (24)

`verbatim*` measures identically. Only the 7-column case agrees with the old
rule, which is why it alone could not settle the question.

Moved expectations, each justified by a number above:

* `verbatim_expands_tabs_to_the_next_stop` asserted
  `lines[0].text == " ".repeat(8) + "a"` for a single leading tab. pdflatex
  puts `a` 5.23 bp from the margin, one cmtt10 cell, so the expectation is
  now `" a"`. Replaced by `verbatim_sets_a_tab_as_a_single_space_not_a_column_stop`,
  which also covers column 2, column 8 and two consecutive tabs — the cases
  that actually discriminate between the two rules.
* Added `verbatim_star_sets_a_tab_as_a_single_visible_space`; the starred
  path had no tab coverage at all, and `\@setupverbvisibletab` makes a
  starred tab one visible space rather than eight.

The middle dot for `\verb*`/`verbatim*` is kept, and the doc comment now says
why it is legitimate rather than implying it is lossy. On pdfTeX
`\verbvisiblespace` is `\asciispace` = `\char32`, and cmtt10 slot 32 is
`/visiblespace` (U+2423 OPEN BOX). The Core 14 Courier face this crate lays
out on has no U+2423, so a substitute is unavoidable; U+00B7 costs nothing
geometrically because Courier's AFM width table is uniform and both
`periodcentered` and `space` advance 600/1000 em (6.0 pt at 10 pt body size).

`cargo test --release` in crates/compiler: 470 passed / 0 failed / 4 ignored,
against 469 / 0 / 4 on a control checkout of the same base. The +1 is the one
replaced test becoming two.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar
GoKubar marked this pull request as ready for review September 14, 2026 01:35
@GoKubar
GoKubar merged commit d3fe5a9 into main Sep 14, 2026
20 checks passed
GoKubar added a commit that referenced this pull request Sep 14, 2026
…s for them

main has moved on since `eea975c3`, and two of its merges matter here:

* **#248** committed the 16 listings fixtures (`16`..`31`) with TL2025
  references. `every_committed_fixture_is_accounted_for` refuses a fixture
  that is neither gated nor listed with a reason, so without this the test
  this branch introduces would fail the moment it reached main. The 15 new
  ones go into a separate `LISTINGS_NOT_YET`, each naming the piece of
  listings' geometry it needs -- the `[c]fixed` slack rule, the `\llap`
  number gutter, `\lst@frameInit`'s rule rectangles, `xleftmargin` expanded
  in the basicstyle font, real tab stops, `breakindent` -- taken from the
  measured specification rather than written as placeholders. Two of them
  record findings worth not losing: fixture 19's reference is byte-identical
  to 18's, so it does not actually discriminate `fullflexible` from
  `flexible`; and fixture 25 contains no ligature-forming pair at all, so it
  cannot have been testing what #145 thought it was.
* **#235** made a verbatim tab one space in the compiler, which is the same
  conclusion this branch's `literal_command_body` reached from the other
  side. Nothing to reconcile.

`28-lstinline`'s fixture and reference were added by both sides. main's
reference is kept: it was generated with this host's TeX Live 2025, and the
cross-check in this branch's test doc is exactly the evidence that the two
distributions agree on this material to 0.001 bp.

The one source conflict is `adapter.rs`, where main added
`kern_amount_matches` and this branch added `literal_command_end`/
`literal_command_body` at the same place; both are kept. main's version is
also the pattern this lane needs later: it gates a `text_kern` signature
change behind a `compiler-package-gating` feature so the crate builds
against the pinned mirror either way.

`LiteralBody::starred`'s doc comment loses the claim that the bundled
OpenType Latin Modern has no `visiblespace` glyph. It has one, at U+2423,
named `uni2423` in the CFF charset -- which is what the rest of this branch
is about -- and the field is no longer dead.

`crates/render-pipeline` `cargo test --release --no-fail-fast` with the
bundled fonts configured: **217 passed / 0 failed / 1 ignored**, against a
`git archive` control of `origin/main` at **213 / 0 / 1**. The +4 are this
branch's own tests; no other test changed state.

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 deleted the verbatim-tab-is-one-space 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