1. Home
  2. ChevronRight@bdocs/plugin-math

@bdocs/plugin-math

Render LaTeX math equations in your MDX documentation using the @bdocs/plugin-math plugin.

The @bdocs/plugin-math plugin integrates KaTeX into Boltdocs. It automatically transforms standard LaTeX delimiters ($ and $) into beautifully rendered math equations at build time, with zero configuration required.


Live DemoLink

Here is inline math: E=mc2E = mc^2, and block math:

k=11k2=π26\sum_{k=1}^{\infty} \frac{1}{k^2} = \frac{\pi^2}{6}

The quadratic formula x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} finds the roots of ax2+bx+c=0ax^2 + bx + c = 0.


Installation & Quick StartLink

Get started by adding the plugin package to your documentation project.

1. Install the packageLink

pnpm add @bdocs/plugin-math

2. Register the pluginLink

Add the plugin to the plugins array in your configuration file:

boltdocs.config.ts
import { defineConfig } from 'boltdocs'
import mathPlugin from '@bdocs/plugin-math'

export default defineConfig({
  plugins: [mathPlugin()],
})

Concepts & ArchitectureLink

The math plugin uses a build-time transformation pipeline to keep your pages fast:

  1. AST Transformation: When Boltdocs parses your MDX files, the plugin's Remark compiler scans text nodes for $...$ and $...$ delimiters. It transforms them into <Math> and <BlockMath> React components directly in the MDX AST.

  2. Client-Side Rendering: KaTeX renders the LaTeX expressions to semantic HTML at runtime via katex.renderToString(). The result is injected using dangerouslySetInnerHTML — no iframes, no layout shifts.

  3. CSS via CDN: KaTeX styles are loaded from a CDN, keeping your bundle lean. Import the stylesheet from @bdocs/plugin-math/style.css if your bundler supports CSS imports.


UsageLink

Inline MathLink

Wrap short expressions with a single $ delimiter:

The famous equation $E = mc^2$ relates energy and mass.

Block MathLink

Use $ delimiters for standalone centered equations:

$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$

FractionsLink

$
\frac{a}{b} \quad \frac{x + y}{x - y}
$

Summations and ProductsLink

$
\sum_{k=0}^{\infty} \frac{1}{k^2} = \frac{\pi^2}{6}
\qquad
\prod_{i=1}^{n} x_i
$

IntegralsLink

$
\int_{a}^{b} f(x) \, dx
\qquad
\oint_{C} \vec{F} \cdot d\vec{r}
$

MatricesLink

$
\begin{pmatrix}
a_{11} & a_{12} & \dots & a_{1n} \\
a_{21} & a_{22} & \dots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \dots & a_{mn}
\end{pmatrix}
$

Systems of EquationsLink

$
\begin{cases}
x + y = 10 \\
x - y = 4
\end{cases}
$

Combined ExampleLink

The quadratic formula $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ gives
the roots of $ax^2 + bx + c = 0$. The discriminant is:

$
\Delta = b^2 - 4ac
$

When $\Delta > 0$, there are two distinct real roots.

API ReferenceLink

Plugin OptionsLink

The mathPlugin() function accepts no options. It works out of the box with zero configuration.

Math ComponentLink

Properties supported when using the <Math /> React component directly in MDX.

PropertyTypeDefaultDescription
childrenstring(Required)The LaTeX expression to render inline.

BlockMath ComponentLink

Properties supported when using the <BlockMath /> React component directly.

PropertyTypeDefaultDescription
childrenstring(Required)The LaTeX expression to render as a block.

Component SyntaxLink

For advanced use cases, you can invoke the JSX components directly:

Inline: <Math>E = mc^2</Math>

Block: <BlockMath>\sum_{i=1}^{n} i</BlockMath>

KaTeX Quick ReferenceLink

Common LaTeX commands supported by KaTeX:

Fractions and RootsLink

CommandDescription
\frac{a}{b}Fraction
\sqrt{x}Square root
\sqrt[n]{x}Nth root

Greek LettersLink

CommandDescription
\alphaAlpha
\betaBeta
\gammaGamma
\deltaDelta
\thetaTheta
\piPi
\sigmaSigma
\phiPhi
\omegaOmega

OperatorsLink

CommandDescription
\sumSummation
\prodProduct
\intIntegral
\ointContour integral
\limLimit
\logLogarithm
\sinSine
\cosCosine

DelimitersLink

CommandDescription
\left( ... \right)Adaptive parentheses
\left[ ... \right]Adaptive brackets
\lbrace ... \rbraceBraces
\langle ... \rangleAngle brackets

SymbolsLink

CommandDescription
\inftyInfinity
\partialPartial derivative
\nablaGradient (nabla)
\approxApproximately equal
\neqNot equal
\leqLess than or equal
\geqGreater than or equal
\pmPlus-minus
\toArrow
\cdotDot
\dotsEllipsis
\quadSpacer

AccentsLink

CommandDescription
\hat{x}Hat
\bar{x}Bar
\tilde{x}Tilde
\vec{x}Vector arrow

MatricesLink

CommandDescription
\begin{pmatrix} ... \end{pmatrix}Matrix with parentheses
\begin{bmatrix} ... \end{bmatrix}Matrix with brackets
\begin{cases} ... \end{cases}Piecewise / system of equations
\begin{aligned} ... \end{aligned}Aligned equations

TroubleshootingLink

Equations do not renderLink

  • Verify Configuration: Ensure mathPlugin() is registered in your boltdocs.config.ts plugins array.
  • Check Delimiters: Use single $ for inline math and double $ for block math. No spaces between the delimiter and the expression are required.

KaTeX CSS missingLink

The plugin loads KaTeX styles from a CDN. If styles are missing, import the CSS file in your layout or stylesheet:

@import url('https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css');

LaTeX syntax errorsLink

When KaTeX encounters invalid LaTeX syntax, the raw expression is displayed as fallback text. Check the browser console for specific error messages. Common issues include:

  • Unmatched braces { / }
  • Missing \ before commands
  • Invalid operator names
  • Unescaped special characters like _ or &

Matrices overflowLink

For wide matrices or long equations, the block math container enables horizontal scrolling automatically. No additional CSS is needed.

Last updated on July 27, 2026

Was this page helpful?