MathJax和相關的Latex語法。

慢慢補:)
##0.語法及常見錯誤

所有公式都需要被一個或兩個美元符號$括起來(下面的有些語句可能會省略兩邊的$),例如$x=a$x=ax=a$$x=a$$x=ax=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}$的結果爲xabcx_{abc}而用$x_abc$的結果爲xabcx_abc。以及如果\begin{array}\end{array}之間存在了一個空行,那麼它們就沒法括在一起,也是語法錯誤。

1. 公式樣式、表格、圖表和矩陣

1.1. 公式

1.1.1. 基本排版

公式的基本排版有行中和行間兩種。行中公式放在文中與其它文字混編,行間公式單獨成行。有點像css樣式裏的block和inline block
行中公式用一個美元符號括起:\$數學公式\$
行間公式則用兩個美元符號括起:\$\$數學公式\$\$
例1:
$y=x^2$ ----- y=x2y=x^2
$$y=x^2$$ ----- y=x2y=x^2

1.1.2. 對齊的公式

1.1.3. 分類表達式

1.1.4. 方程組

1.1.5. 標籤和引用

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)

1.2. 表格

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

nLeftCenterRight10.24112521189832020001+10i\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}
一個複雜的例子如下:

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

1.3. 矩陣

1.3.1. 基本用法

1.3.1. 加括號

1.3.1. 省略元素

1.3.1. 基本用法

1.4. 圖表

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,Δ,Dil.HCl\Delta, Dil.HCl}}>> (RCOR’)+NaCl+SO_2+ H_2O
\end{CD}
RCOHR′SO3Na−→−−−−−−−−−−−Hydrolysis,Δ,Dil.HCl(RCOR′)+NaCl+SO2+H2O

1.6其他

1.6.1. 長除法

2. 符號

2.1. 希臘字母和希伯來字母

英文名稱大寫代碼常用表意小寫代碼常用表意alphaAAα\alphabetaBBβ\betagammaΓ\Gammaγ\gammadeltaΔAδ\deltaepsilonEEϵ\epsilonzetaZZζ\zetaetaHHη\etathetaΘ\Thetaθ\thetaiotaIIι\iotakappaKkappaκ\kappalambdaΛ\Lambdaλ\lambdamuMMμ\mu期望nuNNν\nuxiΞ\Xiξ\xiomicronOOο\omicronpiΠ\Piπ\pirhoPPρ\rhosigmaΣ\Sigmaσ\sigmatauTTτ\tauupsilonΥ\Upsilonυ\upsilonphiΦ\Phiϕ\phichiXxχ\chipsiΦ\Psiψ\psiomegaΩ\Omegaω\omega\begin{array}{cccccc} \text{英文名稱} &amp;\text{大寫} &amp;\text{代碼}&amp;\text{常用表意} &amp;\text{小寫} &amp;\text{代碼}&amp;\text{常用表意} \\ \hline alpha &amp; A &amp; A &amp;&amp; \alpha &amp; \backslash{alpha}&amp;\\ \hline beta&amp; B &amp; B &amp;&amp; \beta &amp; \backslash{beta}&amp;\\ \hline gamma &amp; \Gamma &amp; \backslash{Gamma } &amp;&amp; \gamma &amp; \backslash{gamma }&amp;\\ \hline delta &amp; \Delta &amp; A &amp; &amp;\delta &amp; \backslash{delta}&amp;\\ \hline epsilon&amp; E &amp; E&amp; &amp;\epsilon&amp; \backslash{epsilon}&amp;\\ \hline zeta&amp; Z &amp; Z &amp;&amp; \zeta &amp; \backslash{zeta}&amp;\\ \hline eta&amp; H &amp; H &amp; &amp;\eta&amp; \backslash{eta}&amp;\\ \hline theta &amp; \Theta &amp; \backslash{Theta} &amp; &amp;\theta &amp; \backslash{theta }&amp;\\ \hline iota&amp; I &amp; I &amp; &amp;\iota&amp; \backslash{iota}&amp;\\ \hline kappa&amp; K &amp; kappa &amp; &amp;\kappa&amp; \backslash{kappa}&amp;\\ \hline lambda &amp; \Lambda &amp; \backslash{Lambda } &amp;&amp; \lambda &amp; \backslash{lambda }&amp;\\ \hline mu&amp; M &amp; M &amp;&amp; \mu&amp; \backslash{mu}&amp;\text{期望}\\ \hline nu &amp; N &amp; N &amp; &amp;\nu&amp; \backslash{nu}&amp;\\ \hline xi&amp; \Xi &amp; \backslash{Xi}&amp; &amp;\xi&amp; \backslash{xi}&amp;\\ \hline omicron &amp; O &amp; O &amp;&amp; \omicron&amp; \backslash{omicron}&amp;\\ \hline pi &amp; \Pi &amp; \backslash{Pi} &amp; &amp;\pi &amp; \backslash{pi}&amp;\\ \hline rho &amp; P &amp; P &amp; &amp;\rho&amp; \backslash{rho}&amp;密度\\ \hline sigma&amp; \Sigma &amp; \backslash{Sigma } &amp;求和符號&amp; \sigma&amp; \backslash{sigma}&amp;\\ \hline tau &amp; T &amp; T &amp;&amp; \tau&amp; \backslash{tau}&amp;\\ \hline upsilon&amp; \Upsilon &amp; \backslash{Upsilon} &amp;&amp; \upsilon&amp; \backslash{upsilon}&amp;\\ \hline phi&amp; \Phi &amp; \backslash{Phi} &amp;&amp; \phi&amp; \backslash{phi}&amp;\\ \hline chi&amp; X &amp; x &amp;&amp; \chi&amp; \backslash{chi}&amp;\\ \hline psi&amp; \Phi &amp; \backslash{Psi} &amp;&amp; \psi&amp; \backslash{psi}&amp;\\ \hline omega &amp; \Omega &amp; \backslash{Omega } &amp;&amp; \omega &amp; \backslash{omega }&amp;\\ \end{array}

