本文最后更新于 197 天前 ,文中信息可能已经过时。如有问题请在评论区留言。
温馨提示
本文采用 KaTex 渲染数学公式。

基本语法

Markdown 数学公式:使用 $

内联显示将数学公式写在 $...$ 之间。块显示则将数学公式写在 $$...$$ 之间。

常用符号

上下标

算式markdown
\$a_0\$, \$a_{pre}\$a_0, a_{pre}
\$a^0\$, \$a^{[0]}\$a^0, a^{[0]}

括号

算式markdown
\$(\$, \$)\$(, )
\$[\$, \$]\$[, ]
\$\lang\$, \$\rang\$\lang, \rang 或 \langle, \rangle
\$\lvert\$, \$\rvert\$\lvert, \rvert
\$\lVert\$, \$\rVert\$\lVert, \rVert
\$\lbrace\$, \$\rbrace\$\lbrace, \rbrace 或\{, \}

增大括号方法

算式markdown
\$(x)\$(x)
\$\big( x \big)\$\big( x \big)
\$\Big( x \Big)\$\Big( x \Big)
\$\bigg( x \bigg)\$\bigg( x \bigg)
\$\Bigg( x \Bigg)\$\Bigg( x \Bigg)

其他的大括号

算式markdown
\$\Bigg(\bigg(\Big(\big((x)\big)\Big)\bigg)\Bigg)\$\Bigg(\bigg(\Big(\big((x)\big)\Big)\bigg)\Bigg)
\$\Bigg[\bigg[\Big[\big[[x]\big]\Big]\bigg]\Bigg]\$\Bigg[\bigg[\Big[\big[[x]\big]\Big]\bigg]\Bigg]
\$\Bigg \langle \bigg \langle \Big \langle\big\langle\langle x \rangle \big \rangle\Big\rangle\bigg\rangle\Bigg\rangle\$\Bigg \langle \bigg \langle \Big \langle\big\langle\langle x \rangle \big \rangle\Big\rangle\bigg\rangle\Bigg\rangle
\$\Bigg\lvert\bigg\lvert\Big\lvert\big\lvert\lvert x \rvert\big\rvert\Big\rvert\bigg\rvert\Bigg\rvert\$\Bigg\lvert\bigg\lvert\Big\lvert\big\lvert\lvert x \rvert\big\rvert\Big\rvert\bigg\rvert\Bigg\rvert
\$\Bigg\lVert\bigg\lVert\Big\lVert\big\lVert\lVert x \rVert\big\rVert\Big\rVert\bigg\rVert\Bigg\rVert\$\Bigg\lVert\bigg\lVert\Big\lVert\big\lVert\lVert x \rVert\big\rVert\Big\rVert\bigg\rVert\Bigg\rVert

分数

算式markdown
\$\frac{a}{b}\$\frac{a}{b}

开方

算式markdown
\$\sqrt{a + b}\$\sqrt{a + b}
\$\sqrt[n]{a + b}\$\sqrt[n]{a + b}

累加/累乘

算式markdown
\$\sum_{i = 0}^{n}\frac{1}{i^2}\$\sum_{i = 0}{n}\frac{1}{i2}
\$\prod_{i = 0}^{n}\frac{1}{x^2}\$\prod_{i = 0}{n}\frac{1}{x2}

三角函数

算式markdown
\$\sin\$\sin
\$\cos\$\cos
\$\tan\$\tan
\$\cot\$\cot
\$\sec\$\sec
\$\csc\$\csc
\$\bot\$\bot
\$\angle\$\angle
\$40^\circ\$40^\circ

对数函数

算式markdown
\$\ln{a + b}\$\ln{a + b}
\$\log_{a}^{b}\$\log_{a}^{b}
\$\lg{a + b}\$\lg{a + b}

二元运算符

算式markdown描述算式markdown描述
\$\pm\$\pm正负号\$\triangleleft\$\triangleleft
\$\mp\$\mp\$\triangleright\$\triangleright
\$\times\$\times乘号\$\lhd\$\lhd
\$\div\$\div除号\$\rhd\$\rhd
\$\ast\$\ast\$\unlhd\$\unlhd
\$\star\$\star\$\unrhd\$\unrhd
\$\mid\$\mid\$\bigcirc\$\bigcirc
\$\nmid\$\nmid\$\odot\$\odot
\$\circ\$\circ\$\bigodot\$\bigodot
\$\bullet\$\bullet\$\oslash\$\oslash
\$\cdot\$\cdot\$\ominus\$\ominus
\$\wr\$\wr\$\otimes\$\otimes
\$\diamond\$\diamond\$\bigotimes\$\bigotimes
\$\Diamond\$\Diamond\$\oplus\$\oplus
\$\triangle\$\triangle\$\bigoplus\$\bigoplus
\$\bigtriangleup\$\bigtriangleup\$\dagger\$\dagger
\$\bigtriangledown\$\bigtriangledown\$\ddagger\$\ddagger
\$\amalg\$\amalg

