Markdown编写数学公式实例大全

Markdown编写数学公式实例大全

平时写博客尤其是关于一些数学方面的,就免不了用复杂的数学公式,而采用粘贴图片的方式肯定是不好的,即不方便又影响美观,而且一点儿事儿也不省,还不如老老实实的用KaTeX编写数学公式,既美观又清晰,CSDN-Markdown编辑器支持基于MathJax编写KaTeX数学公式。MathJax是一款运行在浏览器中的开源的数学符号渲染引擎,使用MathJax可以方便的在浏览器中显示数学公式,不需要使用图片。所以我结合我的日常使用情况,汇总了几篇博文中一些常用的Markdown数学公式语法,感觉已经特别全了,当然也可能有遗漏,以后遇到陌生的,再持续更新吧。

官方网站:https://katex.org

文章目录

      • Markdown编写数学公式实例大全
        • 1. 格式语法
        • 2. 括号应用扩展
        • 3. 关系运算符
        • 4. 集合运算符
        • 5. 对数运算符
        • 6. 三角运算符
        • 7. 微积分运算符
        • 8. 逻辑运算符
        • 9. 戴帽符号
        • 10. 连线符号
        • 11. 箭头符号
        • 12. 特殊字符
        • 13. 矩阵
          • 13.1 简单矩阵
          • 13.2 带括号的矩阵
          • 13.3 带省略符号的矩阵
          • 13.4 带参数的矩阵
        • 14. 大括号的方程组
        • 15. 希腊字母
        • 16 字体转换
        • 17. 参考博客链接

1. 格式语法

