Skip to main content

Module scan

Module scan 

Source
Expand description

Structural math recogniser.

Walks source left-to-right with exclusion zones derived from the IR’s inline / block atoms (code spans, code blocks, HTML blocks, inline HTML). Inside an exclusion the scanner skips ahead to the zone’s end, so $ inside `cost is $5` or <a title="$x$"> cannot anchor a math region.

Three opener families are recognised:

  • Delimited pairs: \[ … \], \( … \), $$ … $$, $ … $. Greedy first-close matches the heuristic scanner’s behaviour and the way KaTeX / pandoc resolve these in practice.
  • LaTeX environments: \begin{name} … \end{name}. The recogniser counts nested \begin{name} so an inner environment of the same name does not close the outer.

Each recognised region carries a MathSpan tag (inline, display, or environment) with the body byte range.

Unmatched openers become MathError values without aborting the scan. Brace imbalance inside a recognised body is checked once per region and surfaces as MathError::UnbalancedBraces; the region still scans because its markers are balanced; canonicalisation skips body rewrites for that region.

Structs§

MathConfig
Which math delimiter pairs to recognise.

Functions§

scan_math_regions
Scan source for math regions. Returns regions in source order (non-overlapping) and any unmatched openers / brace-imbalanced bodies as errors.