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

Markdown中数学公式及符号整理

  在写博客、写文档中经常需要编辑各种形式的数学公式。对于简单的公式,可以在word中编辑,对于复杂的公式一般以截图、粘贴的方式。利用Markdown中的LaTeX插件,公式均以代码形式编辑,写文档时十分方便,特别是在推导各种算法公式时。
  首先设置typora的偏好设置,使其支持LaTeX插件。设置方法:文件—偏好设置,找到Markdown扩展语法,勾选 内联公式(例:$\LaTeX$)即可。英文版typora设置方法也是一样的。

一、latex基本语法

1、公式编辑设置
1.1 公式编辑编号设置

  在编写公式之前首先说明一下公式后面的标号编辑方法。默认情况下公式后面是没有序号的。设置标号有如下符号:

符号说明
\eqno{标号}系统序号设置命令, 它紧跟在equation*环境,可在公式右侧人工设置标号。标号可以是任意文本
\leqno{标号}作用于\eqno相同,只是将标号至于公式的左侧。\eqno与\leqno不能同时在一个公式中使用
\nonumber系统取消序号命令,把它插在换行命令\\之前,可以取消为该行公式排序而使其无序号
\notag公式宏包序号取消命令,使用方法和作用与\nonumber命令相同
\tag{标号}公式宏包序号设置命令,可用于带星号公式环境中的公式行
\tag*{标号}作用与\tag相同,只是标号两侧没有圆括号

个人比较喜欢\tag{标号}和\tag*{标号}这两种形式,而且这两种形式用的基本上也是最多的。示例:

$$
x^2+y^2=z^2 \tag{1$'$}
$$
$$
x^3+y^3=z^3  
$$
$$
x^4+y^4=z^4 \tag{*} 
$$
$$
x^5+y^5=z^5 \tag*{*}
$$
$$
x^6+y^6=z^6 \tag{1-1} 
$$

( 1 ′ ) x 2 + y 2 = z 2 x^2+y^2=z^2 \tag{1$'$} x2+y2=z2(1)

x 3 + y 3 = z 3 x^3+y^3=z^3 x3+y3=z3

(*) x 4 + y 4 = z 4 x^4+y^4=z^4 \tag{*} x4+y4=z4(*)

* x 5 + y 5 = z 5 x^5+y^5=z^5 \tag*{*} x5+y5=z5*

(1-1) x 6 + y 6 = z 6 x^6+y^6=z^6 \tag{1-1} x6+y6=z6(1-1)

  上面例子中的\\表示公式换行。\begin{gather}表示环境设置。下一小节将介绍环境设置。
  接下来是引用编号,使用\tag指令指定公式的具体编号后,再使用\label指令埋下锚点,如下:
x^2+y^2=z^2 \tag{1-2} \label{eq:test}
(1-2) x 2 + y 2 = z 2 x^2+y^2=z^2 \tag{1-2} x2+y2=z2(1-2)
使用\eqref指令引用前面标记的锚点,使用$\eqref{eq:test}$指令将显示为: ( 1 (1 (1- 2 ) 2) 2)注意:此处有个很头疼的地方就是,这个\label{eq:test}容易产生多次定义,对于这种问题,如果test确实只定义了一次,关闭typora,重启就好

1.2 公式编辑环境设置

  以下环境中,对齐和对齐 ∗ * (alignat and alignat*)是最有用的,但其他环境有时候也会用到:

环境名称描述备注
eqnarray and eqnarray*与alignat and alignat*相似不建议使用,因为间距不一样
multline and multline*第一行左对齐,最后一行右对齐公式编号与第一行垂直对齐,不像其他环境那样居中
gather and gather*没有对齐的连续方程
flalign and flalign*与align类似,但左对齐第一个方程列,右对齐最后一列
alignat and alignat*采用指定列数的参数。 允许控制方程之间的水平空间如{alignat}{2} :与第二列对齐

还有以下环境,这些环境本身不构成数学环境,但可以用于更复杂结构的构建块:

数学环境名称描述
gathered允许多行(多组)方程式在彼此之下设置并分配单个方程式编号
split与align *类似,但在另一个显示的数学环境中使用
aligned与align类似,可以在其他数学环境中使用。
alignedat与alignat类似,同样需要一个额外的参数来指定要设置的方程列数。

示例如下:

\begin{aligned}
 \left.\begin{aligned}
        B'&=-\partial \times E,\\         %加&指定对齐位置
        E'&=\partial \times B - 4\pi j,
       \end{aligned}
 \right\}								%加右}
 \qquad \text{Maxwell's equations}
\end{aligned}

B ′ = − ∂ × E , E ′ = ∂ × B − 4 π j , } Maxwell’s equations \left.\begin{aligned} B'&=-\partial \times E,\\ E'&=\partial \times B - 4\pi j, \end{aligned} \right\} \qquad \text{Maxwell's equations} BE=×E,=×B4πj,}Maxwell’s equations
注:如果各个方程需要在某个字符处对齐(如等号对齐),只需在所有要对齐的字符前加上 & 符号。如果不需要公式编号,只需在宏包名称后加上 * 号。

\begin{aligned}
 \sigma_1 &= x + y  &\quad \sigma_2 &= \frac{x}{y} \\	
 \sigma_1' &= \frac{\partial x + y}{\partial x} & \sigma_2' 
    &= \frac{\partial \frac{x}{y}}{\partial x}
\begin{aligned}

σ 1 = x + y σ 2 = x y σ 1 ′ = ∂ x + y ∂ x σ 2 ′ = ∂ x y ∂ x \begin{aligned} \sigma_1 &= x + y &\quad \sigma_2 &= \frac{x}{y} \\ \sigma_1' &= \frac{\partial x + y}{\partial x} & \sigma_2' &= \frac{\partial \frac{x}{y}}{\partial x} \end{aligned} σ1σ1=x+y=xx+yσ2σ2=yx=xyx

\begin{aligned}
a_0&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}f(x)\,\mathrm{d}x\\[6pt]
a_n&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}f(x)\cos nx\,\mathrm{d}x=\\
&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}x^2\cos nx\,\mathrm{d}x\\[6pt]
b_n&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}f(x)\sin nx\,\mathrm{d}x=\\
&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}x^2\sin nx\,\mathrm{d}x
\\[6pt]
\end{aligned}

