name: math/unbalanced-braces default: true advisory: false fix: false since: 0.1.0

math/unbalanced-braces

{ / } inside a math body do not balance; math body normalisation is skipped for that region.

What it does

Inside a math region, flags { and } whose depths do not balance: either an extra opening brace with no matching close, or a stray }.

Why

Math renderers (KaTeX, MathJax, pdflatex) all reject unbalanced braces, but they fail with opaque messages far from the source location. Catching the imbalance in the linter pinpoints the offending region in the markdown source, before the math reaches the renderer.

The check only runs inside math regions identified by [math/unbalanced-delim] and [math/unbalanced-env]; balanced-brace checking in prose would be noise, since prose { and } are not paired.

Example (bad)

$$\sum_{i=1^n i$$

Example (good)

$$\sum_{i=1}^n i$$

Configuration

  • Disable inline: <!-- mdwright: allow math/unbalanced-braces -->.
  • Disable in config: [lint] ignore = ["math/unbalanced-braces"].
  • Severity: non-advisory.

References

  • mdwright's brace scanner (src/stdlib/math_unbalanced_braces.rs).
  • TeX: braces group arguments to commands such as \frac{a}{b} and \sum_{i}.