General LaTeX Mathematical Formula Grammar Handbook

MathJax is an open-source JavaScript mathematical symbol rendering engine that runs in web browsers. Through it, mathematical formulas can be easily displayed in modern web browsers. Currently, it can parse markup languages such as LaTex and MathML.

MathJax 是一款运行于 Web 浏览器当中的开源 JavaScript 数学符号渲染引擎,通过它可以方便的在现代 Web 浏览器当中显示数学公式,目前已经能够解析 LaTexMathML 等标记语言。MathJax 项目发源于 2009 年,目前由 NumFOCUS 基金会主持,并且得到了 MathJax 联盟的支持,该联盟是美国数学协会(AMS)和 工业与应用数学协会(SIAM)的共同合资企业。

LaTeX 是一种高质量的排版格式,可以生成复杂的表格与数学公式,是当前电子与数学出版行业的事实标准。本文以 Pandoc 作为 LaTex 渲染引擎(一款用于标记语言文档转换的命令行工具),分门别类的总结了撰写数学公式所需要经常使用到的 LaTeX 语法,方便写作相关科技类文章时随手查阅。

保留字符

LaTeX 环境中具有特殊含义的保留字符,不能直接使用,必须通过指定的语法实现:

序号 符号 LaTeX 序号 符号 LaTeX
1 (#) # 6 ({) {
2 (%) % 7 (}) }
3 (^) ^ 8 ()
4 (&) & 9 ()
5 (_) _

希腊字母

序号 标准符号 LaTeX 首字母大写 LaTeX 使用 var 前缀 LaTeX 读音
1 ()         /ˈælfə/
2 ()         /ˈbeɪtə/
3 () () () /ˈɡæmə/
4 () () () /ˈdɛltə/
5 ()     () /ˈɛpsɪlɒn/
6 ()         /ˈzeɪtə/
7 ()         /ˈeɪtə/
8 () () ()、() /ˈθiːtə/
9 ()         /aɪˈoʊtə/
10 ()     () /ˈkæpə/
11 () () () /ˈlæmdə/
12 ()         /mjuː/
13 ()         /njuː/
14 () () () /zaɪ, ksaɪ/
15 (o) o (O) O     /ˈɒmɪkrɒn/
16 () () ()、() /paɪ/
17 ()     () /roʊ/
18 () () ()、() /ˈsɪɡmə/
19 ()         /taʊ, tɔː/
20 () () () /ˈʌpsɪlɒn/
21 () () ()、() /faɪ/
22 ()         /kaɪ/
23 () () () /psaɪ/
24 () () () /oʊˈmeɪɡə/
25 ()         /daɪ'gæmə/

希伯来字母

序号 符号 LaTeX 英文 序号 符号 LaTeX 英文
1 () aleph 3 () gimel
2 () beth 4 () daleth

二元运算符

序号 符号 LaTeX 序号 符号 LaTeX
1 (+) + 20 ()
2 (-) - 21 ()
3 () 22 ()
4 () 23 ()
5 () 24 ()
6 () 25 ()
7 () 26 ()
8 () 27 ()
9 () 28 ()
10 () 29 ()
11 () 30 ()
12 () 31 ()
13 () 32 ()
14 () 33 ()
15 () 34 ()
16 () 35 ()
17 () 36 ()
18 () 37 ()
19 () 38 ()

二元关系符

