Fumadocs

数学

在 Markdown/MDX 中编写数学方程式。

入门

🌐 Getting Started

npm install remark-math rehype-katex katex

添加插件

🌐 Add Plugins

添加所需的 remark/rehype 插件,代码可能会根据你的内容来源有所不同。

🌐 Add the required remark/rehype plugins, the code might be vary depending on your content source.

source.config.ts
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:

layout.tsx
import 'katex/dist/katex.css';

完成

🌐 Done

在你的文档中输入一些 TeX 表达式,比如勾股定理:

🌐 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: c=±a2+b2c = \pm\sqrt{a^2 + b^2}

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

泰勒展开式(将全纯函数 f(x)f(x) 表示为幂级数):

🌐 Taylor Expansion (expressing holomorphic function f(x)f(x) in power series):

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}}

提示

你实际上可以从维基百科复制公式,粘贴时它们会被转换成 KaTeX 字符串。

S[q]=abL(t,q(t),q˙(t))dt.\displaystyle S[{\boldsymbol {q}}]=\int _{a}^{b}L(t,{\boldsymbol {q}}(t),{\dot {\boldsymbol {q}}}(t))\,dt.

Last updated on

On this page