Skip to content

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

Closed

Description

@charlesroddie

The math parser doesn't like the following:

\sin'
\mu=
\left{ \frac{-b}{2a} \right}
$35.99 \%$

Originally reported errors:

Error: [Math] Invalid command \sin'
Error: [Math] Invalid command \mu=
Error: [Math] Invalid delimiter {
Error: Missing closing brace

Maintainer triage (2026-08-30)

Reproduced against the current master parser:

  • \sin' → Invalid command \sin'
  • \mu= and \Delta= → invalid commands
  • The spaced/braced forms (\Delta =, \Delta{}=) parse successfully

These failures have one tokenizer cause: LaTeXCommandDictionary.SplitCommand absorbs ' and = into the preceding control word. TeX control words end at the first non-letter, so the punctuation must be parsed as the next token. A standalone prime already parses (x'), which confirms that \sin' should be tokenized as \sin followed by '.

Two original examples are not remaining bugs:

  • A brace used as a \left/\right delimiter must be escaped in LaTeX. \left\{ \frac{-b}{2a} \right\} parses; \left{...\right} is invalid input.
  • $35.99 \%$ now parses. (Callers passing math content directly can omit the surrounding $ delimiters.)

Acceptance criteria

  • \sin' parses equivalently to a sine operator followed by a postfix prime.
  • \mu=, \Delta=, and other control words followed immediately by non-letter punctuation parse the same as their spaced equivalents.
  • Explicitly supported starred-command behavior is preserved or handled after normal TeX control-word tokenization.
  • Parser and round-trip regression tests cover apostrophe, equals, and the corrected escaped-brace form.

Activity

  1. added
    Type/Bug
    on Nov 2, 2020
  2. Happypig375 commented on Nov 16, 2020

    @Happypig375
    Collaborator

    This is related to how commands are parsed. It is hard to know whether ' and = are part of the command name or are their own symbols after commands. More digging around LaTeX documentation is needed.

  3. haribo841 commented on Jul 12, 2026

    @haribo841

    SplitCommand method (line 87) in /Structures/Dictionary.cs also don't handle * at the end. Parser explicitly (intentionally increases splitIndex for *, = and ', i.e. includes these characters in the token passed to TryLookup()) appends these signs to the command name, so it reads for ex. also \Delta= as a non-existent command. \Delta{}= and \Delta = circumvent the flaw fo me.

  4. changed the title [-]Invalid command \sin'[/-] [+]Parse punctuation after LaTeX control words (\sin', \mu=, \Delta=)[/+] on Aug 30, 2026
  5. Happypig375 commented on Aug 30, 2026

    @Happypig375
    Collaborator

    Triage update: this remains a real, actionable tokenizer bug, but not for all four original examples. Current master reproduces \sin', \mu=, and \Delta=; it accepts $35.99 \%$ and the valid escaped-brace form \left\{...\right\}.

    The expected token boundary is defined by TeX: a control word is a backslash plus letters and ends before the first non-letter. See the LaTeX2e control-sequence reference and the \left/\right delimiter reference.

    I updated the title/body with the current reproduction and acceptance criteria so the issue can be implemented without re-investigating the obsolete examples.

  6. added
    Area/Parsing
    on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area/ParsingType/Bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions