Mathematics

The @streamdown/math plugin renders LaTeX mathematical notation using KaTeX. It supports both inline expressions and block equations.

Overview

Mathematical expressions are written using standard LaTeX syntax. Inline maths uses single dollar signs ($...$) and block equations use double dollar signs ($$...$$).

Inline maths

Use single dollar signs for inline expressions within paragraph text:

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

The function $f(x) = ax^2 + bx + c$ is a quadratic polynomial.
Rendered output

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

The function f(x)=ax2+bx+cf(x) = ax^2 + bx + c is a quadratic polynomial.

Single dollar sign support

Single dollar sign maths ($...$) is enabled by default. You can disable it in the plugin configuration if it conflicts with your content.

Block equations

Use double dollar signs for centred block equations:

markdown
The quadratic formula:

$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$

Euler's identity:

$$e^{i\pi} + 1 = 0$$
Rendered output

The quadratic formula:

x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Euler's identity:

eiπ+1=0e^{i\pi} + 1 = 0

Examples

Common mathematical expressions you might use in documentation:

ExpressionLaTeX
Summation$$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$
Integral$$\int_{0}^{\infty} e^{-x} dx = 1$$
Matrix$$\begin{pmatrix} a & b \\ c & d \end{pmatrix}$$
Limit$$\lim_{x \to 0} \frac{\sin x}{x} = 1$$

Configuration

Custom maths plugin
import { createMathPlugin } from "@streamdown/math"

const math = createMathPlugin({
  // Allow single dollar sign inline maths
  singleDollarTextMath: true,
  // Colour for rendering errors
  errorColor: "#dc2626",
  // Output format: "html" or "mathml"
  output: "html",
  // Strict mode: warn on unsupported commands
  strict: false,
})