Writing math equations in Markdown/MDX documents

Getting Started

Fumadocs doesn't bundle with other plugins, you have to manually install those plugins.

npm install remark-math rehype-katex katex

Add Plugins

Add the remark/rehype plugins you have installed above.

The code might be vary depending on your content source, here is an example for Fumadocs MDX:

import createMDX from 'fumadocs-mdx/config';
import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
const withMDX = createMDX({
  mdxOptions: {
    remarkPlugins: [remarkMath],
    // Place it at first so that it won't be changed by rehype-pretty-code
    rehypePlugins: (v) => [rehypeKatex, ...v],

Add Stylesheet

In order to make it looks great on the client, add the following to root layout:

import 'katex/dist/katex.css';


Type some TeX expression in your documents

c = \pm\sqrt{a^2 + b^2}
c=±a2+b2c = \pm\sqrt{a^2 + b^2}

Long equations example

Tf(z)=k=0(zc)k2πiγf(w)(wc)k+1dw=12πiγf(w)wck=0(zcwc)kdw=12πiγf(w)wc(11zcwc)dw=12πiγf(w)wzdw=f(z),\displaystyle {\begin{aligned}T_{f}(z)&=\sum _{k=0}^{\infty }{\frac {(z-c)^{k}}{2\pi i}}\int _{\gamma }{\frac {f(w)}{(w-c)^{k+1}}}\,dw\\&={\frac {1}{2\pi i}}\int _{\gamma }{\frac {f(w)}{w-c}}\sum _{k=0}^{\infty }\left({\frac {z-c}{w-c}}\right)^{k}\,dw\\&={\frac {1}{2\pi i}}\int _{\gamma }{\frac {f(w)}{w-c}}\left({\frac {1}{1-{\frac {z-c}{w-c}}}}\right)\,dw\\&={\frac {1}{2\pi i}}\int _{\gamma }{\frac {f(w)}{w-z}}\,dw=f(z),\end{aligned}}

Last updated on

On this page

Edit on Github