序号 符号 LaTeX 序号 符号 LaTeX
1 (=) = 49 ()
2 () 50 ()
3 () 51 ()
4 () 52 ()
5 () 53 ()
6 () 54 ()
7 () 55 ()
8 () 56 ()
9 (:=) := 57 ()
10 () 58 ()
11 () 59 ()
12 () 60 ()
13 () 61 ()
14 () 62 ()
15 () 63 ()
16 () 64 ()
17 () 65 ()
18 () 66 ()
19 () 67 ()
20 () 68 ()
21 () 69 ()
22 () 70 ()
23 () 71 ()
24 () 72 ()
25 (<) < 73 ()
26 () 74 ()
27 () 75 ()
28 () 76 ()
29 () 77 ()
30 () 78 ()
31 () 79 ()
32 (>) > 80 ()
33 () 81 ()
34 () 82 ()
35 () 83 ()
36 () 84 ()
37 () 85 ()
38 () 86 ()
39 () 87 ()
40 () 88 ()
41 () 89 ()
42 () 90 ()
43 () 91 ()
44 () 92 ()
45 () 93 ()
46 () 94 ()
47 () 95 ()
48 () 96 ()

几何符号

序号 符号 LaTeX 序号 符号 LaTeX
1 () 14 ()
2 () 15 ()
3 () 16 ()
4 () 17 ()
5 () 18 ()
6 () 19 ()
7 () 20 ()
8 () 21 ()
9 (45^) 45^ 22 ()
10 () 23 ()
11 () 24 ()
12 () 25 ()
13 () 26 ()

逻辑符号

序号 符号 LaTeX 序号 符号 LaTeX
1 () 20 ()
2 () 21 ()
3 () 22 ()
4 () 23 ()
5 () 24 ()
6 () 25 ()
7 () 26 ()
8 () 27 ()
9 () 28 ()
10 () 29 ()
11 () 30 ()
12 () 31 ()
13 () 32 ()
14 () 33 ()
15 ({q}) {q} 34 ()
16 ({abc}) {abc} 35 ()
17 () 36 ()
18 () 37 ()
19 ()

集合符号

序号 符号 LaTeX 序号 符号 LaTeX
1 ({}) { } 23 ()
2 () 24 ()
3 () 25 ()
4 () 26 ()
5 () 27 ()
6 () 28 ()
7 () 29 ()
8 () 30 ()
9 () 31 ()
10 () 32 ()
11 () 33 ()
12 () 34 ()
13 () 35 ()
14 () 36 ()
15 () 37 ()
16 () 38 ()
17 () 39 ()
18 () 40 ()
19 () 41 ()
20 () 42 ()
21 () 43 ()
22 () 44 ()

箭头符号

序号 符号 LaTeX 序号 符号 LaTeX
1 () 36 ()
2 () 37 ()
3 () 38 ()
4 () 39 ()
5 () 40 ()
6 () 41 ()
7 () 42 ()
8 () 43 ()
9 () 44 ()
10 () 45 ()
11 () 46 ()
12 () 47 ()
13 () 48 ()
14 () 49 ()
15 () 50 ()
16 () 51 ()
17 () 52 ()
18 () 53 ()
19 () 54 ()
20 () 55 ()
21 () 56 ()
22 () 57 ()
23 () 58 ()
24 () 59 ()
25 () 60 ()
26 () 61 ()
27 () 62 ()
28 () 63 ()
29 () 64 ()
30 () 65 ()
31 () 66 ()
32 () 67 ()
33 () 68 ()
34 () 69 ()
35 ()

特殊符号

序号 符号 LaTeX 序号 符号 LaTeX
1 () 33 ()
2 () 34 ()
3 () 35 ()
4 () 36 ()
5 () 37 ()
6 () 38 ()
7 () 39 ()
8 () 40 ()
9 () 41 ()
10 () 42 ()
11 () 43 ()
12 () 44 ()
13 () 45 ()
14 () 46 ()
15 () 47 ()
16 () 48 ()
17 () 49 ()
18 (%) % 50 ()
19 () 51 ()
20 () 52 ()
21 () 53 ()
22 () 54 ()
23 () 55 ()
24 () 56 ()
25 () 57 ()
26 () 58 ()
27 () 59 ()
28 () 60 ()
29 () 61 ()
30 () 62 ()
31 () 63 ()
32 () 64 ()

分数