a 0 = 1 π ∫ − π π f ( x )   d x a n = 1 π ∫ − π π f ( x ) cos ⁡ n x   d x = = 1 π ∫ − π π x 2 cos ⁡ n x   d x b n = 1 π ∫ − π π f ( x ) sin ⁡ n x   d x = = 1 π ∫ − π π x 2 sin ⁡ n x   d x \begin{aligned} a_0&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}f(x)\,\mathrm{d}x\\[6pt] a_n&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}f(x)\cos nx\,\mathrm{d}x=\\ &=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}x^2\cos nx\,\mathrm{d}x\\[6pt] b_n&=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}f(x)\sin nx\,\mathrm{d}x=\\ &=\frac{1}{\pi}\int\limits_{-\pi}^{\pi}x^2\sin nx\,\mathrm{d}x \\[6pt] \end{aligned} a0anbn=π1ππf(x)dx=π1ππf(x)cosnxdx==π1ππx2cosnxdx=π1ππf(x)sinnxdx==π1ππx2sinnxdx

关于公式编辑环境设置的语法说明,此处※※有更详细的说明

二、latex常见数学符号

2.1 常用数学符号

  行内公式使用$....$,行间公式使用$$...$$。常用符号如下表,其中部分符号首字母大写,符号也会变为大写的格式,箭头是变粗

