慢慢补:)
##0.语法及常见错误
所有公式都需要被一个或两个美元符号$
括起来(下面的有些语句可能会省略两边的$
),例如$x=a$
x = a x=a x=a和$$x=a$$
x = a x=a x=a 它们分别代表行内公式和行间公式。有一些特定的样式可以由\begin{}
和 \end{}
括起来,例如数组,矩阵,等等。此处{}里填的就是这些样式的名字,例如数组,就是用\begin{array}
和 \end{array}
括起来表示的,像是这样\begin{array} {c|c} \text{this}&\text{is}\ \hline
\text{an}&\text{array}\end{array}对,array也可以用来表示表格!
上述代码是
\begin{array} {c|c} \text{this}&\text{is}\\
\hline
\text{an}&\text{array}\end{array}
语法上要注意的是,{}
代表括起来的东西作为一个整体,如果没有这个括号,例如\begin array
,就会被理解成\begin a
,而这又是一个不存在的命令,就无法解析。另外的例子还有,在表示下标时用$x_{abc}$
的结果为 x a b c x_{abc} xabc而用$x_abc$
的结果为 x a b c x_abc xabc。以及如果\begin{array}
和 \end{array}
之间存在了一个空行,那么它们就没法括在一起,也是语法错误。
公式的基本排版有行中和行间两种。行中公式放在文中与其它文字混编,行间公式单独成行。有点像css样式里的block和inline block
行中公式用一个美元符号括起:\$数学公式\$
行间公式则用两个美元符号括起:\$\$数学公式\$\$
例1:
$y=x^2$
----- y = x 2 y=x^2 y=x2
$$y=x^2$$
----- y = x 2 y=x^2 y=x2
For longer calculations (or referring to other post’s results) it is convenient to use the tagging/labelling/referencing system. To tag an equation use \tag{yourtag}, and if you want to refer to that tag later on, add \label{somelabel} right after the \tag. It is not necessary that yourtag and somelabel are the same, but it usually is more convenient to do so:
KaTeX parse error: Expected 'EOF', got '\label' at position 22: …x^2-y^3 \tag{*}\̲l̲a̲b̲e̲l̲{*}
a:=x2−y3(*)
In order to refer to an equation, just use \eqref{somelabel}
KaTeX parse error: Expected '}', got '\eqref' at position 18: …+y^3 \stackrel{\̲e̲q̲r̲e̲f̲{*}}= x^2
a+y3=(*)x2
or \ref{somelabel}
Equations are usually referred to as KaTeX parse error: Expected 'EOF', got '\eqref' at position 1: \̲e̲q̲r̲e̲f̲{*}, but you can also use KaTeX parse error: Expected 'EOF', got '\ref' at position 1: \̲r̲e̲f̲{*}.
Equations are usually referred to as (*), but you can also use *.
As you can see, references are even turned into hyperlinks, which you can use externally as well, e.g. like this. Note that you can also reference labels in other posts as long as they appear on the same site, which is especially useful when referring to a question with multiple equations, or when commenting on a post.
Due to a bug blocks containing a \label will break in preview, as a workaround you can put \def\label#1{} in your post while editing and remove that on submission - unfortunately this means you won’t spot misspelled references before submitting… Just don’t forget to remove that \def again
###1.1.6. 高亮公式
To highlight an equation, \bbox can be used. E.g,
KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[yellow] { e^x=…
produces
ex=limn→∞(1+xn)n(1)
By default, the bounding box is “tight”, so it doesn’t extend beyond the characters used in the formula. You can add a little space around the equation by adding a measurement after the color. E.g.,
KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[yellow,5px] { …
produces
ex=limn→∞(1+xn)n(1)
To add a border, use
KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[5px,border:2px…
produces
ex=limn→∞(1+xn)n(2)
You can do both border and background, as well:
KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[yellow,5px,bor…
produces
ex=limn→∞(1+xn)n(1)
mathjax实际上不支持Latex的这里的表格,在mathjax中其实是数组,但是它能实现类似表格的排版功能,因此也把它归类于表格吧。可以使用$$\begin{array}{列样式}...\end{array}$$
这样的形式来创建表格,列样式clr
分别表示居中,左,右对齐,还可以使用|
表示一条竖线。表格中各行使用\\
分隔,各列使用&
分隔,使用\hline
在本行前加入一条直线。
$$\begin{array}
{c|lcr} n & \text{Left} & \text{Center} & \text{Right} \\
2 & -1 & 189 & -8 \\
3 & -20 & 2000 & 1+10i \\
\end{array}$$
n Left Center Right 1 0.24 1 125 2 − 1 189 − 8 3 − 20 2000 1 + 10 i \begin{array}{c|lcr} n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1+10i \\ \end{array} n123Left0.24−1−20Center11892000Right125−81+10i
一个复杂的例子如下:
$$\begin{array} {c}
% inner horizontal array of arrays
\begin{array} {cc}
% inner array of minimum values
\begin{array} {c|cccc}
\text{min} & 0 & 1 & 2 & 3\\
\hline
0 & 0 & 0 & 0 & 0\\
1 & 0 & 1 & 1 & 1\\
2 & 0 & 1 & 2 & 2\\
3 & 0 & 1 & 2 & 3
\end{array}
&
% inner array of maximum values
\begin{array} {c|cccc}
\text{max}&0&1&2&3\\
\hline
0 & 0 & 1 & 2 & 3\\
1 & 1 & 1 & 2 & 3\\
2 & 2 & 2 & 2 & 3\\
3 & 3 & 3 & 3 & 3
\end{array}
\end{array}
\\
% inner array of delta values
\begin{array} {c|cccc}
\Delta&0&1&2&3\\
\hline
0 & 0 & 1 & 2 & 3\\
1 & 1 & 0 & 1 & 2\\
2 & 2 & 1 & 0 & 1\\
3 & 3 & 2 & 1 & 0
\end{array}
\end{array}$$
min 0 1 2 3 0 0 0 0 0 1 0 1 1 1 2 0 1 2 2 3 0 1 2 3 max 0 1 2 3 0 0 1 2 3 1 1 1 2 3 2 2 2 2 3 3 3 3 3 3 Δ 0 1 2 3 0 0 1 2 3 1 1 0 1 2 2 2 1 0 1 3 3 2 1 0 \begin{array} {c} % inner horizontal array of arrays \begin{array} {cc} % inner array of minimum values \begin{array} {c|cccc} \text{min} & 0 & 1 & 2 & 3\\ \hline 0 & 0 & 0 & 0 & 0\\ 1 & 0 & 1 & 1 & 1\\ 2 & 0 & 1 & 2 & 2\\ 3 & 0 & 1 & 2 & 3 \end{array} & % inner array of maximum values \begin{array} {c|cccc} \text{max}&0&1&2&3\\ \hline 0 & 0 & 1 & 2 & 3\\ 1 & 1 & 1 & 2 & 3\\ 2 & 2 & 2 & 2 & 3\\ 3 & 3 & 3 & 3 & 3 \end{array} \end{array} \\ % inner array of delta values \begin{array} {c|cccc} \Delta&0&1&2&3\\ \hline 0 & 0 & 1 & 2 & 3\\ 1 & 1 & 0 & 1 & 2\\ 2 & 2 & 1 & 0 & 1\\ 3 & 3 & 2 & 1 & 0 \end{array} \end{array} min012300000101112012230123max012300123111232222333333Δ012300123110122210133210
Commutative diagrams
AMScd diagrams must start with a “require”:
KaTeX parse error: Expected 'EOF', got '\require' at position 1: \̲r̲e̲q̲u̲i̲r̲e̲{AMScd}
\begin{CD}
A @>a>> B\
@V b V V= @VV c V\
C @>>d> D
\end{CD}
to get this diagram:
Ab⏐↓⏐C−→−−−−a=−→−−−−dB⏐↓⏐cD
@>>> is used for arrow right
@<<< is used for arrow left
@VVV is used for arrow down
@AAA is used for arrow up
@= is used for horizontal double line
@| is used for vertical double line
@. is used for no arrow
Another example:
\begin{CD}
A @>>> B @>{\text{very long label}}>> C \\
@. @AAA @| \\
D @= E @<<< F
\end{CD}
AD−→−−−−======B↑⏐⏐E−→−−−−−−−very long label←−−−−−−−−C∥∥F
Long labels increase the length of the arrow and in this version also automatically increase corresponding arrows.
KaTeX parse error: Expected 'EOF', got '\require' at position 1: \̲r̲e̲q̲u̲i̲r̲e̲{AMScd}
\begin{CD}
RCOHR’SO_3Na @>{\text{Hydrolysis, Δ , D i l . H C l \Delta, Dil.HCl Δ,Dil.HCl}}>> (RCOR’)+NaCl+SO_2+ H_2O
\end{CD}
RCOHR′SO3Na−→−−−−−−−−−−−Hydrolysis,Δ,Dil.HCl(RCOR′)+NaCl+SO2+H2O
英文名称 大写 代码 常用表意 小写 代码 常用表意 a l p h a A A α \ a l p h a b e t a B B β \ b e t a g a m m a Γ \ G a m m a γ \ g a m m a d e l t a Δ A δ \ d e l t a e p s i l o n E E ϵ \ e p s i l o n z e t a Z Z ζ \ z e t a e t a H H η \ e t a t h e t a Θ \ T h e t a θ \ t h e t a i o t a I I ι \ i o t a k a p p a K k a p p a κ \ k a p p a l a m b d a Λ \ L a m b d a λ \ l a m b d a m u M M μ \ m u 期望 n u N N ν \ n u x i Ξ \ X i ξ \ x i o m i c r o n O O ο \ o m i c r o n p i Π \ P i π \ p i r h o P P ρ \ r h o 密 度 s i g m a Σ \ S i g m a 求 和 符 号 σ \ s i g m a t a u T T τ \ t a u u p s i l o n Υ \ U p s i l o n υ \ u p s i l o n p h i Φ \ P h i ϕ \ p h i c h i X x χ \ c h i p s i Φ \ P s i ψ \ p s i o m e g a Ω \ O m e g a ω \ o m e g a \begin{array}{cccccc} \text{英文名称} &\text{大写} &\text{代码}&\text{常用表意} &\text{小写} &\text{代码}&\text{常用表意} \\ \hline alpha & A & A && \alpha & \backslash{alpha}&\\ \hline beta& B & B && \beta & \backslash{beta}&\\ \hline gamma & \Gamma & \backslash{Gamma } && \gamma & \backslash{gamma }&\\ \hline delta & \Delta & A & &\delta & \backslash{delta}&\\ \hline epsilon& E & E& &\epsilon& \backslash{epsilon}&\\ \hline zeta& Z & Z && \zeta & \backslash{zeta}&\\ \hline eta& H & H & &\eta& \backslash{eta}&\\ \hline theta & \Theta & \backslash{Theta} & &\theta & \backslash{theta }&\\ \hline iota& I & I & &\iota& \backslash{iota}&\\ \hline kappa& K & kappa & &\kappa& \backslash{kappa}&\\ \hline lambda & \Lambda & \backslash{Lambda } && \lambda & \backslash{lambda }&\\ \hline mu& M & M && \mu& \backslash{mu}&\text{期望}\\ \hline nu & N & N & &\nu& \backslash{nu}&\\ \hline xi& \Xi & \backslash{Xi}& &\xi& \backslash{xi}&\\ \hline omicron & O & O && \omicron& \backslash{omicron}&\\ \hline pi & \Pi & \backslash{Pi} & &\pi & \backslash{pi}&\\ \hline rho & P & P & &\rho& \backslash{rho}&密度\\ \hline sigma& \Sigma & \backslash{Sigma } &求和符号& \sigma& \backslash{sigma}&\\ \hline tau & T & T && \tau& \backslash{tau}&\\ \hline upsilon& \Upsilon & \backslash{Upsilon} && \upsilon& \backslash{upsilon}&\\ \hline phi& \Phi & \backslash{Phi} && \phi& \backslash{phi}&\\ \hline chi& X & x && \chi& \backslash{chi}&\\ \hline psi& \Phi & \backslash{Psi} && \psi& \backslash{psi}&\\ \hline omega & \Omega & \backslash{Omega } && \omega & \backslash{omega }&\\ \end{array} 英文名称alphabetagammadeltaepsilonzetaetathetaiotakappalambdamunuxiomicronpirhosigmatauupsilonphichipsiomega大写ABΓΔEZHΘIKΛMNΞOΠPΣTΥΦXΦΩ代码AB\GammaAEZH\ThetaIkappa\LambdaMN\XiO\PiP\SigmaT\Upsilon\Phix\Psi\Omega常用表意求和符号小写αβγδϵζηθικλμνξοπρστυϕχψω代码\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda\mu\nu\xi\omicron\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega常用表意期望密度
累加:$\sum_{i=1}^nX_i$
∑ i = 1 n X i \sum_{i=1}^nX_i ∑i=1nXi
累乘:$\prod_{i=1}^nX_i$
∏ i = 1 n X i \prod_{i=1}^nX_i ∏i=1nXi
积分:$\int_{-\infty}^{\infty}x\,dx$
∫ − ∞ ∞ x   d x \int_{-\infty}^{\infty}x\,dx ∫−∞∞xdx,二重$\iint_{-\infty}^{\infty}xy\,dx\,dy$
∬ x y   d x   d y \iint xy\,dx\,dy ∬xydxdy,以此类推。如果多重积分要强调各自的上下限那还是得按一重积分分开写。
曲线积分:$\ointf\,ds$
∮ f   d s \oint f\,ds ∮fds
曲面积分:不知道。
$\lt \gt \le \ge \neq \not\lt$
< > ≤ ≥ ≠ ̸ < \lt \gt \le \ge \neq \not\lt <>≤≱≠<
$\cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing$
∪ ∩ ∖ ⊂ ⊆ ⊊ ⊃ ∈ ∉ ∅ ∅ \cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing ∪∩∖⊂⊆⊊⊃∈∈/∅∅
$\land \lor \lnot \forall \exists \top \bot \vdash \vDash $
$\land \lor \lnot \forall \exists \top \bot \vdash \vDash $
$\to \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto$
$\to \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto $
上下结构:
帽子:单个字符的窄帽子$\hat x$
x ^ \hat {x} x^ 和多个字符的宽$\widehat {xy}$
x y ^ \widehat {xy} xy 。当然,太宽也不好看,所以限制了最多只能帽下4个字符 w a k a k a ^ \widehat {wakaka} wakaka 。
顶上加弯弯(反正我老师这样叫的~~):$\tilde x$
, x ~ \tilde{x} x~。只能对单个字符。
杠:用$\bar x$
搭 ˉ \bar {搭} 搭ˉ对单个字符,用$\overline {搭搭搭搭}$
搭 搭 搭 搭 ‾ \overline {搭搭搭搭} 搭搭搭搭,对多个字符。这个倒是没有限制个数。
如果把这个看成汉语拼音声调的一声的话,下面把另外三声也补上吧:
二声:$\acute {答}$´
, 答 ˊ \acute {答} 答ˊ。
三声:$\check {打}$
, 打 ˇ \check {打} 打ˇ。
四声:$\grave {大}$
, 大 ˋ \grave {大} 大ˋ。
矢量箭头:$\vec x$
x z z z ⃗ \vec {xzzz} xzzz ,这个倒是可以放两个字符:$\vec {nihao}$
n i h a o ⃗ \vec {nihao} nihao,还有个叫顶右向箭头的同类,可以放下多个字符:$\overrightarrow {woshihaoren}$
w o s h i h a o r e n → \overrightarrow {woshihaoren} woshihaoren。
再来一个顶部双向箭头:$\overleftrightarrow {rangshijiechongmanai}$
r a n g s h i j i e c h o n g m a n a i ↔ \overleftrightarrow {rangshijiechongmanai} rangshijiechongmanai 。
顶上加空心点:$\mathring{A}$
, A ˚ \mathring{A} A˚。
顶上加实心点:$\dot{x^2}+x\ddot{x}$
, x 2 ˙ + x x ¨ \dot{x^2}+x\ddot{x} x2˙+xx¨,\dot代表单点,\ddot代表双点。最多可以四个点KaTeX parse error: Expected 'EOF', got '\dddot' at position 16: \dot{x}\ddot{x}\̲d̲d̲d̲o̲t̲{x}\ddddot{x}。
表示上下结构的通法:$\overset{above}{below}$
b e l o w a b o v e \overset{above}{below} belowabove,可以随意填符号对号入座,例如 A @ \overset{@}{A} A@ B ⋆ \overset{\star}{B} B⋆等等。
\star \ast \oplus \circ \bullet : ⋆ ∗ ⊕ ∘ ∙
\infty \aleph_o \nabla \partial \Im \Re : ∞ ℵo ∇ ∂ I R
模运算 \pmode , 如 a \equiv b \pmod n : a≡b(modn)
省略符号
用\mathbb{内容}
或 \Bbb{内容}
表示 "blackboard bold"黑板加粗体:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathbb {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathbb {abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
此字体经常用来表示实数、整数、有理数、复数。
用\mathbf{内容}
表示 "boldface"大脸体:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathbf{abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
用\mathtt{内容}
表示 "typewriter"打字机体:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathtt {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathtt {abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
用\mathrm{内容}
表示罗马体:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathrm{abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
用\mathsf {内容}
表示 sans-serif 体:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathsf {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathsf {abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
用\mathcal {内容}
表示"calligraphic" 书法字母:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathcal {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathcal {abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
用\mathscr {内容}
表示手迹字母:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathscr {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathscr {abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
用\mathfrak {内容}
表示"Fraktur" 老德国风格字母:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \mathfrak {ABCDEFGHIJKLMNOPQRSTUVWXYZ} ABCDEFGHIJKLMNOPQRSTUVWXYZ
a b c d e f g h i j k l m n o p q r s t u v w x y z \mathfrak {abcdefghijklmnopqrstuvwxyz} abcdefghijklmnopqrstuvwxyz
Use \require{cancel} in the first formula in your post that requires cancelling; you need it only once per page. Then use:
y+\cancel{x}\cancel{y+x}y+\bcancel{x}y+\xcancel{x}y+\cancelto{0}{x}\frac{1\cancel9}{\cancel95} = \frac15y+xy+xy+xy+xy+x01995=15
Use \require{enclose} for the following:
\enclose{horizontalstrike}{x+y}\enclose{verticalstrike}{\frac xy}\enclose{updiagonalstrike}{x+y}\enclose{downdiagonalstrike}{x+y}\enclose{horizontalstrike,updiagonalstrike}{x+y}x+yxyx+yx+yx+y
\enclose can also produce enclosing boxes, circles, and other notations; see MathML menclose documentation for a complete list.
\cancelto{\cancelto{\cancelto{x{2+x}}{\cancelto{x2}{x}+4}}4}0