类型 符号 LaTeX
分数 (x=0.5x or {2 }x=0.5x) x=0.5x or {2 }x=0.5x
小型分数 (x = 0.5x) x = 0.5x
大型分数
(不嵌套)
( = 0.5 = a) = 0.5 = a
大型分数
(嵌套)
( = a) = a

数值函数

符号 LaTeX
(_a b = a^b, b = e^b, 10^m) _a b = a^b, b = e^b, 10^m
(c, d = e, _{10} f) c, d = e, _{10} f
(a, b, c, d, e, f) a, b, c, d, e, f
(a, b, c) a, b, c
( d, e, f) d, e, f
(a, b, c, d) a, b, c, d
(k, l, m, n) k, l, m, n
(o, p, q) o, p, q
(r, s ) r, s
((x,y), (x,y)) (x,y), (x,y)

如果需要使用特殊的函数符号,那么可以采用 \operatorname{} 命令进行自定义:

符号 LaTeX
(x) x

根式

符号 LaTeX 符号 LaTeX
() ()
() () *_

微分与导数

符号 LaTeX
(dt, t, t, ) dt, t, t,
(dy/dx, y/x, , , y) dy/dx, y/x, , , y
(, , f^, f', f'', f^{(3)}, y, y) , , f^, f', f'', f^{(3)}, y, y

模运算

符号 LaTeX
(s_k ) s_k
(a b) a b
((m, n), (m, n)) (m, n), (m, n)
(, , , ) , , ,

极限

符号 LaTeX
(_{n }x_n) _{n }x_n
(_{n }x_n) _{n }x_n

范围与预测

符号 LaTeX
(x, y, s, t) x, y, s, t
(u, v, w) u, v, w
(p, q, m, ) p, q, m,
(j, l, z , z) j, l, z , z

积分

符号 LaTeX
(_{1}^{3}, dx) _{1}^{3}, dx
(_{1}^{3}, dx) _{1}^{3}, dx
(_{-N}^{N} e^x dx) _{-N}^{N} e^x dx
(_{-N}^{N} e^x dx) _{-N}^{N} e^x dx
(_D dx,dy) _D dx,dy
(_E dx,dy,dz) _E dx,dy,dz
(_F dx,dy,dz,dt) _F dx,dy,dz,dt
(_{(x,y)C} x^3, dx + 4y^2,dy) _{(x,y)C} x^3, dx + 4y^2, dy
(_{(x,y)C} x^3, dx + 4y^2,dy) _{(x,y)C} x^3, dx + 4y^2, dy

注意:积分符号采用 \int\_{}^{} 命令调用,双重积分符号采用 \iint\_{}^{},以此类推,最高可以支持四重积分。

曲线积分可以使用 \oint 命令调用,但是 MathJax 并不支持该语法,因此在开启了 Unicode 扩展的前提下,可以改为采用 \unicode{} 命令调用:

符号 LaTeX 描述
( _C) _C 曲面积分符号的 Unicode 码十进制为 8751, 十六进制为 x222F
( _C) _C 三维曲面积分符号的 Unicode 码十进制为 8752, 十六进制为 x2230
( _c _c _c) _c _c _c 其它积分符号;

大型运算符

分类 符号 LaTeX 符号 LaTeX
求和 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}
连乘积 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}
余积 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}
并集 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}
交集 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}
析取 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}
合取 (_{a}^{b}) _{a}^{b} (_{a}^{b}) _{a}^{b}

上下标

