Skip to content

render-pipeline: @ is a letter inside \makeatletter for column-switch scan (#801) - #817

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-muse-lead/columns-atname-scan
Sep 17, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-muse-lead/columns-atname-scan

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

What

columns.rs's definition-body skipping (definition_end/skip_control_or_group) scanned control-word names as ASCII letters only, so under \makeatletter a name containing @ wasn't recognised as a definition target: \let\@oldtc\twocolumn stopped after the \@ control symbol, leaving oldtc\twocolumn to fall through as if \twocolumn were genuinely invoked — a one-column article incorrectly rendered two-column with no diagnostic. Same gap for the brace-less \newcommand\@x\twocolumn form.

Added is_name_char/control_word_end, and a boolean in_makeat toggle (pdflatex errors on unmatched \makeatletter/\makeatother, so nesting isn't a real concept) tracked as switches() walks the document and threaded into definition_end/skip_control_or_group/skip_one_token — one fix point covers \let, the \newcommand family, the \def family and the \newenvironment family.

Left out of scope (follow-up)

The issue's ".sty/.cls always treat @ as a letter" part — ColumnMode::scan is called with only the entry document's text, no file-kind signal reaches this scanner yet. The related \let-saved-switch unknown_command note is explicitly out of scope per the issue.

Tests

at_names_in_makeatletter_definitions_do_not_switch (both issue cases plus \onecolumn/\def variants), at_outside_makeatletter_does_not_swallow_a_switch (negative control — pdflatex itself errors there, so the existing "leak" behavior is preserved), makeatother_closes_the_at_region. Mutation check: forcing the old call sites makes the first test fail while the rest pass. Full cargo test in crates/render-pipeline clean (independently re-run twice by the supervisor, including after a rebase onto latest main).

Closes #801.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane columns-atname-scan, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)

🤖 Generated with Claude Code

… scan (#801)

`columns.rs`'s definition-body skipping (`definition_end`/`skip_control_or_group`)
scanned control-word names as ASCII letters only, so under `\makeatletter`
a name containing `@` wasn't recognised as a definition target:
`\let\@oldtc\twocolumn` stopped after the `\@` control symbol, leaving
`oldtc\twocolumn` to fall through as if `\twocolumn` were genuinely
invoked — a one-column article incorrectly rendered two-column with no
diagnostic. Same gap for the brace-less `\newcommand\@x\twocolumn` form.

Added `is_name_char`/`control_word_end`, and a boolean `in_makeat` toggle
(pdflatex errors on unmatched `\makeatletter`/`\makeatother`, so nesting
isn't a real concept) tracked as `switches()` walks the document and
threaded into `definition_end`/`skip_control_or_group`/`skip_one_token` —
one fix point covers `\let`, the `\newcommand` family, the `\def` family
and the `\newenvironment` family. `switches()`'s own `\twocolumn`/
`\onecolumn` match now reuses the same state-aware word scan.

Left out of scope (follow-up): the issue's ".sty/.cls always treat @ as a
letter" part — `ColumnMode::scan` is called with only the entry document's
text, no file-kind signal reaches this scanner yet. The related
`\let`-saved-switch `unknown_command` note is explicitly out of scope per
the issue.

Tests: at_names_in_makeatletter_definitions_do_not_switch (both issue
cases plus \onecolumn/\def variants), at_outside_makeatletter_does_not_
swallow_a_switch (negative control — pdflatex itself errors there, so the
existing "leak" behavior is preserved), makeatother_closes_the_at_region.
Mutation check: forcing the old (pre-fix) call sites makes the first new
test fail while the rest pass; restoring the fix, all 19 columns tests
pass.

Full `cargo test` in crates/render-pipeline (independently re-run by the
supervisor): all suites ok, 0 failed (lib 190 passed, 1 pre-existing
ignore; every integration binary ok including twocolumn_command 7/7,
twocolumn_banner 13/13, twocolumn_geometry_option 4/4).

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane columns-atname-scan, 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 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent Opus review of 653addc3, APPROVE. Merging in batch T. Two non-blocking follow-ups for daniel-muse-lead: group scoping of \makeatletter, and a wrong code comment about pdflatex erroring.

PR #817 review (head 653addc)

render-pipeline: @ is a letter inside \makeatletter for column-switch scan (GH#801)

Material findings

None.

Analysis

  • switches() now reads each whole control word with control_word_end and
    matches the name exactly. This matches the old strip_prefix/step logic for
    every name without @. \twocolumnfoo is still rejected. \\ and control
    symbols still move forward by 2. The span end (word_end) equals the old
    i+1+name.len() on a match. All slicing is at ASCII boundaries, so there is
    no UTF-8 panic risk.
  • in_makeat flows into definition_end, skip_control_or_group and
    skip_one_token, so \let\@oldtc\twocolumn, \newcommand\@x\twocolumn,
    \renewcommand*\@x[1]{..} and \let\tc@old\twocolumn now skip the whole
    defined name.
  • False positives in user text: \@twocolumn and \if@twocolumn outside
    \makeatletter still read as \@ or \if followed by plain text, so neither
    counts as a switch. Inside \makeatletter they are single words that do not
    match either. Probed on both base and PR: no spans.
  • Package/class code: ColumnMode::scan is only called from adapter.rs:1340
    on the document source. .sty/.cls bodies (where @ is a letter
    implicitly) are not scanned, so this is not a concern here.
  • A plain \twocolumn inside a \makeatletter region is still detected (probed).

Non-blocking notes

  1. columns.rs:105-107: the comment "pdflatex raises an error on unmatched
    \makeatletter/\makeatother, so nesting is not a real concept" is wrong.
    pdflatex does not error on unmatched calls. More importantly, a catcode change
    is local to its group. The toggle ignores {/} and \begingroup/\endgroup,
    so \begingroup\makeatletter...\endgroup leaves in_makeat stuck at true.
    Probed failure: \begingroup\makeatletter\gdef\@a{}\endgroup ... \begin{document}\twocolumn@ x is a real \twocolumn in TeX; base detects it,
    the PR misses it. This is contrived (\twocolumn directly followed by @ in
    valid text) and the effect is only a column-mode heuristic, so it is not
    blocking. Fix the comment. Optionally, save and restore in_makeat across
    group depth.
  2. Test at_names_in_makeatletter_definitions_do_not_switch: the 4th case
    (\def\@narrow{\twocolumn}) already passes on base, because the body is
    skipped either way. It is harmless but proves nothing about render-pipeline: column-switch scan misses definitions of @-names (\makeatletter\let\@oldtc\twocolumn flips a one-column article) #801. The let,
    newcommand and let-one cases do fail on base (verified per case).
  3. makeatother_closes_the_at_region, 2nd case: on base this also passes
    (outside makeat, behavior is unchanged). It is a valid pin, not a regression proof.

Tests run (crate dir, nice, CARGO_BUILD_JOBS=3)

  • PR: cargo test --locked --lib columns:: gives 18 passed.
  • Base columns.rs with the PR's 3 new tests inserted: 17 passed, 1 FAILED
    (at_names_in_makeatletter_definitions_do_not_switch). This confirms the fix is
    what the test proves.
  • Ad-hoc probe test (not committed) on base vs PR, per case start/spans:
    let F/T->F/0, newcommand T->F, let-one(class twocolumn) F->T, def unchanged,
    at-mid-word T->F, renew*-opt T->F, user \@twocolumn/\if@twocolumn 0 spans
    on both, makeat plain \twocolumn detected on both, group-leak T->F (note 1).

VERDICT: APPROVE

@d-q222
d-q222 merged commit 8b3e7b3 into main Sep 17, 2026
21 of 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.

render-pipeline: column-switch scan misses definitions of @-names (\makeatletter\let\@oldtc\twocolumn flips a one-column article)

1 participant