【持续更新】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$'$}

x 3 + y 3 = z 3 x^3+y^3=z^3

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

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

(1-1) x 6 + y 6 = z 6 x^6+y^6=z^6 \tag{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}
使用\eqref指令引用前面标记的锚点,使用$\eqref{eq:test}$指令将显示为: ( 1 (1 - 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}
注:如果各个方程需要在某个字符处对齐(如等号对齐),只需在所有要对齐的字符前加上 & 符号。如果不需要公式编号,只需在宏包名称后加上 * 号。

\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}

\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}

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

二、latex常见数学符号

2.1 常用数学符号

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

符号 代码 符号 代码
\sum $\sum$ × \times $\times$
i = 0 n \sum_{i=0}^n $\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} $\hat{y}$ α \alpha $\alpha$
y ˇ \check{y} $\check{y}$ β \beta $\beta$
y ˘ \breve{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} $\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}

  • 分段函数
$$
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.

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}

  • 方程组
$$
\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.

  • 线性模型
$$
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

  • 均方误差
$$
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

  • 批量梯度下降
$$
\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

  • 推导过程
$$
\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}

  • 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}

  • 带方框的等式
$$
\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}

  • 最大(最小)操作符
$$
\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}

  • 求极限
$$
\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}

lim a 1 a \begin{aligned} \lim\nolimits_{a\to \infty} \tfrac{1}{a} \end{aligned}

  • 求积分
$$
\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}

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

  • 求累加
$$
\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}

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

  • 求累乘
$$
  \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}

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

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

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

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

2.3 其他格式

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

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

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

三、总结

  在编辑的过程中,发现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

猜你喜欢

转载自blog.csdn.net/qq_18150255/article/details/88040858