Skip to content

Respect TeX control-sequence boundaries - #276

Merged
Happypig375 merged 2 commits into
masterfrom
fix/issue-182-control-word-boundary
Aug 31, 2026
Merged

Happypig375 merged 2 commits into
masterfrom
fix/issue-182-control-word-boundary

Conversation

@Happypig375

@Happypig375 Happypig375 commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • tokenize ordinary LaTeX control words as backslash plus ASCII letters only
  • treat @ as a non-letter by default: \@ is a one-character control symbol, and \foo@bar ends at \foo
  • keep apostrophe, relation, and star punctuation available to the normal parser
  • consume delimiter whitespace only after control words, not control symbols
  • reject backslash-prefixed command registrations that extend beyond their token boundary

Specification

CSharpMath does not track catcode-changing contexts, so it uses the ordinary document boundary where @ has default catcode 12.

Regression coverage

  • adjacent apostrophe, relation, and star punctuation
  • @ terminating a control word and \@ acting as a control symbol
  • control-word versus control-symbol whitespace
  • acceptance of reachable command keys and rejection of unreachable keys
  • parser atom types and exact serialization

Compatibility

Previously accepted custom command names containing @, such as \foo@bar, are now rejected as unreachable under the default tokenizer. Supporting package-style names would require explicit catcode-context support rather than an unconditional exception.

Validation

  • full Core Release suite: 1,533/1,533 passed
  • focused tokenizer/parser cases: 21/21 passed
  • independent code review: approved
  • git diff --check passed

Fixes #182

@Happypig375 Happypig375 added Type/Bug A reproducible defect in CSharpMath. Area/Parsing LaTeX tokenization, parsing, commands, and serialization. labels Aug 30, 2026
@Happypig375

Happypig375 commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

Resolved and merged as d8d5d004.

Clarification on @: it is not a CSharpMath custom extension, and the earlier Stack Overflow wording was only a quotation from that linked post, not the specification. Under the ordinary LaTeX document catcode regime, @ is a non-letter, so \@ is a one-character control symbol and \foo@bar ends the control word at \foo. Inside a \makeatletter context, LaTeX temporarily makes @ a letter, allowing package-style control words that contain it.

CSharpMath does not model mutable TeX catcodes or \makeatletter contexts. It therefore uses the ordinary document rule consistently: control words are backslash plus ASCII letters; control symbols are backslash plus one non-letter; delimiter whitespace is discarded only after a control word. Registrations that extend beyond that reachable token boundary are rejected.

Authoritative references: LaTeX2e control sequences and \makeatletter / \makeatother.

Full Core validation passed 1,533/1,533 tests before merge.

@Happypig375
Happypig375 merged commit d8d5d00 into master Aug 31, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area/Parsing LaTeX tokenization, parsing, commands, and serialization. Type/Bug A reproducible defect in CSharpMath.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse punctuation after LaTeX control words (\sin', \mu=, \Delta=)

2 participants