Skip to content

tex-expansion: give TAB catcode 10 (fixes root cause of #839 and #836) - #840

Merged
d-q222 merged 2 commits into
mainfrom
muse/ross-tab-whitespace
Sep 18, 2026
Merged

d-q222 merged 2 commits into
mainfrom
muse/ross-tab-whitespace

Conversation

@d-q222

@d-q222 d-q222 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Give TAB catcode 10, as both TeX formats do

Fixes the root cause behind #839 and #836, found by real-user corpus testing after the owner reported "flashtex doesn't render if you use tabs".

The bug

CatCodeTable::plain_initial() assigned \, % and space but never \t, so a literal TAB kept the array fill value CatCode::Other (12), lexed as a printable character, and reached shaping — which has no glyph for U+0009.

Why plain_initial() and not latex_initial()

An earlier analysis argued TAB is genuinely catcode 12 in plain TeX and the assignment therefore belonged in latex_initial(). That is wrong, and it is worth recording why. Both formats set it, with the identical comment:

  • plain.tex:18 — \catcode^^I=10 % ascii tab is a blank space`
  • latex.ltx:314 — \catcode^^I=10 % ascii tab is a blank space`

Confirmed empirically rather than by reading: \the\catcode^^Iprints **10** underpdftex(plain) and **10** underpdflatex`. TeX Live 2026.

No lexer change was needed — the Space-arm state handling already implements start-of-line skipping and run collapsing once the catcode is right.

Evidence

Real-user corpus: 20 Ross Mathematics Program problem sets, 19 of which use tabs (4,755 lines of tab indentation, 49 mid-line tabs).

before after
set1.tex diagnostics 632 (597 = no glyph for '\t') 35, none mentioning U+0009
all 20 files tab diagnostics throughout zero in every file

The A/B also proves the live crate really loaded: reverting the single line reproduces the flood.

Two filed defects trace to this one table entry:

Tests

  • New crates/compiler/tests/tab_whitespace.rs, 5 tests: tab ≡ space in text and math mode, start-of-line collapse, run collapse, group edges, tab-only input, trailing tab. Authentic pre-fix failure: all 5 failed before the change with the U+0009 glyph error.
  • crates/compiler: 1,055 passed, 0 failed (86 binaries). crates/tex-expansion: all green.

⚠️ This does not reach users yet

flashtex-render-pipeline builds against the frozen snapshot crates/render-pipeline/vendor/tex-expansion, which still carries the old table. The CLI binary is byte-unchanged by this commit — I rebuilt it and confirmed the repros still fail through the renderer. A vendor re-pin is required and is tracked separately; I'll fold it into the pending consolidated re-pin.

Provenance

Implemented by a sandboxed Muse lane (muse/ross-tab-whitespace). The lane hit an expected sandbox denial — its worktree .git pointer resolves outside the sandbox root, so git and muse.write_file were unusable — reported it, made no commits, and never touched .git or renamed anything to work around it, which is the required behaviour. I committed and published on its behalf after verifying the change and re-running the tests.

🤖 Generated with Claude Code

d-q222 and others added 2 commits September 17, 2026 18:34
…ex.ltx do

A literal TAB (U+0009) lexed as a printable "other" character (catcode 12)
and reached shaping, which has no glyph for it. Both formats set it to 10:
plain.tex:18 and latex.ltx:314 carry the identical `\catcode`\^^I=10 % ascii
tab is a blank space`, and `\the\catcode`\^^I` prints 10 under pdftex and
pdflatex alike -- so the assignment belongs in plain_initial(), not only in
latex_initial().

No lexer change was needed: the Space-arm state handling already implements
start-of-line skipping and run collapsing once the catcode is right.

Measured on a real-user corpus (20 Ross Mathematics Program problem sets,
19 of which use tabs -- 4,755 lines of tab indentation): set1.tex went from
632 diagnostics, 597 of them `no glyph for '\t' (U+0009)`, to 35 with none
mentioning U+0009. All 20 files now emit zero tab diagnostics.

This also underlies two filed defects: #839 (a tab-only line failed to end a
paragraph, so paragraphs merged -- 14/20 corpus documents) and #836 (a tab
between \begin{itemize} and the first \item started an empty paragraph,
adding one \baselineskip; replacing that whitespace takes set3 from 10 pages
to 9, matching pdflatex).

NOTE: this does NOT reach users yet. flashtex-render-pipeline builds against
the frozen snapshot crates/render-pipeline/vendor/tex-expansion, which still
carries the old table; the CLI binary is byte-unchanged by this commit. A
vendor re-pin is required and is tracked separately.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: daniel-parent
Co-authored-by: muse-spark-1.3-contributor <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
Both points from the independent review of #840.

The comment cited TeXbook p. 341 for TAB=10. That page is the INITEX table,
where TAB is 12 -- the reviewer verified `pdftex -ini` prints 12 while plain
pdftex and pdflatex both print 10. The value comes from the formats
(plain.tex:18, latex.ltx:314), not from INITEX. The comment now says so, and
notes that this table already models the post-format state: {, $, &, #, ^, _
and ~ are all assigned here and are all 12 in virgin INITEX.

The five existing tests only compared tab against space, so a regression that
broke paragraph breaking for BOTH would have kept them green -- exactly the
gap the reviewer identified. whitespace_only_line_ends_the_paragraph pins the
absolute behaviour instead: a tab-only line, a space-only line and an empty
line must all produce 2 blocks. Verified authentic by removing the catcode
line and watching it fail.

Implementation-Agent: daniel-parent
Commit-Executor: daniel-parent
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Independent review: APPROVE. Both of its findings are now fixed in 1e0a30b-series follow-up; recording the review here because two of its verifications are worth keeping.

Placement was right, and the objection was wrong twice over. The reviewer ran three engines: pdftex (plain) → TAB=10, pdflatex → 10, pdftex -ini (virgin INITEX) → 12. TAB is 12 only in INITEX; plain.tex:18 makes it 10 in the plain format itself. The earlier analysis confused INITEX with plain TeX. It also observed the question is moot here — latex_initial() is literally Self::plain_initial(), one table — and that plain_initial() already assigns {, $, &, #, ^, _, ~, all of which are 12 in virgin INITEX. That table has always modelled the post-format state, so TAB=10 sits consistently with its existing contents.

No regressions, verified empirically rather than architecturally. verbatim, \verb and lstlisting with embedded tabs are byte-identical pre- and post-fix. Tab→space in verbatim is pre-existing and untouched: expansion.rs:221-359 blanks verbatim byte ranges to ASCII spaces in a private copy before tokenization, and parser.rs:7166+ re-reads verbatim bodies from the original source, so verbatim never reaches CatCodeTable. \obeylines/\obeyspaces/tabbing are parser-state flags, not catcode machinery (CatCodeTable::set has exactly two call sites). Suites green: tex-expansion, compiler (29 suites), bridge (18), paragraph-layout (15).

Fixed in this follow-up:

  1. Test gap. The five original tests only compared tab against space — a regression breaking paragraph breaking for both would have kept them green. Added whitespace_only_line_ends_the_paragraph, pinning the absolute behaviour (tab-only ≡ space-only ≡ empty line ≡ 2 blocks). Confirmed authentic: removing the catcode line makes it fail.
  2. Wrong citation. Dropped the TeXbook p. 341 reference and replaced it with the formats, plus the reasoning about why this table models post-format state.

Two things for the Commander, not for this PR:

Merging.

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