2.2. 運算符和操作符

2.2.1. 比較運算符

2.2.2. 集合運算符

2.2.3. 計算運算符

2.2.4. 求和、積及積分運算符

累加:$\sum_{i=1}^nX_i$i=1nXi\sum_{i=1}^nX_i
累乘:$\prod_{i=1}^nX_i$i=1nXi\prod_{i=1}^nX_i
積分:$\int_{-\infty}^{\infty}x\,dx$x&ThinSpace;dx\int_{-\infty}^{\infty}x\,dx,二重$\iint_{-\infty}^{\infty}xy\,dx\,dy$xy&ThinSpace;dx&ThinSpace;dy\iint xy\,dx\,dy,以此類推。如果多重積分要強調各自的上下限那還是得按一重積分分開寫。
曲線積分:$\ointf\,ds$f&ThinSpace;ds\oint f\,ds
曲面積分:不知道。

2.2.5. 邏輯運算符及推導符號

$\lt \gt \le \ge \neq \not\lt$
&lt;&gt;̸&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 $

2.2.6. 三角運算符

2.2.7. 對數運算符

2.2.7.橫線、箭頭、帽子等修飾、強調符號

上下結構:
帽子:單個字符的窄帽子$\hat x$ x^\hat {x} 和多個字符的寬$\widehat {xy}$xy^\widehat {xy}。當然,太寬也不好看,所以限制了最多隻能帽下4個字符wakaka^\widehat {wakaka}
頂上加彎彎(反正我老師這樣叫的~~):$\tilde x$ ,x~\tilde{x}。只能對單個字符。
槓:用$\bar x$ ˉ\bar {搭}對單個字符,用$\overline {搭搭搭搭}$\overline {搭搭搭搭},對多個字符。這個倒是沒有限制個數。
如果把這個看成漢語拼音聲調的一聲的話,下面把另外三聲也補上吧:
二聲:$\acute {答}$´,ˊ\acute {答}
三聲:$\check {打}$,ˇ\check {打}
四聲:$\grave {大}$,ˋ\grave {大}

矢量箭頭:$\vec x$ xzzz\vec {xzzz} ,這個倒是可以放兩個字符:$\vec {nihao}$ nihao\vec {nihao},還有個叫頂右向箭頭的同類,可以放下多個字符:$\overrightarrow {woshihaoren}$woshihaoren\overrightarrow {woshihaoren}
再來一個頂部雙向箭頭:$\overleftrightarrow {rangshijiechongmanai}$rangshijiechongmanai\overleftrightarrow {rangshijiechongmanai}
頂上加空心點:$\mathring{A}$A˚\mathring{A}
頂上加實心點:$\dot{x^2}+x\ddot{x}$x2˙+xx¨\dot{x^2}+x\ddot{x},\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}$belowabove\overset{above}{below},可以隨意填符號對號入座,例如A@\overset{@}{A}B\overset{\star}{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)
省略符號

2.3轉義字符

2.x. 其他

3.字體

3.1. 加粗斜體和下劃線

3.2字體變形

\mathbb{內容}\Bbb{內容} 表示 "blackboard bold"黑板加粗體:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathbb {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathbb {abcdefghijklmnopqrstuvwxyz}
此字體經常用來表示實數、整數、有理數、複數。

\mathbf{內容} 表示 "boldface"大臉體:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathbf{abcdefghijklmnopqrstuvwxyz}

\mathtt{內容}表示 "typewriter"打字機體:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathtt {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathtt {abcdefghijklmnopqrstuvwxyz}

\mathrm{內容}表示羅馬體:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathrm{abcdefghijklmnopqrstuvwxyz}

\mathsf {內容}表示 sans-serif 體:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathsf {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathsf {abcdefghijklmnopqrstuvwxyz}

\mathcal {內容}表示"calligraphic" 書法字母:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathcal {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathcal {abcdefghijklmnopqrstuvwxyz}

\mathscr {內容}表示手跡字母:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathscr {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathscr {abcdefghijklmnopqrstuvwxyz}

\mathfrak {內容}表示"Fraktur" 老德國風格字母:
ABCDEFGHIJKLMNOPQRSTUVWXYZ\mathfrak {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
abcdefghijklmnopqrstuvwxyz\mathfrak {abcdefghijklmnopqrstuvwxyz}

3.x. 其他

4.上下標及附加樣式

4.1. 上下標

4.1. 頂部符號

4.1. 底部符號

4.1. 劃線符號

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

4.x. 其他

發佈了31 篇原創文章 · 獲贊 12 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章