Skip to content

Parse inline math spans inside \text{...} #205

Open

Description

@mauler2025

Inside math mode, CSharpMath currently treats \text{...} as a Roman math list. Nested inline-math delimiters are therefore ignored: \text{if $n$ is even} does not switch back to math for n.

Reproduction:

f(n) = \begin{cases}
n/2, & \text{if $n$ is even} \
3n+1, & \text{if $n$ is odd}
\end{cases}

Acceptance criteria:

  • \text{...} parses ordinary text content and can enter/leave inline math with balanced $ delimiters.
  • The n atoms above use math layout while the surrounding words use text layout and spacing.
  • Escaped dollar signs remain literal text.
  • Unbalanced nested math delimiters return a useful position-aware error.
  • Parsing, serialization, and rendering tests cover the cases expression and mixed text/math round trips.

The parser unification needed to avoid maintaining two incompatible mode implementations is tracked by #58.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area/ParsingLaTeX tokenization, parsing, commands, and serialization.Type/BugA reproducible defect in CSharpMath.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions