Skip to content

compiler: diagnose \0-\9 control symbols instead of silently typesetting them - #838

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-muse-lead/ross-recovery
Sep 18, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-muse-lead/ross-recovery

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Summary

  • Real-user-corpus finding (Ross problem sets, set7.tex:206): $\2^9 - 1$ for $2^9 - 1$ compiled with zero diagnostics, silently typesetting "2 9 − 1" — the student never learns their input didn't mean what they thought. pdflatex reports ! Undefined control sequence for \2.
  • Root cause: the lexer maps every backslash+non-letter to a one-character control-symbol word — correct for real commands (\%, \,, \', …) but also silently accepted for \0-\9, which no LaTeX layer defines.
  • Fix: new Diagnostic::undefined_control_symbol reports the digit case as unknown_command with a mechanical suggestion (a digit has exactly one reading, unlike a mistyped name with close neighbours). Rendered output is unchanged — only the missing diagnostic is added.

This is one fix out of a slice comparing FlashTeX's error-recovery quality against pdflatex's own on 5 real typo shapes from a real user's homework corpus (assignment context: issue #2 / Ross corpus). Two other findings from the same comparison are reported but not fixed here (broader-blast-radius recovery-architecture changes):

  • an unknown-command argument-skipping heuristic that orphans a follow-on group on a definition-like typo
  • the did-you-mean tie-break preferring same-length candidates, which misfires on a glued-suffix typo (\cdotg → suggests \cdots instead of \cdot g)
  • unbounded did-you-mean tie lists (single-letter typos can produce 16 equally-close candidates)

Test plan

  • cargo test --locked --test recovery backslash_digit → 1 passed (new test, real typo shape, checks span/suggestion/replacement identity and content survival; \%/\, verified still silent)
  • Full cargo test --locked for crates/compiler → 0 failed
  • crates/compiler/RECOVERY.md regenerated via the repo's own generator (purely additive diff)
  • Needs a crates/render-pipeline/vendor/compiler re-pin to reach users; no render-pipeline code touched.

🤖 Generated with Claude Code

…ing them (Ross corpus finding)

A real user typo (Ross corpus set7.tex:206, `$\2^9 - 1$` for `$2^9 - 1$`)
compiled with zero diagnostics, silently typesetting "2 9 - 1" where
pdflatex reports "! Undefined control sequence" and the student never
learns their input didn't mean what they thought.

Root cause: the lexer maps every backslash+non-letter to a one-character
control-symbol word, correct for real commands like \%, \, and \' but
also silently accepted for \0-\9, which no LaTeX layer defines. New
Diagnostic::undefined_control_symbol reports it as unknown_command with a
mechanical suggestion (a digit has exactly one reading, unlike a mistyped
name with several close neighbours) while keeping the same rendered
output, so recovery behavior is unchanged and only the missing diagnostic
is added.

This is the fix from a slice comparing FlashTeX's error-recovery quality
against pdflatex's own on 5 real typo shapes from a real user's homework
corpus; two other cases (a tie-break preference and an unbounded
did-you-mean list) were reported but not fixed here, as recovery-
architecture changes with broader blast radius.

Tests: cargo test --locked --test recovery backslash_digit -> 1 passed.
Full cargo test --locked for crates/compiler: 0 failed. Needs a
crates/render-pipeline/vendor/compiler re-pin to reach users; no
render-pipeline code touched.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane ross-recovery, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
@d-q222

d-q222 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Independent review: APPROVE.

Over-triggering — the main risk for an error-recovery change — passed. The reviewer built a probe harness against the real crate and checked the legitimate constructs:

  • \def\1{one} \1 → 0 diagnostics (expansion resolves it before this code path runs)
  • \newcommand{\1}{one} \1 → 0 diagnostics

It independently confirmed in real pdflatex that both of those are legal and compile cleanly, which is exactly the false-positive risk this class of change carries. All of \0–\9 fire uniformly; genuine control symbols (\%, \,, \', \ ) never do; \verb|\2| does not false-positive.

Test authenticity verified by revert, not taken on trust: reverting diagnostics.rs/math.rs/parser.rs while keeping the new test makes it fail (left: 0, right: 1).

One wording nit, non-blocking. The body says rendered output is "unchanged". True relative to before-PR FlashTeX — but measured, pdflatex in nonstopmode drops the token entirely (Lead 9 − 1 Tail., the "2" vanishes), while FlashTeX still renders the bare digit. That divergence is pre-existing and out of scope here, but "unchanged" reads as "correct". Worth one line in the body.

Correction to the reviewer's vendor figure, since it affects planning. It reported vendor/compiler as 106 commits behind at PIN=c95977d6. That PIN is from a stale local checkout. On origin/main (f189d339) the PIN file reads 4511166e… and the real lag is 15 commits — confirmed with git show origin/main:crates/render-pipeline/vendor/compiler/PIN and git rev-list --count. (I made this identical mistake earlier tonight reading a PIN from an old branch; scripts/check-vendor-pins.sh, merged in #850, now reports it from the repo root to avoid exactly this.)

The substantive point stands regardless: this fix touches only crates/compiler, so it does not reach flashtex-cli until the re-pin, exactly as the PR body says.

Base is 12 commits behind main but with no file overlap; gh reports CLEAN/MERGEABLE, no deletion risk. Full crates/compiler suite: 0 failed.

@d-q222
d-q222 merged commit e79c491 into main Sep 18, 2026
22 checks passed
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