Skip to main content

Module math

Module math 

Source
Expand description

In-tree TeX math content parser.

Produces a lossless structural CST for the content between math delimiters (the delimiters themselves are owned by the host INLINE_MATH / DISPLAY_MATH nodes, see parser/inlines/math.rs). The returned subtree is rooted at SyntaxKind::MATH_CONTENT and is spliced directly into the host document tree, replacing the opaque content TEXT token.

This is a syntactic parse, not a semantic one: TeX is a Turing-complete macro language, so we only capture structure that a formatter can safely act on — brace groups, \begin/\end environments, control sequences, alignment tabs (&), line breaks (\\), sub/superscript markers, comments, and whitespace. Everything else is an ordinary-atom run (MATH_TEXT).

The CST is lossless and never fails (node.text() == content for every input; worst case is a single MATH_TEXT atom). Structural problems (unbalanced braces, unclosed or mismatched environments) are not reported here: they are derived from the realized tree shape by crate::syntax::math_diagnostics, the single source of truth shared by the linter, formatter, and LSP. Keeping the parser diagnostic-free means the host-aligned ranges come for free from the spliced subtree.

Structs§

MathParseOptions
Flavor-/extension-dependent parsing options for math content. Default is all-off (pure TeX). The math grammar itself is flavor-agnostic; only constructs layered on top of TeX by a Markdown flavor live here.

Functions§

parse_math_content
Parse math content into a lossless MATH_CONTENT green node. content is the raw text between (but excluding) the math delimiters. Never fails: SyntaxNode::new_root(result).text() == content for every input.