Make @ a letter only inside makeatletter

The scanner treated @ as a letter everywhere, so \makeatletter was a no-op and
\foo@bar parsed as one command even outside it. Canonicalise the source once,
before captures: in the default state a control word stops at @ (and a marker
keeps later scanners from re-joining the split), between \makeatletter and
\makeatother the name is rewritten with a private-use placeholder that
control_sequence and expand_macro_lookup accept as a letter and normalise back
to @. Grouping saves and restores the state, and route-D's own \@... names plus
the internal \p@/\z@/\protected@edef family stay literal so their handlers keep
matching; markers are stripped from text before shaping.

Tests cover \@foo inside makeatletter, \foo@bar splitting to \foo plus "@bar",
\@ifundefined still working, and a group-local \makeatother.
This commit is contained in:
gloamxun committed 2026-10-27 00:24:28 +08:00
1 parent d4de3a3f35
commit 621a8abb92
3 files changed
+226 -13

No files matched your search

+9 -6
View File
@@ -370,7 +370,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 991 tests (437 route-D unit, 366 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
The crate currently has 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 992 tests (437 route-D unit, 367 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
### M0 incremental demo
@@ -526,9 +526,12 @@ honest open items against the "feature-complete LaTeX compiler" objective are:
- **Macro engine scope**: `\def`-style definitions, registers, conditionals,
`\csname`, `\expandafter`, delimited parameters and `\edef` are executed
textually. `@` counts as a letter in control words (so `\@foo` is one
command), `\makeatletter`/`\makeatother` are consumed as no-ops, and a
line-based capture only consumes a definition when it ends the line. Runtime
textually. `@` is a letter in a control word only between `\makeatletter`
and `\makeatother` (grouping restores the state); user names containing it
are canonicalised through a private-use placeholder, while route-D's own
`\@...`/`\p@`-style names and a small internal list stay literal so their
handlers keep matching. A line-based capture only consumes a definition when
it ends the line. Runtime
expansion keeps a scope stack for `{}` and `\begingroup`/`\endgroup`: a
`\def` inside a group is local to it, while a top-level `\def` or any
`\gdef` updates the document table; grouping braces are removed after
@@ -537,8 +540,8 @@ honest open items against the "feature-complete LaTeX compiler" objective are:
runs before `\begin{document}` and outside braces, so a definition on its own
line inside a group stays local. `\edef`/`\xdef` lines in the preamble and in
the body expand their bodies (including `\csname`) when read, while a plain
`\def` stays lazy. There is still no catcode state and no token stream, so
class code that relies on those semantics degrades.
`\def` stays lazy. There is still no catcode table beyond `@` and no token
stream, so class code that relies on those semantics degrades.
- **Boxes**: `\sbox`/`\savebox` content and `\mbox`/`\hbox`/`\makebox`
bodies are inserted as one unbreakable inline box (interword spaces become
fixed-width boxes), so `\usebox` no longer reflows across lines. Savebox