关系符号

算式markdown描述算式markdown描述
\$\leq\$\leq小于等于\$\models\$\models
\$\geq\$\geq大于等于\$\prec\$\prec
\$\equiv\$\equiv\$\succ\$\succ
\$\sim\$\sim\$\perp\$\perp
\$\preceq\$\preceq\$\succeq\$\succeq
\$\simeq\$\simeq\$\mid\$\mid
\$\ll\$\ll\$\gg\$\gg
\$\asymp\$\asymp\$\parallel\$\parallel
\$\approx\$\approx约等于\$\cong\$\cong
\$\neq\$\neq不等于\$\doteq\$\doteq
\$\propto\$\propto\$\bowtie\$\bowtie
\$\Join\$\Join\$\smile\$\smile
\$\frown\$\frown\$\vdash\$\vdash
\$\dashv\$\dashv

极限

算式markdown
\$\lim\$\lim
\$\rightarrow\$\rightarrow 或 \to
\$\infty\$\infty
\$\lim_{n \to +\infty}n\$\lim_{n \to +\infty}n

向量

算式markdown
\$\vec{a}\$\vec{a}

箭头

算式markdown描述算式markdown描述
\$\uparrow\$\uparrow\$\downarrow\$\downarrow
\$\updownarrow\$\updownarrow\$\Uparrow\$\Uparrow
\$\Downarrow\$\Downarrow\$\Updownarrow\$\Updownarrow
\$\rightarrow\$\rightarrow\$\leftarrow\$\leftarrow
\$\leftrightarrow\$\leftrightarrow\$\Rightarrow\$\Rightarrow
\$\Leftarrow\$\Leftarrow\$\Leftrightarrow\$\Leftrightarrow
\$\longrightarrow\$\longrightarrow\$\longleftarrow\$\longleftarrow
\$\longleftrightarrow\$\longleftrightarrow\$\Longrightarrow\$\Longrightarrow
\$\Longleftarrow\$\Longleftarrow\$\Longleftrightarrow\$\Longleftrightarrow
\$\mapsto\$\mapsto\$\longmapsto\$\longmapsto
\$\hookleftarrow\$\hookleftarrow\$\hookrightarrow\$\hookrightarrow
\$\rightharpoonup\$\rightharpoonup\$\leftharpoondown\$\leftharpoondown
\$\rightleftharpoons\$\rightleftharpoons\$\leftharpoonup\$\leftharpoonup
\$\rightharpoondown\$\rightharpoondown\$\leadsto\$\leadsto
\$\nearrow\$\nearrow\$\searrow\$\searrow
\$\swarrow\$\swarrow\$\nwarrow\$\nwarrow

集合

算式markdown描述算式markdown描述
\$\emptyset\$\emptyset\$\in\$\in
\$\ni\$\ni\$\notin\$\notin
\$\subset\$\subset\$\supset\$\supset
\$\not\subset\$\not\subset\$\subseteq\$\subseteq
\$\supseteq\$\supseteq\$\cup\$\cup
\$\bigcup\$\bigcup\$\cap\$\cap
\$\bigcap\$\bigcap\$\uplus\$\uplus
\$\biguplus\$\biguplus\$\sqsubset\$\sqsubset
\$\sqsupset\$\sqsupset\$\sqcap\$\sqcap
\$\sqsubseteq\$\sqsubseteq\$\sqsupseteq\$\sqsupseteq
\$\vee\$\vee\$\wedge\$\wedge
\$\setminus\$\setminus

微积分

算式markdown
\$\prime\$\prime
\$\int\$\int
\$\iint\$\iint
\$\iiint\$\iiint
\$\oint\$\oint
\$\nabla\$\nabla
\$\int_0^2 x^2 dx\$\int_0^2 x^2 dx

逻辑运算

算式markdown
\$\because\$\because
\$\therefore\$\therefore
\$\forall\$\forall
\$\exist\$\exist
\$\vee\$\vee
\$\wedge\$\wedge
\$\bigvee\$\bigvee
\$\bigwedge\$\bigwedge

上下标符号

