Nextra supports mathematical typesetting through two renderers: KaTeX pre-renders LaTeX expressions at build time for fast, flicker-free display, while MathJax renders math dynamically in the browser with richer accessibility features. LaTeX support is disabled by default and must be enabled in your Nextra configuration.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
Setup
import nextra from 'nextra'
const withNextra = nextra({
latex: true
})
export default withNextra({})
Import from katex package
Install the
katex package and import its stylesheet in your root layout: Load from CDN
Add a Alternatively, include the
<link> tag directly in your root layout file. Note that <link rel="stylesheet" /> is not supported via the Next.js Metadata API, so include it as JSX:<link> directly in any individual MDX file where KaTeX is used.Writing Math
Once enabled, you can write LaTeX expressions in your MDX files.Inline Math
Wrap an expression in single dollar signs for inline math:Block Math
Use a fenced code block with themath language tag for display (block-level) equations:
Full Example
MathJax Options
When using MathJax, math is rendered client-side viabetter-react-mathjax. Pass configuration through the options key:
| Option | Type | Description |
|---|---|---|
options.src | string | URL for the MathJax script. Defaults to the MathJax CDN at cdnjs.cloudflare.com. |
options.config | object | MathJax configuration passed at init time. |
Only serializable values can be passed via
options in next.config.mjs.
To pass Functions or other non-serializable objects, use the
<MathJaxContext config={...} /> component directly in your MDX source.KaTeX vs. MathJax
KaTeX
Pre-renders math at build time — no flicker, fastest possible page loads.
Does not support all LaTeX features, particularly those related to
accessibility.
MathJax
Renders math at page load in the browser. Tab-accessible formulas with a
context menu that helps screen readers reprocess math for the visually
impaired. Supports a broader set of LaTeX features.
Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
latex | boolean | { renderer: 'katex' | 'mathjax', options?: {...} } | undefined | Enable LaTeX support and choose a renderer. |
latex.renderer | 'katex' | 'mathjax' | 'katex' | Which math renderer to use. |
latex.options | RehypeKatexOptions | MathJaxOptions | {} | Renderer-specific options. |