Skip to main content

Crate mdwright_math

Crate mdwright_math 

Source
Expand description

Math-region grammar.

TeX-style math (\[ … \], \( … \), $$ … $$, $ … $, \begin{env} … \end{env}) is opaque to CommonMark: pulldown tokenises the bytes inside as plain prose, so _ becomes emphasis, [ becomes a link candidate, * becomes a delimiter run. Without an overlay the formatter’s round-trip drifts.

This module is the structural recogniser. scan::scan_math_regions consumes source plus the IR’s inline / block atoms and produces:

  • MathRegion values consumed by the format pipeline. The region carries a span::MathSpan tag with delimiter and body data.
  • span::MathError values surfaced by the math/unbalanced-delim, math/unbalanced-env, and math/unbalanced-braces lint rules.

Stack-based tracking enforces \begin / \end balance with nesting on the same environment name; the four primitive delimiter pairs match greedily on first close.

Re-exports§

pub use scan::MathConfig;
pub use scan::scan_math_regions;
pub use span::AnyDelim;
pub use span::DisplayDelim;
pub use span::InlineDelim;
pub use span::MathBody;
pub use span::MathError;
pub use span::MathSpan;

Modules§

env
LaTeX environment classification.
normalise
Pure string-to-string math-body normalisations.
render
Delimiter rewrite helper for dollar-shaped renderer output.
scan
Structural math recogniser.
span
Delimiter classification, recogniser error types, and per-region tagged spans.

Structs§

MathRegion
One recognised math region in source order.