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.

Activity

  1. added
    Type/Bug
    on Feb 28, 2022
  2. changed the title [-]Math mode in \text gets ignored[/-] [+]Parse inline math spans inside \text{...}[/+] on Aug 30, 2026
  3. 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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions