使用 latex语法在Markdown文档中插入数学公式和特殊符号

大部分markdown编辑器都自带latex的公式解析功能。

起止符

行内公式使用$作为起止符,如

$a$

块级公式使用$$作为起止符,如

$$a$$

输入希腊字母和希伯来字母

Latex 显示效果
\alpha \(\alpha\)
\beta \(\beta\)
\gamma \(\gamma\)
\delta \(\delta\)
\epsilon \(\epsilon\)
\zeta \(\zeta\)
\eta \(\eta\)
\theta \(\theta\)
\iota \(\iota\)
\kappa \(\kappa\)
\lambda \(\lambda\)
\mu \(\mu\)
\varepsilon \(\varepsilon\)
\varkappa \(\varkappa\)
\nu \(\nu\)
\digamma \(\digamma\)
\vartheta \(\vartheta\)
\xi \(\xi\)
\pi \(\pi\)
\rho \(\rho\)
\sigma \(\sigma\)
\varsigma \(\varsigma\)
\upsilon \(\upsilon\)
\phi \(\phi\)
\chi \(\chi\)
\psi \(\psi\)
\omega \(\omega\)
\varrho \(\varrho\)
\tau \(\tau\)
\varpi \(\varpi\)
\varsigma \(\varsigma\)
\varphi \(\varphi\)
\aleph \(\aleph\)
\beth \(\beth\)
\daleth \(\daleth\)
\gimel \(\gimel\)

当希腊字母的LaTex语法首字母大写时,即输出大写的希腊字母;首字母小写时,输出小写的希腊字母,如:

  • 小写:$\alpha$将转换为\(\alpha\)
  • 大写:$\Alpha$将转换为\(\Alpha\)

插入一些数学的结构

Latex 显示效果
\frac{abc}{xyz} \(\frac{abc}{xyz}\)
f’ \(f’\)
\sqrt{abc} \(\sqrt{abc}\)
\sqrt[n]{abc} \(\sqrt[n]{abc}\)
\overline{abc} \(\overline{abc}\)
\underline{abc} \(\underline{abc}\)
\widehat{abc} \(\widehat{abc}\)
\widetilde{abc} \(\widetilde{abc}\)
\overrightarrow{abc} \(\overrightarrow{abc}\)
\overleftarrow{abc} \(\overleftarrow{abc}\)
\overbrace{abc} \(\overbrace{abc}\)
\underbrace{abc} \(\underbrace{abc}\)

插入定界符

Math_symbol_Delimiters

注:将上述定界符与\left和right组合使用可以使得定界符匹配其内容的高度。

比如要构建一个如下的矩阵的行列式:

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

显示效果如下:
$$
\left|\begin{matrix}
1 & 2 & 3 \
4 & 5 & 6 \
7 & 8 & 9
\end{matrix} \right|
$$

插入一些可变大小的符号