符号代码符号代码
∑ \sum $\sum$ × \times ×$\times$
∑ i = 0 n \sum_{i=0}^n i=0n$\sum_{i=0}^n$ ± \pm ±$\pm$
÷ \div ÷$\div$ ∣ \mid $\mid$
⋅ \cdot $\cdot$ ∘ \circ $\circ$
∗ \ast $\ast$ ≤ \leq $\leq$
⨂ \bigotimes $\bigotimes$ ≥ \geq $\geq$
⨁ \bigoplus $\bigoplus$ ≠ \neq ̸=$\neq$
∏ \prod $\prod$ ≈ \approx $\approx$
∐ \coprod $\coprod$ ∬ \iint $\iint$
⋯ \cdots $\cdots$ ∫ \int $\int$
∇ \nabla $\nabla$ ∮ \oint $\oint$
∵ \because $\because$ ∞ \infty $\infty$
∴ \therefore $\therefore$ ̸ > \not> ̸>$\not>$
∀ \forall $\forall$ ̸ ⊂ \not\subset ̸$\not\subset$
∃ \exists $\exists$ ∅ \emptyset $\emptyset$
⋃ \bigcup $\bigcup$ ∈ \in $\in$
⋂ \bigcap $\bigcap$ ∉ \notin /$\notin$
⋁ \bigvee $\bigvee$ ⊂ \subset $\subset$
⋀ \bigwedge $\bigwedge$ ⊆ \subseteq $\subseteq$
y ^ \hat{y} y^$\hat{y}$ α \alpha α$\alpha$
y ˇ \check{y} yˇ$\check{y}$ β \beta β$\beta$
y ˘ \breve{y} y˘$\breve{y}$ γ \gamma γ$\gamma$
↑ \uparrow $\uparrow$ Γ \Gamma Γ$\Gamma$
↓ \downarrow $\downarrow$ δ \delta δ$\delta$
⇑ \Uparrow $\Uparrow$ Δ \Delta Δ$\Delta$
↓ \downarrow $\Downarrow$ ϵ \epsilon ϵ$\epsilon$
→ \rightarrow $\rightarrow$ ε \varepsilon ε$\varepsilon$
← \leftarrow $\leftarrow$ ζ \zeta ζ$\zeta$
⇒ \Rightarrow $\Rightarrow$ η \eta η$\eta$
⇐ \Leftarrow $\Leftarrow$ θ \theta θ$\theta$
⟸ \Longleftarrow $\Longleftarrow$ Θ \Theta Θ$\Theta$
⟵ \longleftarrow $\longleftarrow$ ϑ \vartheta ϑ$\vartheta$
⟶ \longrightarrow $\longrightarrow$ ι \iota ι$\iota$
Σ \Sigma Σ$\Sigma$ π \pi π$\pi$
ν \nu ν$\nu$ ϕ \phi ϕ$\phi$
ξ \xi ξ$\xi$ ψ \psi ψ$\psi$
τ \tau τ$\tau$ Ψ \Psi Ψ$\Psi$
λ \lambda λ$\lambda$ ω \omega ω$\omega$
Λ \Lambda Λ$\Lambda$ Ω \Omega Ω$\Omega$
μ \mu μ$\mu$ χ \chi χ\chi
∂ \partial $\partial$ ρ \rho ρ$\rho$
{ } \lbrace \rbrace {}$\lbrace \rbrace$ ο \omicron ο$\omicron$
a ‾ \overline{a} a$\overline{a}$ σ \sigma σ$\sigma$
⇔ \Leftrightarrow $\Leftrightarrow$ ∠ \angle $\angle$
⇌ \rightleftharpoons \rightleftharpoons △ \triangle $\triangle$
↗ \nearrow $\nearrow$ ↖ \nwarrow $\nwarrow$
↘ \searrow $\searrow $ ↙ \swarrow $\swarrow$
♢ \diamondsuit $\diamondsuit$ ⋄ \diamond $\diamond$
♡ \heartsuit $\heartsuit$ ∥ \parallel $\parallel$
2.2 各种表达式
  • text文字表达
$$
z = \overbrace{
   \underbrace{x}_\text{real} + i
   \underbrace{y}_\text{imaginary}
  }^\text{complex number}
$$

z = x ⎵ real + i y ⎵ imaginary ⏞ complex number z = \overbrace{ \underbrace{x}_\text{real} + i \underbrace{y}_\text{imaginary} }^\text{complex number} z=real x+iimaginary y complex number

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

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

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

u ( x ) = { exp ⁡ x if  x ≥ 0 1 if  x &lt; 0 u(x) = \begin{cases} \exp{x} &amp; \text{if } x \geq 0 \\ 1 &amp; \text{if } x &lt; 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

  • 线性模型
$$
h(\theta) = \sum_{j = 0} ^n \theta_j x_j
$$

h ( θ ) = ∑ j = 0 n θ j x j h(\theta) = \sum_{j = 0} ^n \theta_j x_j h(θ)=j=0nθjxj

  • 均方误差
$$
J(\theta) = \frac{1}{2m}\sum_{i = 0} ^m(y^i - h_\theta (x^i))^2
$$

J ( θ ) = 1 2 m ∑ i = 0 m ( y i − h θ ( x i ) ) 2 J(\theta) = \frac{1}{2m}\sum_{i = 0} ^m(y^i - h_\theta (x^i))^2 J(θ)=2m1i=0m(yihθ(xi))2

  • 批量梯度下降
$$
\frac{\partial J(\theta)}{\partial\theta_j}=-\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i))x^i_j 
$$

∂ J ( θ ) ∂ θ j = − 1 m ∑ i = 0 m ( y i − h θ ( x i ) ) x j i \frac{\partial J(\theta)}{\partial\theta_j}=-\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i))x^i_j θjJ(θ)=m1i=0m(yihθ(xi))xji

  • 推导过程
$$
\begin{aligned}
\frac{\partial J(\theta)}{\partial\theta_j}
& = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i)) \frac{\partial}{\partial\theta_j}(y^i-h_\theta(x^i)) \\
& = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i)) \frac{\partial}{\partial\theta_j}(\sum_{j=0}^n\theta_jx_j^i-y^i) \\
& = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i))x^i_j
\end{aligned}
$$

∂ J ( θ ) ∂ θ j = − 1 m ∑ i = 0 m ( y i − h θ ( x i ) ) ∂ ∂ θ j ( y i − h θ ( x i ) ) = − 1 m ∑ i = 0 m ( y i − h θ ( x i ) ) ∂ ∂ θ j ( ∑ j = 0 n θ j x j i − y i ) = − 1 m ∑ i = 0 m ( y i − h θ ( x i ) ) x j i \begin{aligned} \frac{\partial J(\theta)}{\partial\theta_j} &amp; = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i)) \frac{\partial}{\partial\theta_j}(y^i-h_\theta(x^i)) \\ &amp; = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i)) \frac{\partial}{\partial\theta_j}(\sum_{j=0}^n\theta_jx_j^i-y^i) \\ &amp; = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i))x^i_j \end{aligned} θjJ(θ)=m1i=0m(yihθ(xi))θj(yihθ(xi))=m1i=0m(yihθ(xi))θj(j=0nθjxjiyi)=m1i=0m(yihθ(xi))xji

  • case环境的使用
$$
a =
   \begin{cases}
     \int x\, \mathrm{d} x\\
     b^2
   \end{cases}
$$

