LaTeX 公式基础

Published at 2022-09-15
Last update over 365 days agoNo English versionLicensed under CC BY-NC-SA 4.0latexmathnoteprogramming-language

用 LaTeX 写数学公式的时候,总记不住一些写法,故在此记录学习笔记。

常见符号

希腊字母

大小写希腊字母的写法区别就在于 LaTeX 符号的首字母大小写。而如果使用 MathJax,这样直接将小写希腊字母的首字母大写的写法是无效的(表中带有"或 \mathrm{...}"的那些),必须使用 \mathrm{...}

若要使用斜体可以在前面加上 var 前缀,例如 \varGamma 可以用来显示 Γ\varGamma 。也可以使用 \mathit{...},例如使用 \mathit{\Gamma} 来显示 Γ\mathit{\Gamma},使用 \mathit{A} 来显示 A\mathit{A}

大写字母 LaTeX 写法 小写字母 LaTeX 写法
A\mathrm{A} \Alpha 或 \mathrm{A} α\alpha \alpha
B\mathrm{B} \Beta 或 \mathrm{B} β\beta \beta
Γ\Gamma \Gamma γ\gamma \gamma
Δ\Delta \Delta δ\delta \delta
E\mathrm{E} \Epsilon 或 \mathrm{E} ϵ\epsilon \epsilon
Z\mathrm{Z} \Zeta 或 \mathrm{Z} ζ\zeta \zeta
H\mathrm{H} \Eta 或 \mathrm{H} η\eta \eta
Θ\Theta \Theta θ\theta \theta
I\mathrm{I} \Iota 或 \mathrm{I} ι\iota \iota
K\mathrm{K} \Kappa 或 \mathrm{K} κ\kappa \kappa
Λ\Lambda \Lambda λ\lambda \lambda
M\mathrm{M} \Mu 或 \mathrm{M} μ\mu \mu
N\mathrm{N} \Nu 或 \mathrm{N} ν\nu \nu
Ξ\Xi \Xi ξ\xi \xi
O\mathrm{O} \Omicron 或 \mathrm{O} ο\omicron \omicron
Π\Pi \Pi π\pi \pi
P\mathrm{P} \Rho 或 \mathrm{P} ρ\rho \rho
Σ\Sigma \Sigma σ\sigma \sigma
T\mathrm{T} \Tau 或 \mathrm{T} τ\tau \tau
Υ\Upsilon \Upsilon υ\upsilon \upsilon
Φ\Phi \Phi ϕ\phi \phi
X\mathrm{X} \Chi 或 \mathrm{X} χ\chi \chi
Ψ\Psi \Psi ψ\psi \psi
Ω\Omega \Omega ω\omega \omega

运算符

渲染结果 LaTeX 写法 记法
±\pm \pm 英文:Plus + Minus
\mp \mp 英文:Minus + Plus
×\times \times times 就有“乘”的意思
÷\div \div 6÷3=26 \div 3=2 表述为:Six divided by two is three.
\geq \geq “大于等于”的英文:greater than or equal to
\leq \leq “小于等于”的英文:less than or equal to
\neq \neq “不等于”的英文:not equal to
\approx \approx “约等于”的英文:approximately equal to
\propto \propto “正比于”的英文:be proportional to
x\lceil x \rceil \lceil x \rceil
x\lfloor x \rfloor \lfloor x \rfloor

圈与点

渲染结果 LaTeX 写法
^{\circ} \degree 或 ^{\circ}
\circ \circ
\cdot \cdot
\cdotp \cdotp
\cdots \cdots
\ddots \ddots
\bullet \bullet
a˙\dot{a} \dot{a}

箭头

参考 MathJax 支持的 Latex 符号总结 (各种箭头符号)_liyuanbhu 的博客-CSDN 博客

数理逻辑

名称 渲染结果 LaTeX 写法
否定 ¬\neg \neg
合取 \land \land 或 \wedge
析取 \lor \lor 或 \vee
双条件     \iff \iff
全称量词 \forall \forall
存在量词 \exists \exists

集合论

名称 渲染结果 LaTeX 写法
属于 \in \in
不属于 \notin \notin
包含 \subseteq \subseteq
真包含 \subset \subset
\supseteq \supseteq
\supset \supset
空集 \varnothing \varnothing
全集 E\mathit{E} \mathit{E}
幂集 P\mathcal{P} \mathcal{P}
\cap \cap
\cup \cup
- -
绝对补 \sim \sim
对称差 \oplus \oplus