![Math_symbol_Variable-sized symbols](https://omssurgeon-pic.oss-cn-chengdu.aliyuncs.com/website/Math_symbol_Variable-sized symbols.png)

插入一些函数名称


Math_symbol_Function_names

插入二进制运算符和关系运算符


Math_symbol_binary_operation_relation_symbols_2


Math_symbol_binary_operation_relation_symbols_1

插入箭头符号


Math_symbol_arrow_symbols

插入一些其它的符号


Math_symbol_Miscellaneous_symbols

上下标

我们可以使用^来输出上标,使用_来输出下标。如:

$$
 \sin^2(\theta) + \cos^2(\theta) = 1\\
$$

$$
 \sum_{n=1}^\infty k
 $$

将显示为:
$$
\sin^2(\theta) + \cos^2(\theta) = 1

\[
\]

\sum_{n=1}^\infty k
$$

输出矩阵

矩阵中的各元素通过用&来分隔,\\来换行。如:

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

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

$$
 \begin{pmatrix}
 0&1&2\\
 3&4&5\\
 6&7&8\\
 \end{pmatrix}
$$

$$
\begin{pmatrix}
0&1&2\
3&4&5\
6&7&8\
\end{pmatrix}
$$

输出分段函数

\begin{cases}\end{cases}来构造分段函数,中间则用\\来分段。如:

$$
 f(x) = 
 \begin{cases}
 2x,\,\,x>0\\
 3x,\,\,x\le0\\
 \end{cases}
$$

$$
f(x) =
\begin{cases}
2x,,,x>0\
3x,,,x\le0\
\end{cases}
$$

字体

$\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

显示大小

  • 数学模式
$$
 {\displaystyle \int f(x)\,dx}
 $$

$$
{\displaystyle \int f(x),dx}
$$

$$
 {\textstyle \int f(x)\,dx}
$$

$$
{\textstyle \int f(x),dx}
$$

$$
 \scriptstyle \int f(x)\,dx
$$

$$
\scriptstyle \int f(x),dx
$$

$$
 \scriptscriptstyle \int f(x)\,dx
$$

$$
\scriptscriptstyle \int f(x),dx
$$

  • 文本模式

$\tiny{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\tiny{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\scriptsize{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\scriptsize{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\small{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\small{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\normalsize{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\normalsize{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\large{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\large{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$Large{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\Large{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\LARGE{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\LARGE{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\huge{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\huge{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

$\Huge{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}$
\(\Huge{ABCDEFGHIJKLMNOPQRSTUVWXYZabc123}\)

常用的一些公式输入范例

$\vec x$
\(\vec x\)

$\bar x$
\(\bar x\)

$\dot x$
\(\dot x\)

$\ddot x$
\(\ddot x\)

$$
 f'(x) = x^2 + x
$$

$$
f'(x) = x^2 + x
$$

$$
 \lim_{x\to0}\frac{9x^5+7x^3}{x^2+6x^8}
$$

$$
\lim_{x\to0}\frac{9x^5+7x^3}{x^2+6x^8}
$$

$$
 \int_a^b f(x)\,dx
$$

$$
\int_a^b f(x),dx
$$

$$
 \int_0^{+\infty}f(x)\,dx
$$

$$
\int_0^{+\infty}f(x),dx
$$

$$
 \int_{x^2+y^2\leq R^2} \,f(x,y)\,dx\,dy = \int_{\theta=0}^{2\pi}\int_{r=0}^R \,f(r\cos\theta,r\sin\theta)\,r\,dr\,d\theta
$$

$$
\int_{x^2+y^2\leq R^2} ,f(x,y),dx,dy = \int_{\theta=0}^{2\pi}\int_{r=0}^R ,f(r\cos\theta,r\sin\theta),r,dr,d\theta
$$

$$
 \int\!\!\!\int_D f(x,y)dxdy
$$

$$
\int!!!\int_D f(x,y)dxdy
$$

原文:一篇文章教会你如何在Markdown文档中插入数学公式
原文链接:https://zhuanlan.zhihu.com/p/158156773


更多符号:

更多Math symbols的latex语法:
http://www.csun.edu/~hcmth008/mathml/latex_help/Tables.pdf

其他:
https://www.cnblogs.com/ywsun/p/14271547.html

在word内使用latex语法输入公式和特殊符号

通过快捷键alt + =调出公式编辑器,即可使用latex语法输入。

但有部分latex语法在word中不支持,具体参考:https://support.microsoft.com/zh-cn/office/word-中使用-unicodemath-和-latex-的线性格式公式-2e00618d-b1fd-49d8-8cb4-8d17f25754f8?ui=zh-cn&rs=zh-cn&ad=cn

公式分行

输入公式如果太长有时需要将一个公式分成两行写,这里需要用到\begin{split}和\end{split},然后使用\将公式分成两行。如:

 $$
 \begin{split}
 L= (3 + 5) \div \\ (5 + 3)
 \end{split}
 $$

效果:

$$
\begin{split}
L= (3 + 5) \div \\ (5 + 3)
\end{split}
$$

公式对齐

当公式有多个等号的时候,需要将等号对齐,需要用到align环境,同时等号前要加上&符号,如:

$$
\begin{align}
S & = (1+4)\times 2 \\\\ & = 1\times 2+4\times 2 \\\\ & = 2+8 \\\\ & = 10
\end{align}
$$

效果:

$$
\begin{align}
S & = (1+4)\times 2 \\ & = 1\times 2 + 4\times 2 \\ & = 2+8 \\ & = 10
\end{align}
$$