zudo-doc
GitHub repository

Type to search...

to open search from anywhere

Math Equations

Created Mar 14, 2026Updated Oct 13, 2026Takeshi Takatsudo

KaTeX math equation support using the MathBlock JSX component.

Copy Markdown manually
The full Markdown is selected. Use your device’s copy command or try Copy again.

When math is enabled in settings (default: false), you can render mathematical equations using KaTeX via the <MathBlock> JSX component.

Note

math: true requires installing the optional peer katex (pnpm add katex@^0.19.0) — create-zudo-doc does not add it for you. See Configuration — math for the full optional-peer contract (katex for math, diff for Document History).

Info

$...$, $$...$$, and ```math fences are not supported in zfb. The zfb Rust MDX emitter does not process those syntaxes — use <MathBlock latex="..." /> instead (shipped as @takazudo/zudo-doc/math-block).

Inline Math

Use <MathBlock latex="..." /> (without the block prop) to embed math within a line of text.

The formula E=mc2E = mc^2 is inline.

The formula <MathBlock latex="E = mc^2" /> is inline.

Block Math

Add the block prop to render a centered display equation.

∫−∞∞e−x2dx=π\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
<MathBlock latex="\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}" block />

Patched KaTeX setup

The unreleased package supports the optional peer ^0.18.2 || ^0.19.0; the consumer matrix covers 0.18.2, 0.18.11 and 0.19.0. This raises the compatibility floor from 0.16.x. Versions below 0.18.2 are affected by GHSA-238p-pmpm-9mq7; 0.20 and later are not part of this contract. This source change has not yet been published to npm.

Install KaTeX only in a math-enabled project:

pnpm add katex@^0.19.0

Import the installed version's stylesheet in src/styles/global.css, before the existing features.css import. The build bundles its CSS and fonts locally; no CDN or client renderer is needed.

@import "katex/dist/katex.min.css";
@import "@takazudo/zudo-doc/features.css";

KaTeX 0.18 renamed its internal .base class to .katex-base; the package styles follow that change while preserving token colors and local display-equation scrolling. Rendering remains server-side, with trust disabled by default and malformed expressions shown as error text. A project that does not use MathBlock needs neither KaTeX nor its stylesheet. Module loading and math-disabled builds work without the peer; rendering MathBlock without it reports a missing-peer error during SSR/build.

Configuration

Math support is controlled by the math field in zfb.config.ts:

zfb.config.ts
export default defineConfig(
  zudoDoc({
    // ...
    math: true, // disabled by default; also `pnpm add katex@^0.19.0`
  }),
);

More Examples

Quadratic Formula

x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
<MathBlock latex="x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}" block />

Summation

∑i=1ni=n(n+1)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
<MathBlock latex="\sum_{i=1}^{n} i = \frac{n(n+1)}{2}" block />

Matrix

[abcd][xy]=[ax+bycx+dy]\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} ax + by \\ cx + dy \end{bmatrix}
<MathBlock latex="\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} ax + by \\ cx + dy \end{bmatrix}" block />

Revision History

Takeshi TakatsudoCreated: 2026-03-14T21:08:12+09:00Updated: 2026-10-13T07:54:57Z

AI Assistant

Ask a question about the documentation.

Preview theme

Loading theme previews…