序关系

渲染结果 LaTeX 写法
\prec \prec
\succ \succ
\preccurlyeq \preccurlyeq
\succcurlyeq \succcurlyeq

上下标的输入方法

上标 ^ ,下标 _,例如:

X_1 = a^2,X_2 = b^2

X1=a2,X2=b2X_1 = a^2,X_2 = b^2

同时上下标,只要连续输入 _^ 即可,例如:

X_3^2 = 9,X_4^2 = 16

X32=9,X42=16X_3^2 = 9,X_4^2 = 16

上下标如果由多字符组成,则需要加上花括号,例如:

X_{i+j}^{k+l}

Xi+jk+lX_{i+j}^{k+l}

左边的上下标只要写在前面就行了,例如:

^a_bX^c_d

baXdc^a_bX^c_d

所以除了通过 \degree 的方法写度数,也可以通过上标的方法达到类似效果:

45\degree,90^{\circ}

45°,9045\degree,90^{\circ}

“上升”:

X^{X^{X^{X^{X^{X}}}}}

XXXXXXX^{X^{X^{X^{X^{X}}}}}

”下降“:

X_{X_{X_{X_{X_{X}}}}}

XXXXXXX_{X_{X_{X_{X_{X}}}}}

分式

\frac{a}{b}

ab\frac{a}{b}

根式

渲染结果 LaTeX 写法
2\sqrt{2} \sqrt{2}
23\sqrt[3]{2} \sqrt[3]{2}
\sqrt[b]{a}

ab\sqrt[b]{a}

矩阵

使用 \left\right 来指定左右两边用什么框;& 是对齐符号;\\ 表示换行(有的时候要转义的话则是四个)。

\left[
\begin{matrix}
0      &0      &0      &\cdots &0      \\\\
0      &1      &0      &\cdots &0      \\\\
0      &0      &1      &\cdots &0      \\\\
\vdots &\vdots &\vdots &\ddots &\vdots \\\\
0      &0      &0      &\cdots &1
\end{matrix}
\right]

[0000010000100001]\left[ \begin{matrix} 0 &0 &0 &\cdots &0 \\ 0 &1 &0 &\cdots &0 \\ 0 &0 &1 &\cdots &0 \\ \vdots &\vdots &\vdots &\ddots &\vdots \\ 0 &0 &0 &\cdots &1 \end{matrix} \right]

分段

Cost(h_\theta(x), y)=
\begin{cases}
-log(h_\theta(x)) & \text{if }y=1 \\\\
-log(1-h_\theta(x)) & \text{if }y=0 \\\\
\end{cases}

Cost(hθ(x),y)={log(hθ(x))if y=1log(1hθ(x))if y=0Cost(h_\theta(x), y)= \begin{cases} -log(h_\theta(x)) & \text{if }y=1 \\ -log(1-h_\theta(x)) & \text{if }y=0 \\ \end{cases}

其他常用符号写法

渲染结果 LaTeX 写法 记法
\to \to
\infty \infty ”无穷“的英文:infinity
i=05\sum_{i=0}^{5} \sum_{i=0}^{5}
limx0\lim_{x \to 0} \lim_{x \to 0}
ab\int_a^b \int_a^b “积分”的英文:integral
\partial \partial
\bot \bot
\perp \perp ”相互垂直“的英文:perpendicular to each other
a˙\dot{a} \dot{a}
a^\hat{a} \hat{a}
aˉ\bar{a} \bar{a}
a\vec{a} \vec{a} ”向量“的英文:vector
a~\tilde{a} \tilde{a} ”波浪号“的英文:tilde

使用符号的习惯与约定

来自 在数学环境中,\LaTeX 命令是否应该包在 \mathrm 中? - Emrys 的回答 - 知乎 的参考,再结合我自己的习惯:

  • 标量 ii: $i$
  • 向量 x\mathbf{x}x\vec{x}: \mathbf{x}\vec{x}
  • 矩阵 R\mathbf{R}: \mathbf{R}
  • 用文字表示的变量名 Duration\mathrm{Duration}: \mathrm{Duration}
  • 用文字表示的函数名 Sigmoid\operatorname{Sigmoid}: \operatorname{Sigmoid}

参考资料