Math
Writing math equations in Markdown/MDX.
Getting Started
npm install remark-math rehype-katex katex
pnpm add remark-math rehype-katex katex
yarn add remark-math rehype-katex katex
bun add remark-math rehype-katex katex
Add Plugins
Add the required remark/rehype plugins, the code might be vary depending on your content source.
import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
import { defineConfig } from 'fumadocs-mdx/config';
export default defineConfig({
mdxOptions: {
remarkPlugins: [remarkMath],
// Place it at first, it should be executed before the syntax highlighter
rehypePlugins: (v) => [rehypeKatex, ...v],
},
});
Add Stylesheet
Add the following to root layout to make it looks great:
import 'katex/dist/katex.css';
Done
Type some TeX expression in your documents, like the Pythagoras theorem:
Inline: $$c = \pm\sqrt{a^2 + b^2}$$
```math
c = \pm\sqrt{a^2 + b^2}
```
Inline:
Taylor Expansion (expressing holomorphic function in power series):
Tip
You can actually copy equations on Wikipedia, they will be converted into a KaTeX string when you paste it.
How is this guide?
Last updated on