算式markdown
\$\bar{a}\$\bar{a}
\$\acute{a}\$\acute{a}
\$\breve{a}\$\breve{a}
\$\grave{a}\$\grave{a}
\$\dot{a}\$\dot{a}
\$\ddot{a}\$\ddot{a}
\$\hat{a}\$\hat{a}
\$\check{a}\$\check{a}
\$\breve{a}\$\breve{a}
\$\tilde{a}\$\tilde{a}
\$\vec{a}\$\vec{a}
\$\overline{a + b + c + d}\$\overline{a + b + c + d}
\$\underline{a + b + c + d}\$\underline{a + b + c + d}
\$\overbrace{a + b + c + d}\$\overbrace{a + b + c + d}
\$\underbrace{a + b + c + d}\$\underbrace{a + b + c + d}
\$\overbrace{a + \underbrace{b + c}_{1.0} + d}^{2.0}\$\overbrace{a + \underbrace{b + c}_{1.0} + d}^{2.0}

希腊字母

大写markdown小写markdown
\$\Alpha\$\Alpha\$\alpha\$\alpha
\$\Beta\$\Beta\$\beta\$\beta
\$\Gamma\$\Gamma\$\gamma\$\gamma
\$\Delta\$\Delta\$\delta\$\delta
\$\Epsilon\$\Epsilon\$\epsilon\$\epsilon
\$\varepsilon\$\varepsilon
\$\Zeta\$\Zeta\$\zeta\$\zeta
\$\Eta\$\Eta\$\eta\$\eta
\$\Theta\$\Theta\$\theta\$\theta
\$\Iota\$\Iota\$\iota\$\iota
\$\Kappa\$\Kappa\$\kappa\$\kappa
\$\Lambda\$\Lambda\$\lambda\$\lambda
\$\Mu\$\Mu\$\mu\$\mu
\$\Nu\$\Nu\$\nu\$\nu
\$\Xi\$\Xi\$\xi\$\xi
\$\Omicron\$\Omicron\$\omicron\$\omicron
\$\Pi\$\Pi\$\pi\$\pi
\$\Rho\$\Rho\$\rho\$\rho
\$\Sigma\$\Sigma\$\sigma\$\sigma
\$\Tau\$\Tau\$\tau\$\tau
\$\Upsilon\$\Upsilon\$\upsilon\$\upsilon
\$\Phi\$\Phi\$\phi\$\phi
\$\varphi\$\varphi
\$\Chi\$\Chi\$\chi\$\chi
\$\Psi\$\Psi\$\psi\$\psi
\$\Omega\$\Omega\$\omega\$\omega

省略号

算式markdown
\$\dots\$\dots
\$\ldots\$\ldots
\$\cdots\$\cdots
\$\vdots\$\vdots
\$\ddots\$\ddots

例子如下:

markdown
1
2
3
$$
x_1, x_2, \dots, x_n \quad \quad 1, 2, \cdots, n \quad \quad \vdots \quad \quad \ddots
$$
$$ x_1, x_2, \dots, x_n \quad \quad 1, 2, \cdots, n \quad \quad \vdots \quad \quad \ddots $$

空格

算式markdown描述
\$123\!123\$123\!123空格距离:-3/18 em
\$123\,123\$123\,123空格距离:3/18 em
\$123\:123\$123\:123空格距离:4/18 em
\$123\ 123\$123\;123 or 123\ 123空格距离:5/18 em
\$123\quad123\$123\quad123空格距离:1 em
\$123\qquad123\$123\qquad123空格距离:2 em

上表中的 em 是指当前文本中文本的字体尺寸

其他符号

算式markdown算式markdown算式markdown
\$\aleph\$\aleph\$\hbar\$\hbar\$\imath\$\imath
\$\jmath\$\jmath\$\ell\$\ell\$\wp\$\wp
\$\Re\$\Re\$\Im\$\Im\$\mho\$\mho
\$\nabla\$\nabla\$\surd\$\surd\$\top\$\top
\$\bot\$\bot\$\neg\$\neg\$\flat\$\flat
\$\natural\$\natural\$\sharp\$\sharp\$\backslash\$\backslash
\$\partial\$\partial\$\Box\$\Box\$\clubsuit\$\clubsuit
\$\diamondsuit\$\diamondsuit\$\heartsuit\$\heartsuit\$\spadesuit\$\spadesuit
\$\lceil\$\lceil\$\rceil\$\rceil\$\lfloor\$\lfloor
\$\rfloor\$\rfloor

公式

分支公式

markdown
1
2
3
4
5
6
7
8
$$
y=
\begin{cases}
-x,\quad x\leq 0\\
x, \quad x>0
\end{cases}
\tag{1}
$$
$$ y= \begin{cases} -x,\quad x\leq 0\\ x, \quad x>0 \end{cases} \tag{1} $$

矩阵

不带括号

markdown
1
2
3
4
5
6
7
8
$$
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\tag{1}
$$
$$ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \tag{1} $$

