markdown 数学公式语法
建议参考这三个官方资源。
Markdown 中的公式渲染支持方案分为两大阵营——MathJax和KaTeX。
对于较为常见的公式,两方渲染都一样。但是如果是一些不太常见的符号或者功能时,两方的语法就不一样了。使用前必须先确定你使用的 Markdown 工具正在使用的是哪个。
怎么确定?看工具的说明/帮助,或者直接深入安装文件夹中 node_modules 之类的地方翻一翻。在线的工具,只好按 F12 扒拉源代码。
确定了阵营之后,就要翻一下官家的说明文档,看各家对于数学符号和扩展功能的支持如何:
- MathJax:
Supported TeX/LaTeX commands — MathJax 3.2 documentation
The TeX/LaTeX Extension List — MathJax 3.2 documentation - KaTeX:
Supported Functions KaTeX
Extensions & Libraries KaTeX
可以看出,MathJax通过插件的形式支持 mhchem 包和其它一些符号,但有些符号需要手动配置加载扩展;KaTeX原生支持 mhchem 包以及较多的符号,但是官方没有提供更丰富的符号扩展。
参考知乎-知乎用户的回答
如何在MarkDown中使用LaTeX输入长等号
markdown里的公式分为行内公式和行间公式,
行内公式是$公式语法$
。诸如:\(y=hx+n\)
行间公式是$$公式语法$$
。诸如:$$y=hx+n$$
希腊字母表
名称 | code | 大写 | code | 小写 |
---|---|---|---|---|
alpha | \Alpha |
\(\Alpha\) | \alpha |
\(\alpha\) |
beta | \Beta |
\(\Beta\) | \beta |
\(\beta\) |
gamma | \Gamma |
\(\Gamma\) | \gamma |
\(\gamma\) |
delta | \Delta |
\(\Delta\) | \delta |
\(\delta\) |
epsilon | \Epsilon |
\(\Epsilon\) | \epsilon |
\(\epsilon\) |
zeta | \Zeta |
\(\Zeta\) | \zeta |
\(\zeta\) |
eta | \Eta$ |
\(\Eta\) | \eta |
\(\eta\) |
theta | \Theta |
\(\Theta\) | \theta |
\(\theta\) |
iota | \Iota |
\(\Iota\) | \iota |
\(\iota\) |
kappa | \Kappa |
\(\Kappa\) | \kappa |
\(\kappa\) |
lambda | \Lambda |
\(\Lambda\) | \lambda |
\(\lambda\) |
mu | \Mu |
\(\Mu\) | \mu |
\(\mu\) |
nu | \Nu |
\(\Nu\) | \nu |
\(\nu\) |
xi | \Xi |
\(\Xi\) | \xi |
\(\xi\) |
omicron | \Omicron |
\(\Omicron\) | \omicron |
\(\omicron\) |
pi | \Pi |
\(\Pi\) | \pi |
\(\pi\) |
rho | \Rho |
\(\Rho\) | \rho |
\(\rho\) |
sigma | \Sigma |
\(\Sigma\) | \sigma |
\(\sigma\) |
tau | \Tau |
\(\Tau\) | \tau |
\(\tau\) |
upsilon | \Upsilon$ |
\(\Upsilon\) | \upsilon |
\(\upsilon\) |
phi | \Phi |
\(\Phi\) | \phi |
\(\phi\) |
chi | \Chi |
\(\Chi\) | \chi |
\(\chi\) |
psi | \Psi |
\(\Psi\) | \psi |
\(\psi\) |
omega | \Omega |
\(\Omega\) | \omega |
\(\omega\) |
其他格式字体
-
装饰性字体 Caligraphic letters:
\mathcal{A}
etc.: \(\mathcal A \mathcal B \mathcal C \mathcal D \mathcal E \mathcal F \mathcal G \mathcal H \mathcal I \mathcal J \mathcal K \mathcal L \mathcal M \mathcal N \mathcal O \mathcal P \mathcal Q \mathcal R \mathcal S \mathcal T \mathcal U \mathcal V \mathcal W \mathcal X \mathcal Y \mathcal Z\) -
Mathbb letters:
\mathbb{A}
etc.: $\mathbb A \mathbb B \mathbb C \mathbb D \mathbb E \mathbb F \mathbb G \mathbb H \mathbb I \mathbb J \mathbb K \mathbb L \mathbb M \mathbb N \mathbb O \mathbb P \mathbb Q \mathbb R \mathbb S \mathbb T \mathbb U \mathbb V \mathbb W \mathbb X \mathbb Y \mathbb Z $ -
Mathfrak letters:
\mathfrak{A}
etc.: \(\mathfrak A \mathfrak B \mathfrak C \mathfrak D \mathfrak E \mathfrak F \mathfrak G \mathfrak H \mathfrak I \mathfrak J \mathfrak K \mathfrak L \mathfrak M \mathfrak N \mathfrak O \mathfrak P \mathfrak Q \mathfrak R \mathfrak S \mathfrak T \mathfrak U \mathfrak V \mathfrak W \mathfrak X \mathfrak Y \mathfrak Z \mathfrak 1 \mathfrak 2 \mathfrak 3 \mathfrak a \mathfrak b \mathfrak c\) -
Math Sans serif letters:
\mathsf{A}
etc.: \(\mathsf A \mathsf B \mathsf C \mathsf D \mathsf E \mathsf F \mathsf G \mathsf H \mathsf I \mathsf J \mathsf K \mathsf L \mathsf M \mathsf N \mathsf O \mathsf P \mathsf Q \mathsf R \mathsf S \mathsf T \mathsf U \mathsf V \mathsf W \mathsf X \mathsf Y \mathsf Z\) -
Math bold letters:
\mathbf{A}
etc.: $\mathbf A \mathbf B \mathbf C \mathbf D \mathbf E \mathbf F \mathbf G \mathbf H \mathbf I \mathbf J \mathbf K \mathbf L \mathbf M \mathbf N \mathbf O \mathbf P \mathbf Q \mathbf R \mathbf S \mathbf T \mathbf U \mathbf V \mathbf W \mathbf X \mathbf Y \mathbf Z $
标准函数名称
数学里一些函数比如sin,正确的打印字体应该是罗马字体并不是一般的字体
Function names should appear in Roman, not Italic, e.g.,
code | 示例 | code | 示例 | code | 示例 | code | 示例 |
---|---|---|---|---|---|---|---|
\arccos |
\(arccos\) | \arcsin |
\(\arcsin\) | \arctan |
\(\arctan\) | \arg |
\(\arg\) |
\cos |
\(cos\) | \cosh |
\(\cosh\) | \cot |
\(\cot\) | \coth |
\(\coth\) |
\csc |
\(csc\) | \deg |
\(\deg\) | \det |
\(\det\) | \dim |
\(\dim\) |
\exp |
\(exp\) | \gcd |
\(\gcd\) | \hom |
\(\hom\) | \inf |
\(\inf\) |
\ker |
\(ker\) | \lg |
\(\lg\) | \lim |
\(\lim\) | \liminf |
\(\liminf\) |
\limsup |
\(limsup\) | \ln |
\(\ln\) | \log |
\(\log\) | \max |
\(\max\) |
\min |
\(min\) | \Pr |
\(\Pr\) | \sec |
\(\sec\) | \sin |
\(\sin\) |
\sinh |
\(sinh\) | \sup |
\(\sup\) | \tan |
\(\tan\) | \tanh |
\(\tanh\) |
对齐
公式换行对齐
需要对齐的内容以\begin{align}
和\end{aligned}
包围,在需要对齐的符号(如等号)前加&
来标记,用\\
来换行。多隔对齐要素继续用&&
\begin{align}
KPI&=(N+S)W \\
&=NW+SW
\end{align}
\begin{align}
KPI&=N+&&SW \\
API&=&&SW
\end{align}
括号大小对齐
公式中经常出现括号,括号的大小要与相邻的公式相适应。
Use the pair \left s1 and \right s2 to match height of delimiters s1 and s2 to the height of their contents, e.g.,
\left( \frac {\partial f}{\partial x} \right)
上标
X^a
\(X^a\)
X^{3a}
\(X^{3a}\)
语法 | 示例 |
---|---|
\overline x |
\(\overline x\) |
\widehat x |
\(\widehat x\) |
\widetilde x |
\(\widetilde x\) |
\vec x |
\(\vec x\) |
\overrightarrow x |
\(\overrightarrow x\) |
\overleftarrow x |
\(\overleftarrow x\) |
\overbrace x |
\(\overbrace x\) |
下标
X_a
\(X_a\)
X_{3a}
\(X_{3a}\)
\underline x
\(\underline x\)
\underbrace x
\(\underbrace x\)
箭头上下标
A_{1} \stackrel{R_{1}}{\longrightarrow} A_{2} \stackrel{R_{2}}{\longrightarrow} \cdots \stackrel{R_{l}}{\longrightarrow} A_{l+1}
使用underset作为上下
\underset{a}{\arg \max}(-a^2)
定界符
语法 | 示例 |
---|---|
\vert |
\(\vert\) |
| |
\(|\) |
\Vert |
\(\Vert\) |
\{ |
\(\{\) |
\} |
\(\}\) |
\langle |
\(\langle\) |
\rangle |
\(\rangle\) |
\lfloor |
\(\lfloor\) |
\rfloor |
\(\rfloor\) |
\lceil |
\(\lceil\) |
\rceil |
\(\rceil\) |
/ |
\(/\) |
\backslash |
\(\backslash\) |
[ |
\([\) |
] |
\(]\) |
\Uparrow |
\(\Uparrow\) |
\uparrow |
\(\uparrow\) |
\Downarrow |
\(\Downarrow\) |
\downarrow |
\(\downarrow\) |
\llcorner |
\(\llcorner\) |
\lrcorner |
\(\lrcorner\) |
\ulcorner |
\(\ulcorner\) |
\urcorner |
\(\urcorner\) |
微分
语法 | 示例 |
---|---|
$\nabla$ |
\(\nabla {x}\) |
$\mathrm{d} x$ |
\(\mathrm{d} x\) |
$\dot y$ |
\(\dot y\) |
$\ddot {y}$ |
\(\ddot y\) |
$\partial x$ |
\(\partial x\) |
积分
\sum a_{ij}
\(\sum a_{ij}\)
\int a_{ij}
\(\int a_{ij}\)
\iint a_{ij}
\(\iint a_{ij}\)
\iiint a_{ij}
\(\iiint a_{ij}\)
开方
\sqrt x
\(\sqrt x\)
\sqrt[4] x
\(\sqrt[4] x\)
分式
- frac
\frac{abc}{xyz}
\(\frac{abc}{xyz}\) - over
x+y \over x-y
\(x+y \over x-y\) - cfrac用法与frac一样,但是公式会大一些
1 + \cfrac{x}{1+\cfrac {x}{1+...}}
\(1 + \cfrac{x}{1+\cfrac {x}{1+...}}\)
1 + \frac{x}{1+\frac {x}{1+...}}
\(1 + \frac{x}{1+\frac {x}{1+...}}\)
条件
用\begin{cases}...\end{cases}
表示分式,\\
换行,&
表示对齐
矩阵 向量
矩阵表示有行和列,用\\
表示换行,&
表示分列。
同时还有上面说的,大括号、方括号、小括号与内容大小相适应。
比如说
\left ( \begin{matrix} a & b \\ c & d \end{matrix}\right)
替换上式中的martix
可以表示不同的行列式、大矩阵、...等
martix |
示例 | 代码 |
---|---|---|
pmatrix |
\(\begin{pmatrix} a & b \\ c & d \end{pmatrix}\) | \begin{pmatrix}a & b \\ c & d \end{pmatrix} |
bmatrix |
\(\begin{bmatrix} a & b \\ c & d \end{bmatrix}\) | \begin{bmatrix}a & b \\ c & d \end{bmatrix} |
Bmatrix |
\(\begin{Bmatrix} a & b \\ c & d \end{Bmatrix}\) | \begin{Bmatrix}a & b \\ c & d \end{Bmatrix} |
vmatrix |
\(\begin{vmatrix} a & b \\ c & d \end{vmatrix}\) | \begin{vmatrix}a & b \\ c & d \end{vmatrix} |
Vmatrix |
\(\begin{Vmatrix} a & b \\ c & d \end{Vmatrix}\) | \begin{Vmatrix}a & b \\ c & d \end{Vmatrix} |
The environments pmatrix, bmatrix, Bmatrix, vmatrix, and Vmatrix have (respectively) ( ), [ ], { }, | |, and ‖ ‖ delimiters built in