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).

Two outputs, two channels — the same split YAML uses (see parser/yaml/model.rs) and that texlab uses for LaTeX:

  • the CST is lossless and never fails (node.text() == content for every input; worst case is a single MATH_TEXT atom), and
  • errors ride a side-channel (MathParseReport::diagnostics) so the linter (and by proxy the LSP) can surface unbalanced braces and mismatched environments without the parser ever rejecting input.

Modules§

diagnostic_codes
Stable diagnostic codes for math content. Mirrors yaml::diagnostic_codes.

Structs§

MathDiagnostic
A non-fatal problem found while parsing math content. Byte offsets are relative to the math content string (the caller offsets them into host document coordinates when surfacing through the linter/LSP).
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.
MathParseReport
The lossless CST plus any diagnostics gathered on the side-channel.

Functions§

parse_math_content
Parse math content into a lossless MATH_CONTENT green node, discarding diagnostics. content is the raw text between (but excluding) the math delimiters.
parse_math_report
Parse math content into a lossless CST plus a side-channel of diagnostics.