a = { ∫ x &ThinSpace; d x b 2 a = \begin{cases} \int x\, \mathrm{d} x\\ b^2 \end{cases} a={xdxb2

  • 带方框的等式
$$
\begin{aligned}
 \boxed{x^2+y^2 = z^2}
\end{aligned}
$$

x 2 + y 2 = z 2 \begin{aligned} \boxed{x^2+y^2 = z^2} \end{aligned} x2+y2=z2

  • 最大(最小)操作符
$$
\begin{gathered}
\operatorname{arg\,max}_a f(a) 
 = \operatorname*{arg\,max}_b f(b) \\
 \operatorname{arg\,min}_c f(c) 
 = \operatorname*{arg\,min}_d f(d)
\end{gathered}
$$

arg&ThinSpace;max ⁡ a f ( a ) = * ⁡ a r g &ThinSpace; m a x b f ( b ) arg&ThinSpace;min ⁡ c f ( c ) = * ⁡ a r g &ThinSpace; m i n d f ( d ) \begin{gathered} \operatorname{arg\,max}_a f(a) = \operatorname*{arg\,max}_b f(b) \\ \operatorname{arg\,min}_c f(c) = \operatorname*{arg\,min}_d f(d) \end{gathered} argmaxaf(a)=*argmaxbf(b)argmincf(c)=*argmindf(d)

  • 求极限
$$
\begin{aligned}
  \lim_{a\to \infty} \tfrac{1}{a}
\end{aligned}
$$
$$
\begin{aligned}
   \lim\nolimits_{a\to \infty} \tfrac{1}{a}
\end{aligned}
$$

lim ⁡ a → ∞ 1 a \begin{aligned} \lim_{a\to \infty} \tfrac{1}{a} \end{aligned} alima1

lim ⁡ a → ∞ 1 a \begin{aligned} \lim\nolimits_{a\to \infty} \tfrac{1}{a} \end{aligned} limaa1

  • 求积分
$$
\begin{aligned}
   \int_a^b x^2  \mathrm{d} x
\end{aligned}
$$
$$
\begin{aligned}
   \int\limits_a^b x^2  \mathrm{d} x
\end{aligned}
$$

∫ a b x 2 d x \begin{aligned} \int_a^b x^2 \mathrm{d} x \end{aligned} abx2dx

∫ a b x 2 d x \begin{aligned} \int\limits_a^b x^2 \mathrm{d} x \end{aligned} abx2dx

  • 求累加
$$
\begin{aligned}
   \sum\nolimits' C_n
\end{equation}
$$

$$
\begin{aligned}
   \sum_{n=1}\nolimits' C_n
\end{aligned}
$$

$$
\begin{aligned}
   \sideset{}{'}\sum_{n=1}C_n
\end{aligned}
$$

$$
\begin{aligned}
   \sideset{_a^b}{_c^d}\sum
\end{aligned}
$$

∑ ′ C n \begin{aligned} \sum\nolimits&#x27; C_n \end{aligned} Cn

∑ n = 1 ′ C n \begin{aligned} \sum_{n=1}\nolimits&#x27; C_n \end{aligned} n=1Cn

  • 求累乘
$$
  \prod_{{
  \begin{gathered}
            1\le i \le n\\
            1\le j \le m
  \end{gathered}
            }}
     M_{i,j}
$$

∏ 1 ≤ i ≤ n 1 ≤ j ≤ m M i , j \prod_{ \begin{gathered} 1\le i \le n \\ 1\le j \le m \end{gathered} } M_{i,j} 1in1jmMi,j

  • 开根号
$$
\sqrt x * \sqrt[3] x * \sqrt[-1] x
$$

x ∗ x 3 ∗ x − 1 \sqrt x * \sqrt[3] x * \sqrt[-1] x x 3x 1x

  • 省略号的使用
$$
{1+2+3+\ldots+n}
$$

1 + 2 + 3 + … + n {1+2+3+\ldots+n} 1+2+3++n

2.3 其他格式

  不同括号的效果如下:
$ \tbinom{n}{k}$ ⟶ \longrightarrow ( n k ) \tbinom{n}{k} (kn)
$ \binom{n}{k}$ ⟶ \longrightarrow ( n k ) \binom{n}{k} (kn)
$ \dbinom{n}{k}$ ⟶ \longrightarrow ( n k ) \dbinom{n}{k} (kn)
$ {n\brace k}$ ⟶ \longrightarrow \{ n k \} {n\brace k} {kn}
$ {n\choose k}$ ⟶ \longrightarrow ( n k ) {n\choose k} (kn)
$ {n\brack k}$ ⟶ \longrightarrow [ n k ] {n\brack k} [kn]

  上述括号特别适用于求和,求积,以及概率的表达式中,如独立重复事件表达式:
P ( n ) = c P(n) = {\Huge c} P(n)=c ( n k ) \dbinom{n}{k} (kn)

上下标格式
$ stackrel{x}{y}$ ⟶ \longrightarrow y x \stackrel{x}{y} yx
$ overset{x}{y}$ ⟶ \longrightarrow y x \overset{x}{y} yx
$ underset{x}{y}$ ⟶ \longrightarrow y x \underset{x}{y} xy

三、总结

  在编辑的过程中,发现typora中的Latex公式环境在CSDN中Markdown编辑器中不适用。以及对于行内公式,CSDN中的$...$要求$与表达式之间不能有空格,不然也显示不出来,而Latex则没有如此严格。
  后面查看Katex API中Handling Errors
If KaTeX encounters an error (invalid or unsupported LaTeX) and throwOnError hasn’t been set to false, then katex.render and katex.renderToString will throw an exception of type katex.ParseError. The message in this error includes some of the LaTeX source code, so needs to be escaped if you want to render it to HTML. For example…
  上述文字说明了KaTeX确实对某些Latex公式不支持。最后希望以后CSDN平台也能兼容LaTeX格式。对Latex和Markdown感兴趣的,大家可以评论区留言交流。
后面再继续更新补充。。。

四、参考资料

1.typora-数学符号
2.试试LaTeX插入数学公式
3.CSDN·Markdown·KaTex/LaTex 用法小全
4.最全 Markdown + Latex 编写技巧
5.LaTeX/Advanced Mathematics
6.MathJax: LaTeX Basic Tutorial und Referenz (Deutsch)
7.Katex API

更新文本折叠功能:
由于老版本typora不支持部分HTML语法,因此最好先typora更新到最新版本,即可支持文本折叠功能。
  在平常的写文档过程中,对于大段的文字、段落需要将其折叠,查看的时候打开折叠即可。Markdown也支持该功能,具体示例如下:

<details>
  <summary> 点击此区域标题:查看详细内容 </summary>
  <p> - 测试文本段落 </p>
  <pre><code>  title,value,callBack可以缺省  </code>  </pre>
</details>

CSDN的博客文档显示不出来。。。可直接复制上述代码例子到自己的Markdown编辑器中测试即可,在typora最新版上可正常显示。

参考资料:
1.HTML Support in Typora

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值