格式 语法 示例 预览
行内公式 $数学公式$ $\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N$ Γ ( n ) = ( n − 1 ) ! ∀ n ∈ N \Gamma(n) = (n-1)!\quad\forall n\in\mathbb N Γ(n)=(n1)!nN
块级公式 $$数学公式$$ $$ x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$ x = − b ± b 2 − 4 a c 2 a x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} x=2ab±b24ac
省略号 \ldots 底线对齐,\cdots 中线对齐 $f(x_1,x_2,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2$ f ( x 1 , x 2 , … , x n ) = x 1 2 + x 2 2 + ⋯ + x n 2 f(x_1,x_2,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2 f(x1,x2,,xn)=x12+x22++xn2
间隔空间 \空格 或 \;增加些许间隙,\quad 与 \qquad 更大的间隙 $a;b$ 或 $a\quad b$ 或 $a\qquad b$ a    b a\;b ab a b a\quad b ab a b a\qquad b ab
换行 加\\ 即可 $$ 1 + 1 = 2 \ 1 + 2 = 3 $$ 1 + 1 = 2 1 + 2 = 3 1 + 1 = 2 \\ 1 + 2 = 3 1+1=21+2=3
上标和下标 ^表示上标,_表示下标 $x^2 y^{x+1} \quad x_2 y_{y+1}$ x 2 y x + 1 y 2 x y + 1 x^2 y^{x+1} \quad y_2 x_{y+1} x2yx+1y2xy+1
分数表示 \frac{分子}{分母} 或者 分子 \over 分母 $\frac{a+b}{c+d}$ 或 $1 \over 3$ a + b c + d \frac{a+b}{c+d} c+da+b 或  1 3 1 \over 3 31
括号 ()、[]和|可以直接表示自己,而{}本来用于分组,因此需要用\{\}来表示自身 ${[z-(1+\frac23x)y]\div 4}$ { [ z − ( 1 + 2 3 x ) y ] ÷ 4 } \{[z-(1+\frac23x)y]\div 4\} { [z(1+32x)y]÷4}
缩放 用\left和\right标记 $\left(1+\frac23x\right)$ ( 1 + 2 3 x ) \left(1+\frac23x\right) (1+32x)
根号表示 \sqrt[开方次数,默认为2]{开方因子} $\sqrt{x^3}$ 和 $\sqrt[3]{\frac xy}$ x 3 \sqrt{x^3} x3  和  x y 3 \sqrt[3]{\frac xy} 3yx
矢量表示 \vec{矢量值} $\vec{a} \cdot \vec{b}=0$ a ⃗ ⋅ b ⃗ = 0 \vec{a} \cdot \vec{b}=0 a b =0

2. 括号应用扩展

\left和\right标记必须是成对出现的,但有时候我们只用到其中一个,比如只用一个|当作分割线,这时候可以通过.来表示空的那一方,即用\left.表达左边空的情况,用\right.表达右边空的情况。

格式 语法 示例 预览
单独用 \left和\right标记 $\left. \frac{du}{dx}\right| _{x=0}$ d u d x ∥ x = 0 \left. \frac{du}{dx} \right\| _{x=0} dxdux=0
符号名称 LaTex代码 例子 产生的效果
小括号 ( 和 ) $\left (\frac{1}{2}\right)$ ( 1 2 ) \left (\frac{1}{2}\right) (21)
中括号 [ 和 ] $\left [\frac{1}{2}\right]$ [ 1 2 ] \left [\frac{1}{2}\right] [21]
大括号 { 和 } $\left {\frac{1}{2}\right}$ { 1 2 } \left \{\frac{1}{2}\right\} { 21}
取绝对值 | $\left|\frac{1}{2}\right|$ ∥ 1 2 ∥ \left\|\frac{1}{2}\right\| 21
尖括号 \langle 和 \rangle $\left\langle\frac{1}{2}\right\rangle$ ⟨ 1 2 ⟩ \left \langle \frac{1}{2} \right \rangle 21
向上取整 \lceil 和 \rceil $\left\lceil\frac{1}{2}\right\rceil$ ⌈ 1 2 ⌉ \left\lceil\frac{1}{2}\right\rceil 21
向下取整 \lfloor 和 \rfloor $\left\lfloor\frac{1}{2}\right\rfloor$ ⌊ 1 2 ⌋ \left\lfloor\frac{1}{2}\right\rfloor 21

3. 关系运算符

运算符 语法表达
± \pm
× \times
÷ \div
\mid
\nmid
\cdot
\circ
\ast
\bigodot
\bigotimes
\bigoplus
\leq
\geq
\neq
\approx
\equiv
\sum
\prod
\coprod

4. 集合运算符

运算符 语法表达
\emptyset
\in
\notin
\subset
\supset
\subseteq
\supseteq
\bigcap
\bigcup
\bigvee
\bigwedge
\biguplus
\bigsqcup

5. 对数运算符

运算符 语法表达
log \log
lg \lg
ln \ln

6. 三角运算符

运算符 语法表达
\bot
\angle
30∘ 30^\circ
sin \sin
cos \cos
tan \tan
cot \cot
sec \sec
csc \csc

7. 微积分运算符

运算符 语法表达
\prime
\int
\iint
\iiint
\iiiint
\oint
lim \lim
\infty
\nabla

8. 逻辑运算符

运算符 语法表达
\because
\therefore
\forall
\exists
\not=
\not>
\not\subset

9. 戴帽符号

运算符 语法表达
y^ \hat{y}
\check{y}
\breve{y}

10. 连线符号

运算符 语法表达
a + b + c + d ‾ \overline{a+b+c+d} a+b+c+d \overline{a+b+c+d}
a + b + c + d ‾ \underline{a+b+c+d} a+b+c+d \underline{a+b+c+d}
a + b + c ⏟ 1.0 + d ⏞ 2.0 \overbrace{a+\underbrace{b+c}_{1.0}+d}^{2.0} a+1.0 b+c+d 2.0 \overbrace{a+\underbrace{b+c}_{1.0}+d}^{2.0}

11. 箭头符号

运算符 语法表达
\uparrow
\downarrow
\Uparrow
\Downarrow
\rightarrow
\leftarrow
\Rightarrow
\Leftarrow
\longrightarrow
\longleftarrow
\Longrightarrow
\Longleftarrow

12. 特殊字符

运算符 语法表达
空格 \空格
# \#
$ \$
% \%
& \&
_ \_
{ \{
} \}

13. 矩阵

13.1 简单矩阵
$$
  \begin{matrix}
   1 & 2 & 3 \\
   4 & 5 & 6 \\
   7 & 8 & 9
  \end{matrix} \tag{1}
$$ 

1 2 3 4 5 6 7 8 9 (1) \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \tag{1} 147258369(1)

13.2 带括号的矩阵
$$
 \left\{
 \begin{matrix}
   1 & 2 & 3 \\
   4 & 5 & 6 \\
   7 & 8 & 9
  \end{matrix}
  \right\} \tag{2}
$$

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

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

[ 1 2 3 4 5 6 7 8 9 ] (3) \left[ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right] \tag{3} 147258369(3)

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

[ 1 2 3 4 5 6 7 8 9 ] (4) \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \tag{4} 147258369(4)

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

{ 1 2 3 4 5 6 7 8 9 } (5) \begin{Bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{Bmatrix} \tag{5} 147258369(5)

13.3 带省略符号的矩阵
$$
\left[
\begin{matrix}
 1      & 2      & \cdots & 4      \\
 7      & 6      & \cdots & 5      \\
 \vdots & \vdots & \ddots & \vdots \\
 8      & 9      & \cdots & 0      \\
\end{matrix}
\right]
$$

[ 1 2 ⋯ 4 7 6 ⋯ 5 ⋮ ⋮ ⋱ ⋮ 8 9 ⋯ 0 ] (6) \left[ \begin{matrix} 1 & 2 & \cdots & 4 \\ 7 & 6 & \cdots & 5 \\ \vdots & \vdots & \ddots & \vdots \\ 8 & 9 & \cdots & 0 \\ \end{matrix} \right] \tag6 178269450(6)

13.4 带参数的矩阵
$$ 
\left[
    \begin{array}{cc|c}
      1 & 2 & 3 \\
      4 & 5 & 6
    \end{array}
\right] \tag{7}
$$

[ 1 2 3 4 5 6 ] (7) \left[ \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array} \right] \tag{7} [142536](7)

$$
\begin{array}{c|clr}
n &\text{左对齐} & \text{居中对齐} & \text{右对齐} \\
\hline
1 & 0.24 & 0.33 &122 \\
2 & -0.31 & 0.67 & 32821\\
3 &-7 &-3 & 33\\
\end{array} \tag{8}
$$

n 左对齐 居中对齐 右对齐 1 0.24 0.33 122 2 − 0.31 0.67 32821 3 − 7 − 3 33 (8) \begin{array}{c|clr} n &\text{左对齐} & \text{居中对齐} & \text{右对齐} \\ \hline 1 & 0.24 & 0.33 &122 \\ 2 & -0.31 & 0.67 & 32821\\ 3 &-7 &-3 & 33\\ \end{array}\tag{8} n123左对齐0.240.317居中对齐0.330.673右对齐1223282133(8)

14. 大括号的方程组

$$ f(x)=\left\{
\begin{aligned}
x & = & \cos(t) \\
y & = & \sin(t) \\
z & = & \frac xy
\end{aligned}
\right.
$$

f ( x ) = { x = cos ⁡ ( t ) y = sin ⁡ ( t ) z = x y f(x)=\left\{ \begin{aligned} x & = & \cos(t) \\ y & = & \sin(t) \\ z & = & \frac xy \end{aligned} \right. f(x)=xyz===cos(t)sin(t)yx

$$ x^{y}=\left\{
\begin{array}{rcl}
x_0       &      & {0      <      S_L}\\
x^2_0     &      & {S_L \leq 0 < S_M}\\
x^2_1     &      & {S_M \leq 0 < S_R}\\
x_2       &      & {S_R \leq 0}
\end{array} \right. 
$$

x y = { x 0 0 < S L x 0 2 S L ≤ 0 < S M x 1 2 S M ≤ 0 < S R x 2 S R ≤ 0 x^{y}=\left\{ \begin{array}{rcl} x_0 & & {0 < S_L}\\ x^2_0 & & {S_L \leq 0 < S_M}\\ x^2_1 & & {S_M \leq 0 < S_R}\\ x_2 & & {S_R \leq 0} \end{array} \right. xy=x0x02x12x20<SLSL0<SMSM0<SRSR0

$$f(x)=
\begin{cases}
0& \text{x=0}\\
1& \text{x!=0}
\end{cases}
$$

f ( x ) = { 0 x=0 1 x!=0 f(x)= \begin{cases} 0& \text{x=0}\\ 1& \text{x!=0} \end{cases} f(x)={ 01x=0x!=0

$$
\begin{aligned} % requires amsmath; align* for no eq. number
A & =(x-y)(x+y) \\
   & =x*x+x*y-y*x-y*y\\
   & = x^2 - y^2
\end{aligned}
$$

A = ( x − y ) ( x + y ) = x ∗ x + x ∗ y − y ∗ x − y ∗ y = x 2 − y 2 \begin{aligned} % requires amsmath; align* for no eq. number A & =(x-y)(x+y) \\ & =x*x+x*y-y*x-y*y\\ & = x^2 - y^2 \end{aligned} A=(xy)(x+y)=xx+xyyxyy=x2y2

$$
f(x) = \left\{
  \begin{array}{lr}
    x^2 & : x < 0\\
    x^3 & : x \ge 0
  \end{array}
\right.
$$

f ( x ) = { x 2 : x < 0 x 3 : x ≥ 0 f(x) = \left\{ \begin{array}{lr} x^2 & : x < 0\\ x^3 & : x \ge 0 \end{array} \right. f(x)={ x2x3:x<0:x0

$$
u(x) = 
  \begin{cases} 
   \exp{x} & \text{if } x \geq 0 \\
   1       & \text{if } x < 0
  \end{cases}
$$

u ( x ) = { exp ⁡ x if  x ≥ 0 1 if  x < 0 u(x) = \begin{cases} \exp{x} & \text{if } x \geq 0 \\ 1 & \text{if } x < 0 \end{cases} u(x)={ expx1if x0if x<0

$$
\left\{ 
\begin{array}{c}
    a_1x+b_1y+c_1z=d_1 \\ 
    a_2x+b_2y+c_2z=d_2 \\ 
    a_3x+b_3y+c_3z=d_3
\end{array}
\right. 
$$

{ a 1 x + b 1 y + c 1 z = d 1 a 2 x + b 2 y + c 2 z = d 2 a 3 x + b 3 y + c 3 z = d 3 \left\{ \begin{array}{c} a_1x+b_1y+c_1z=d_1 \\ a_2x+b_2y+c_2z=d_2 \\ a_3x+b_3y+c_3z=d_3 \end{array} \right. a1x+b1y+c1z=d1a2x+b2y+c2z=d2a3x+b3y+c3z=d3

15. 希腊字母

希腊字母(小写) 输入 希腊字母(大写) 输入
α \alpha Α A
β \beta Β B
γ \gamma Γ \Gamma
δ \delta Δ \Delta
ε或ϵϵ \epsilon或\varepsilon Ε E
ζ \zeta Ζ Z
η \eta Η H
θ或ϑ \theta或\vartheta Θ \Theta
ι \iota Ι I
κ \kappa Κ K
λ \lambda Λ \Lambda
μ \mu Μ M
ν \nu Ν N
ξ \xi Ξ \Xi
ο o Ο O
π或ϖ \pi或\varpi Π \Pi
ρ或ϱ \rho或\varrho Ρ P
σ或ς \sigma或\varsigma Σ \Sigma
τ \tau Τ T
υ \upsilon Υ \Upsilon
φ或φ \phi或\varphi Φ \Phi
χ \chi Χ X
ψ \psi Ψ \Psi
ω \omega Ω \Omega

16 字体转换

要对公式的某一部分字符进行字体转换,可以用{\rm 需转换的部分字符}命令,其中\rm可以参照下表选择合适的字体。一般情况下,公式默认为意大利体。

字体符号 字体名称
\rm 罗马体
\it 意大利体
\bf 黑体
\sf 等线体
\mit 数学斜体
\tt 打字机字体
\sc 小体大写字母

17. 参考博客链接

  • 【持续更新】Markdown中数学公式及符号整理

  • CSDN-markdown语法之如何使用LaTeX语法编写数学公式

  • Markdown中编写LaTeX数学公式

你可能感兴趣的:(Algorithm,markdown,latex,katex,数学公式)