括号

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$$
\left(
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\right)
\tag{2}
$$
$$ \left( \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right) \tag{2} $$

中括号

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$$
\left[
\begin{matrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{matrix}
\right]
\tag{3}
$$
$$ \left[ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right] \tag{3} $$

大括号

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$$
\left\{
	\begin{matrix}
	1 & 2 & 3 \\
	4 & 5 & 6 \\
	7 & 8 & 9
	\end{matrix}
\right\}
\tag{4}
$$
$$ \left\{ \begin{matrix} 1 & 2 & 3\\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right\} \tag{4} $$

带省略号

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$$
\left\{
\begin{matrix}
a & a & \cdots & a \\
b & b & \cdots & b \\
\vdots & \vdots & \ddots & \vdots \\
c & c & \cdots & c
\end{matrix}
\right\}
\tag{5}
$$
$$ \left\{ \begin{matrix} a & a & \cdots & a\\ b & b & \cdots & b \\ \vdots & \vdots & \ddots & \vdots \\ c & c & \cdots & c \end{matrix} \right\} \tag{5} $$

带竖线分割的矩阵

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$$
\left[
	\begin{array}{c|cc}
	1 & 2 & 3 \\
	4 & 5 & 6 \\
	7 & 8 & 9
	\end{array}
\right]
\tag{7}
$$
$$ \left[ \begin{array}{c|cc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right] \tag{6} $$

带横线分割的矩阵

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$$
\left[
	\begin{matrix}
	1 & 2 & 3 \\ \hline
	4 & 5 & 6 \\
	7 & 8 & 9
	\end{matrix}
\right]
\tag{7}
$$
$$ \left[ \begin{matrix} 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right] \tag{7} $$

同时带横线和竖线的矩阵

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$$
\left[
	\begin{array}{c|cc}
	1 & 2 & 3 \\ \hline
	4 & 5 & 6 \\
	7 & 8 & 9
	\end{array}
\right]
\tag{8}
$$
$$ \left[ \begin{array}{c|cc} 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right] \tag{8} $$

字符的大小、位置和颜色

调整大小

调整大小时,只需在公式之前添加相应的标识,如 \Large

markdown
1
2
3
$$
\Large E=mc^2
$$
$$ \Large E=mc^2 $$
示例标识
\$\Huge E=mc^2\$\Huge
\$\huge E=mc^2\$\huge
\$\LARGE E=mc^2\$\LARGE
\$\Large E=mc^2\$\Large
\$\large E=mc^2\$\large
\$\normalsize E=mc^2\$\normalsize (default)
\$\small E=mc^2\$\small
\$\footnotesize E=mc^2\$\footnotesize
\$\scriptsize E=mc^2\$\scriptsize
\$\tiny E=mc^2\$\tiny

粗体斜体

编码字体效果
\rm罗马体\$\rm E=mc^2\$
\it意大利体(默认)\$\it E=mc^2\$
\bf粗体\$\bf E=mc^2\$
\boldsymbol黑体\$\boldsymbol E=mc^2\$
\Bbb黑板粗体\$\Bbb E=mc^2\$

换行 居中

使用 \\,对齐使用 align

markdown
1
2
3
4
5
6
7
$$
\begin{align}
x^2-8 & = 2x \\
x^2-2x+1 & = 9 \\
(x-1)^2 & = (\pm3)^2
\end{align}
$$
$$ \begin{align} x^2-8 & = 2x \\ x^2-2x+1 & = 9 \\ (x-1)^2 & = (\pm3)^2 \end{align} $$

若提示 KaTeX parse error: No such environment: align at position .... 错误,可尝试使用 aligned

其他环境:

环境名称描述
align最基本的对齐环境
multline非对齐环境
gather无对齐的连续方程

修改颜色

markdown
1
2
3
$$
P\left(x_{l} \mid y_{l}\right) = \frac{P(x_l,y_l)}{P(y_l)}=\frac{\textcolor{#FF0000}{P(y_l\mid x_l)}P(x_l)}{P(y_l)}
$$
$$ P\left(x_{l} \mid y_{l}\right) = \frac{P(x_l,y_l)}{P(y_l)}=\frac{\textcolor{#FF0000}{P(y_l\mid x_l)}P(x_l)}{P(y_l)} $$

常用颜色:

  • red:红色
  • green:绿色
  • blue:蓝色
  • yellow:黄色

花体字母

编码如下

markdown
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$\mathbb{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathcal{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathscr{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathrm{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathbf{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathit{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathsf{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathtt{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

$\mathfrak{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}$

效果依次如下

\$\mathbb{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathcal{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathscr{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathrm{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathbf{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathit{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathsf{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathtt{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

\$\mathfrak{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\$

参考