类型 符号 代码
上标 (a2)
(a
{x+3})
a2
a{x+3}
下标 (a_2) a_2
组合 (10^{30} a^{2+2})
(a{i,j} b{f'})
10^{30} a^{2+2}
a{i,j} b{f'}
上下标混合 (x_23)
({x_2}
3)
x_23
{x_2}3
上标的上标 (10{10{8}}) 10{10{8}}
混合标识 (X_a^b)
({}_1^2!_3^4)
X_a^b
{}_1^2!_3^4
顶标底标 ()
()
()
()



导数 (x', y'', f', f'') (x^, y^{}) x', y'', f', f'' x^, y^{}
导数点 (, ) ,
上下划线与向量 (a  b  c)
(    )
(  )
a  b  c
   
 
弧度 ( {AB}) {AB}
箭头 (A B C) A B C
大括号 (^{5050}) ^{5050}
底部大括号 (_{26}) _{26}
求和运算 (_{k=1}^N k^2) _{k=1}^N k^2
文本模式下的求和运算 (_{k=1}^N k^2) _{k=1}^N k^2
分式中的求和运算 ()
分式中的求和运算 ()
分式中的求和运算 ()
乘积运算 (_{i=1}^N x_i) _{i=1}^N x_i
乘积运算 (_{i=1}^N x_i) _{i=1}^N x_i
副乘运算 (_{i=1}^N x_i) _{i=1}^N x_i
副乘运算 (_{i=1}^N x_i) _{i=1}^N x_i
极限 (_{n }x_n) _{n }x_n
极限 (_{n }x_n) _{n }x_n
积分 (_{1}^{3}, dx) _{1}^{3}, dx
积分 (_{1}^{3}, dx) _{1}^{3}, dx
积分 (_{-N}^{N} e^x dx) _{-N}^{N} e^x dx
积分 (_{-N}^{N} e^x dx) _{-N}^{N} e^x dx
双重积分 (_D dx,dy) _D dx,dy
三重积分 (_E dx,dy,dz) _E dx,dy,dz
四重积分 (_F dx,dy,dz,dt) _F dx,dy,dz,dt
路径积分 (_{(x,y)C} x^3, dx + 4y^2, dy) _{(x,y)C} x^3, dx + 4y^2, dy
环路积分 (_{(x,y)C} x^3, dx + 4y^2, dy) _{(x,y)C} x^3, dx + 4y^2, dy
交集 (_{i=1}^n E_i) _{i=1}^n E_i
并集 (_{i=1}^n E_i) _{i=1}^n E_i

二项式系数

类型 符号 LaTeX
二项式系数 ()
小型二项式系数 ()
大型二项式系数 ()

矩阵

符号 LaTeX
[ \[\begin{matrix} x &amp; y \\ z &amp; v \end{matrix}\] ]
\begin{matrix}
x & y \\
z & v
\end{matrix}
[ \[\begin{vmatrix} x &amp; y \\ z &amp; v \end{vmatrix}\] ]
\begin{vmatrix}
x & y \\
z & v
\end{vmatrix}
[ \[\begin{Vmatrix} x &amp; y \\ z &amp; v \end{Vmatrix}\] ]
\begin{Vmatrix}
x & y \\
z & v
\end{Vmatrix}
[ \[\begin{bmatrix} 0 &amp; \cdots &amp; 0 \\ \vdots &amp; \ddots &amp; \vdots \\ 0 &amp; \cdots &amp; 0 \end{bmatrix}\] ]
\begin{bmatrix}
0 & \cdots & 0 \\
\vdots & \ddots & \vdots \\
0 & \cdots & 0
\end{bmatrix}
[ \[\begin{Bmatrix} x &amp; y \\ z &amp; v \end{Bmatrix}\] ]
\begin{Bmatrix}
x & y \\
z & v
\end{Bmatrix}
[ \[\begin{pmatrix} x &amp; y \\ z &amp; v \end{pmatrix}\] ]
\begin{pmatrix}
x & y \\
z & v
\end{pmatrix}
[( \[\begin{smallmatrix} a&amp;b\\ c&amp;d \end{smallmatrix}\] ) ]
\bigl( \begin{smallmatrix}
a&b\\
c&d
\end{smallmatrix} \bigr)

数组

\begin{array}{ | c | c | c | }
a & b & S \\
\hline
0 & 0 & 1 \\
0 & 1 & 1 \\
1 & 0 & 1 \\
1 & 1 & 0
\end{array}

方程与方程组

\begin{cases}
3x + 5y + z \\
7x - 2y + 4z \\
-6x + 3y + 2z
\end{cases}

条件定义

f(n) =
\begin{cases}
n/2, & \text{if }n\text{ is even} \\
3n+1, & \text{if }n\text{ is odd}
\end{cases}

多行等式

符号 LaTeX
[\[\begin{align} f(x) &amp; = (a+b)^2\\ &amp; = a^2+2ab+b^2 \end{align}\] ]
\begin{align}
f(x) & = (a+b)^2\\
& = a^2+2ab+b^2
\end{align}
[\[\begin{alignat}{2} f(x) &amp; = (a-b)^2 \\ &amp; = a^2-2ab+b^2 \end{alignat}\] ]
\begin{alignat}{2}
f(x) & = (a-b)^2 \\
& = a^2-2ab+b^2
\end{alignat}
[ \[\begin{array}{lcl} z &amp; = &amp; a \\ f(x,y,z) &amp; = &amp; x + y + z \end{array}\] ]
\begin{array}{lcl}
z & = & a \\
f(x,y,z) & = & x + y + z
\end{array}
[ \[\begin{array}{lcr} z &amp; = &amp; a \\ f(x,y,z) &amp; = &amp; x + y + z \end{array}\] ]
\begin{array}{lcr}
z & = & a \\
f(x,y,z) & = & x + y + z
\end{array}

自动编号

描述 符号 LaTeX
开启 AMS 扩展包的情况下,会在部分环境的多行公式后自动编号; [\[\begin{eqnarray} E = mc^2 \\ e^{i\pi}+1=0 \end{eqnarray}\] ]
\begin{eqnarray}
E = mc^2 \\
e^{i\pi}+1=0
\end{eqnarray}
整个公式都不进行编号,可以使用 {equation}{eqnarray} 环境; [\[\begin{eqnarray*} E = mc^2 \\ e^{i\pi}+1=0 \end{eqnarray*}\] ]
\begin{eqnarray*}
E = mc^2 \\
e^{i\pi}+1=0
\end{eqnarray*}
单个方程不进行编号,可以在指定方程后面添加命令; [\[\begin{eqnarray} E = mc^2 \\ e^{i\pi}+1=0 \nonumber \end{eqnarray}\] ]
\begin{eqnarray}
E = mc^2 \\
e^{i\pi}+1=0 \nonumber
\end{eqnarray}
个别公式出现或者不出现编号,可以在公式后使用或者命令; [\[\begin{eqnarray} E = mc^2 \notag\\ e^{i\pi}+1=0 \tag{b} \end{eqnarray}\] ]
\begin{eqnarray}
E = mc^2 \notag\\
e^{i\pi}+1=0 \tag{b}
\end{eqnarray}

括号

常用的 ()[]{} 括号符号可以在 LaTeX 环境当中直接进行使用,但是如果处于较大的符号当中,就应该配合 \left\right 命令来使用:

类型 符号 LaTeX
圆括号、小括号 (( )) ( )
方括号、中括号 ()
( )

花括号、大括号 ({ })
( )
{ }
角括号 ( )
单竖线和双竖线 ( )
( )

取整函数与取顶函数 ( )
( )

斜线与反斜线 (/ ) /
上下箭头 ( )
( )
( )


混合括号 (] ] ] ]) ( ( ( ( ( ] ] ] ] ]
({ { { { { ) { { { { {
()
()
()
()
(/ / / / / ) / / / / /

空格与换行

序号 符号 LaTeX
双空格 (a b) a b
单空格 (a b) a b
字符空格 (a b) a b
文本模式中的字符空格 (a b) a b
大空格 (a;b) a;b
小空格 (a,b) a,b
极小空格 (ab) ab
极小空格(用于区分语法) (a b) a b
无空格(用于区分多字母变量) ()

MathJax 3.0 取消了单行公式环境下 \\ 的强制换行功能,因此强制换行命令 \\ 仅能用于 eqnarrayalignarraymatrix 等多行环境当中。除此之外,还可以在 \displaylines{} 行显示命令当中使用 \\ 强制换行命令:

符号 LaTeX
()

颜色

编写 LaTeX 的时候,支持将文本符号或者背景设置为下面表格当中的各种颜色:

() - Apricot () - Emerald () - OliveGreen () - RubineRed
() - Aquamarine () - ForestGreen () - Orange () - Salmon
() - Bittersweet () - Fuchsia () - OrangeRed () - SeaGreen
() - Black () - Goldenrod () - Orchid () - Sepia
() - Blue () - Gray () - Peach () - SkyBlue
() - BlueGreen () - Green () - Periwinkle () - SpringGreen
() - Blueviolet () - GreenYellow () - PineGreen () - Tan
() - BrickRed () - JungleGreen () - Plum () - TealBlue
() - Brown () - Lavender () - ProcessBlue () - Thistle
() - BurntOrange () - LimeGreen () - Purple () - Turquoise
() - CadetBlue () - Magenta () - RawSienna () - Violet
() - CarnationPink () - Mahogany () - Red () - VioletRed
() - CornFlowerBlue () - Melon () - Redviolet () - WildStrawberry
() - Cerulean () - Maroon () - RedOrange () - white
() - Cyan () - MidnightBlue () - Rhodamine () - Yellow
() - Dandelion () - Mulberry () - RoyalBlue () - YellowGreen
() - DarkOrchid () - NavyBlue () - RoyalPurple () - YellowOrange

字体颜色

公式当中可以使用 {\color{hues}text} 调用颜色命令,其中 hues 参数为字体颜色,而 text 参数是公式内容

符号 LaTeX
({x^2}+{2x}-{1}) {x^2}+{2x}-{1}

背景颜色

文本环境中可以使用 \colorbox{hues}{text} 来调用背景颜色命令,其中 hues 参数为背景颜色,而 text 参数是公式内容

符号 LaTeX
()

该命令应用于数学环境当中时,需要在第 2 个参数加入 $\displaystyle + 公式$

符号 LaTeX
[ ]

注意:在 Markdown 内联 LaTeX 公式 $...$ 当中使用 $\displaystyle + 公式$ 语法时将会引发冲突,因此该语法仅用于多行公式 $$...$$

RGB 颜色

通过使用 \definecolor 命令可以自定义 LaTeX 公式的颜色:

符号 LaTeX
( {e^{i } + 1 = 0 }) {e^{i } + 1 = 0 }

字体

字体加粗

符号 LaTeX
()
()
()

黑体

符号 LaTeX
()
()
()

黑板报体

符号 LaTeX
()
()
()

斜体

符号 LaTeX
()
()
()

罗马体

符号 LaTeX
()
()
()

无衬线体

符号 LaTeX
()
()
()

手写体

符号 LaTeX
()
()
()

哥特字体

符号 LaTeX
()
()
()

小脚本风格

符号 LaTeX
({}) {}
({}) {}
({}) {}

字号尺寸

符号 LaTeX
({abc 极小 tiny}) {abc极小tiny}
({abc 超小 scriptsize}) {abc 超小 scriptsize}
({abc 小 small}) {abc 小 small}
({abc 正常 normal}) {abc 正常 normal}
({abc 大 large}) {abc 大 large}
({abc 超大 Large}) {abc 超大 Large}
({abc 特大 LARGE}) {abc 特大 LARGE}
({abc 巨大 huge}) {abc 巨大 huge}s
({abc 巨无霸 Huge}) {abc 巨无霸 Huge}

通用 LaTeX 数学公式语法手册