文章目錄
- LaTeX編輯數學公式基本語法元素
- 1. 各類希臘字母表
- 2. 如何輸入括號和分隔符
- 3. 三角運算子
- 4. 微積分運算子
- 5. 邏輯運算子
- 6. 上下標
- 7. 根號
- 8. 省略號
- 9. 運算子
- 10. 分數
- 11. 矩陣和行列式
- 12. 行列式
- 13. 如何輸入帶分割符號的矩陣
- 14. 如何輸入向量
- 15. 如何輸入積分
- 16. 如何進行字體轉換
- 17. 如何高亮一行公式
- 18. 更改文字顏色
- 19. 添加洗掉線
- 20. 包圍公式
- 21. 箭頭
- 22. 方程式
- 23. 分隔符
- 24. 分段函式
- 25. 如何輸入一個左側對齊的條件運算式
- 26. 方程組
- 27. 如何使條件運算式適配行高
- 28. 陣列與表格使用參考之如何輸入一個陣列或表格
- 29. 陣列與表格使用參考之如何輸入一個嵌套的陣列或表格
- 案例
- 1. 線性模型
- 2. 均方誤差
- 3. 批量梯度下降
- 4. 推導程序
- 參考檔案
注意:有一些公式在csdn中無法顯示,但是在typora中可以顯示出來,可以自己在本地上的typora上使用體驗一下
LaTeX編輯數學公式基本語法元素
LaTeX中數學模式有兩種形式:inline和display,前者是指正文插入行間數學公式,后者獨立排列,可以有或沒有編號,
行間公式(inline):用 $...$ 將公式括起來
塊間公式(display):用 $$...$$ 將公式括起來,默認顯示在行中間
1. 各類希臘字母表
| 希臘字母 | 代號 | 希臘字母 | 代號 | 希臘字母 | 代號 | 希臘字母 | 代號 |
|---|---|---|---|---|---|---|---|
| α | \alpha | θ | \theta | o | o | τ | \tau |
| β | \beta | ? | \vartheta | π | \pi | υ | \upsilon |
| γ | \gamma | ι | \iota | ? | \varpi | ? | \phi |
| δ | \delta | κ | \kappa | ρ | \rho | φ | \varphi |
| ? | \epsilon | λ | \lambda | ? | \varrho | χ | \chi |
| ε | \varepsilon | μ | \mu | σ | \sigma | ψ | \psi |
| ζ | \zeta | ν | \nu | ? | \varsigma | ω | \omega |
| η | \eta | ξ | \xi | Σ | \Sigma | Ψ | \Psi |
| Γ | \Gamma | Λ | \Lambda | Υ | \Upsilon | Ω | \Omega |
| Δ | \Delta | Ξ | \Xi | Φ | \Phi | ||
| Θ | \Theta | Π | \Pi |
2. 如何輸入括號和分隔符
()、[] 和 | 表示符號本身,使用 \{\} 來表示 {} ,當要顯示大號的括號或分隔符時,要用 \left 和 \right 命令,
一些特殊的括號:
| 輸入 | 顯示 | 輸入 | 顯示 |
|---|---|---|---|
| \langle | ? \langle ? | \rangle | ? \rangle ? |
| \lceil | ? \lceil ? | \rceil | ? \rceil ? |
| \lfloor | ? \lfloor ? | \rfloor | ? \rfloor ? |
| \lbrace | { \lbrace { | \rbrace | } \rbrace } |
| \lvert | ∣ \lvert ∣ | \rvert | ∣ \rvert ∣ |
| \lVert | ∥ \lVert ∥ | \rVert | ∥ \rVert ∥ |
有時,我們需要在行內使用兩個豎杠表示向量間的某種空間距離,可以這樣寫
$\lVert \boldsymbol{X}_i - \boldsymbol{S}_j \rVert^2$ →
∥
X
i
?
S
j
∥
2
\lVert \boldsymbol{X}_i - \boldsymbol{S}_j \rVert^2
∥Xi??Sj?∥2
示例
$$
f(x,y,z) = 3y^2z \left( 3+\frac{7x+5}{1+y^2} \right)
$$
結果
f
(
x
,
y
,
z
)
=
3
y
2
z
(
3
+
7
x
+
5
1
+
y
2
)
f(x,y,z) = 3y^2z \left( 3+\frac{7x+5}{1+y^2} \right)
f(x,y,z)=3y2z(3+1+y27x+5?)
有時要用 \left. 或 \right. 進行匹配而不顯示本身,
示例
$$
\left. \frac{{\rm d}u}{{\rm d}x} \right| _{x=0}
$$
結果
d
u
d
x
∣
x
=
0
\left. \frac{{\rm d}u}{{\rm d}x} \right| _{x=0}
dxdu?∣∣∣∣?x=0?
3. 三角運算子
| 輸入 | 顯示 | 輸入 | 顯示 | 輸入 | 顯示 |
|---|---|---|---|---|---|
| \backsim | ∽ \backsim ∽ | \cong | ? \cong ? | \angle A | ∠ A \angle A ∠A |
| \sin | sin ? \sin sin | \cos | cos ? \cos cos | \tan | tan ? \tan tan |
| \csc | csc ? \csc csc | \sec | sec ? \sec sec | \cot | cot ? \cot cot |
4. 微積分運算子
| 輸入 | 顯示 | 輸入 | 顯示 | 輸入 | 顯示 |
|---|---|---|---|---|---|
| \int | ∫ \int ∫ | \iint | ? \iint ? | \iiint | ? \iiint ? |
| \partial | ? \partial ? | \oint | ∮ \oint ∮ | \prime | ′ \prime ′ |
| \lim | lim ? \lim lim | \infty | ∞ \infty ∞ | \nabla | ? \nabla ? |
5. 邏輯運算子
| 輸入 | 顯示 | 輸入 | 顯示 | 輸入 | 顯示 |
|---|---|---|---|---|---|
| \because | ∵ \because ∵ | \therefore | ∴ \therefore ∴ | \neg | ? \neg ? |
| \forall | ? \forall ? | \exists | ? \exists ? | \not\subset | ?? \not\subset ?? |
| \not< | <? \not< ?< | \not> | >? \not> ?> | \not= | =? \not= ?= |
6. 上下標
下標:$x_i$ →
x
i
x_i
xi?
上標:$x^i$ →
x
i
x^i
xi
注意 :上下標如果多余一個字母或者符號,需要用一對{}括起來:
多個字母下標:$x_{i1}$ →
x
i
1
x_{i1}
xi1?
多個字母上標:$x^{i1}$ →
x
i
1
x^{i1}
xi1
另外,如果要在左右兩邊都有上下標,可以使用 \sideset 命令;也可以簡單地在符號前面多打一個上下標,此時會以行內公式渲染,
示例:
$$
\sideset{^1_2}{^3_4}\bigotimes \quad or \quad {^1_2}\bigotimes {^3_4}
$$
結果
KaTeX parse error: Undefined control sequence: \sideset at position 2: \?s?i?d?e?s?e?t?{^1_2}{^3_4} \b…
7. 根號
根號:$\sqrt[n]{5}$ →
5
n
\sqrt[n]{5}
n5
?
8. 省略號
省略號:$\dots$ →
…
\dots
… || $\cdots$ →
?
\cdots
?
9. 運算子
基本運算子:+ - * /等可以直接輸入,其他特殊的有:
| \pm | \times | \div | \cdot | \cap | \cup | \geq | \leq | \neq | \approx | \equix |
|---|---|---|---|---|---|---|---|---|---|---|
| ± | × | ÷ | ? | ∩ | ∪ | ≥ | ≤ | ≠ \neq ?= | ≈ | ≡ |
求和:$\sum_1^n$ →
∑
1
n
\sum_1^n
∑1n?
累乘:$\prod_{n=1}^{99}x_n$ →
∏
n
=
1
99
x
n
\prod_{n=1}^{99}x_n
∏n=199?xn?
積分:$\int_1^n$ →
∫
1
n
\int_1^n
∫1n?
極限:$\lim\limits _ {x \to \infty}$ →
lim
?
x
→
∞
\lim\limits _ {x \to \infty}
x→∞lim?
10. 分數
分數的表示:$\frac{3}{8}$ →
3
8
\frac{3}{8}
83?
11. 矩陣和行列式
示例
$$
\begin{matrix}
1&x&x^2\\
1&y&y^2\\
1&z&z^2\\
\end{matrix}
$$
結果
1
x
x
2
1
y
y
2
1
z
z
2
\begin{matrix} 1&x&x^2\\ 1&y&y^2\\ 1&z&z^2\\ \end{matrix}
111?xyz?x2y2z2?
12. 行列式
使用 \cdots , \ddots , \vdots 來輸入省略符號,
示例:
$$
X=\left|
\begin{matrix}
x_{11} & x_{12} & \cdots & x_{1d}\\
x_{21} & x_{22} & \cdots & x_{2d}\\
\vdots & \vdots & \ddots & \vdots\\
x_{m1} & x_{m2} & \cdots & x_{md} \\
\end{matrix}
\right|
$$
結果
X
=
∣
x
11
x
12
?
x
1
d
x
21
x
22
?
x
2
d
?
?
?
?
x
m
1
x
m
2
?
x
m
d
∣
X=\left| \begin{matrix} x_{11} & x_{12} & \cdots & x_{1d}\\ x_{21} & x_{22} & \cdots & x_{2d}\\ \vdots & \vdots & \ddots & \vdots\\ x_{m1} & x_{m2} & \cdots & x_{md} \\ \end{matrix} \right|
X=∣∣∣∣∣∣∣∣∣?x11?x21??xm1??x12?x22??xm2???????x1d?x2d??xmd??∣∣∣∣∣∣∣∣∣?
在開頭將 matrix 替換為 pmatrix bmatrix Bmatrix vmatrix Vmatrix ,
示例
$ \begin{matrix} 1 & 2 \\ 3 & 4 \\ \end{matrix} $
$ \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ \end{pmatrix} $
$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ \end{bmatrix} $
$ \begin{Bmatrix} 1 & 2 \\ 3 & 4 \\ \end{Bmatrix} $
$ \begin{vmatrix} 1 & 2 \\ 3 & 4 \\ \end{vmatrix} $
$ \begin{Vmatrix} 1 & 2 \\ 3 & 4 \\ \end{Vmatrix} $
結果
| matrix | pmatrix | bmatrix | Bmatrix | vmatrix | Vmatrix |
|---|---|---|---|---|---|
| $ \begin{matrix} 1 & 2 \ 3 & 4 \ \end{matrix} $ | $ \begin{pmatrix} 1 & 2 \ 3 & 4 \ \end{pmatrix} $ | $ \begin{bmatrix} 1 & 2 \ 3 & 4 \ \end{bmatrix} $ | $ \begin{Bmatrix} 1 & 2 \ 3 & 4 \ \end{Bmatrix} $ | $ \begin{vmatrix} 1 & 2 \ 3 & 4 \ \end{vmatrix} $ | $ \begin{Vmatrix} 1 & 2 \ 3 & 4 \ \end{Vmatrix} $ |
13. 如何輸入帶分割符號的矩陣
示例
$$
\left[
\begin{array}{cc|c}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{array}
\right]
$$
結果
[
1
2
3
4
5
6
]
\left[ \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \\ \end{array}\right]
[14?25?36?]
其中 cc|c 代表在一個三列矩陣中的第二和第三列之間插入分割線,
14. 如何輸入向量
使用 \vec{向量} 來自動產生一個向量,也可以使用 \overrightarrow 等命令自定義字母上方的符號,
示例
$$
\vec{a} \cdot \vec{b}=0
$$
結果
a
?
?
b
?
=
0
\vec{a} \cdot \vec{b}=0
a
?b
=0
示例
$$
xy \text{ with arrows:}
\quad
\overleftarrow{xy} \;
\mid \;
\overleftrightarrow{xy} \;
\mid \;
\overrightarrow{xy}
$$
結果
x
y
with arrows:
x
y
←
??
∣
??
x
y
?
??
∣
??
x
y
→
xy \text{ with arrows:} \quad \overleftarrow{xy} \; \mid \; \overleftrightarrow{xy} \; \mid \; \overrightarrow{xy}
xy with arrows:xy
?∣xy
?∣xy
?
15. 如何輸入積分
使用 \int_積分下限^積分上限 {被積運算式} 來輸入一個積分,
示例
$$
\int_0^1 {x^2} \,{\rm d}x
$$
結果
∫
0
1
x
2
?
d
x
\int_0^1 {x^2} \,{\rm d}x
∫01?x2dx
本例中 \, 和 {\rm d} 部分可省略,但加入能使式子更美觀
16. 如何進行字體轉換
若要對公式的某一部分字符進行字體轉換,可以用 {\字體 {需轉換的部分字符}} 命令,其中 \字體 部分可以參照下表選擇合適的字體,一般情況下,公式默認為斜體字 ,
示例中 全部大寫 的字體僅大寫可用,
| 輸入 | 全字母可用 | 顯示 | 輸入 | 僅大寫可用 | 顯示 |
|---|---|---|---|---|---|
| \rm | 羅馬體 | s a m p l e \rm {sample} sample | \mathcal | 花體(數學符號等) | s a m p l e \mathcal {sample} sample |
| \it | 斜體 | s a m p l e \it {sample} sample | \mathbb | 黑板粗體(定義域等) | s a m p l e \mathbb {sample} sample |
| \bf | 粗體 | s a m p l e \bf {sample} sample | \mit | 數學斜體 | KaTeX parse error: Undefined control sequence: \mit at position 1: \?m?i?t? ?{sample} |
| \sf | 等線體 | s a m p l e \sf {sample} sample | \scr | 手寫體 | KaTeX parse error: Undefined control sequence: \scr at position 1: \?s?c?r? ?{sample} |
| \tt | 打字機體 | s a m p l e \tt {sample} sample | |||
| \frak | 舊德式字體 | s a m p l e \frak {sample} sample |
@lymd
\boldsymbol{\alpha}用來表示向量或者矩陣的加粗斜體,如向量 ,
轉換字體十分常用,例如在積分中:
示例
\begin{array}{cc}
\mathrm{Bad} & \mathrm{Better} \\
\hline \\
\int_0^1 x^2 dx & \int_0^1 x^2 \,{\rm d}x
\end{array}
結果
B
a
d
B
e
t
t
e
r
∫
0
1
x
2
d
x
∫
0
1
x
2
?
d
x
\begin{array}{cc} \mathrm{Bad} & \mathrm{Better} \\ \hline \\ \int_0^1 x^2 dx & \int_0^1 x^2 \,{\rm d}x\end{array}
Bad∫01?x2dx?Better∫01?x2dx??
注意比較兩個式子間 與 的不同,
使用 \operatorname 命令也可以達到相同的效果,
17. 如何高亮一行公式
使用 \bbox[底色, (可選)邊距, (可選)邊框 border: 框寬度 框型別 框顏色] 命令來高亮一行公式,
邊距及框寬度支持 絕對像素 px 或 相對大小 em,框型別支持 實線 solid 或 虛線 dashed,
示例
$$
\bbox[yellow]{ e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1)}
$$
結果
KaTeX parse error: Undefined control sequence: \bbox at position 2: \?b?b?o?x?[yellow]{ e^…
示例
$$
\bbox[#9ff, 5px]{ #此處向外添加 5 像素的邊距
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1)}
$$
結果
KaTeX parse error: Undefined control sequence: \bbox at position 2: \?b?b?o?x?[#9ff, 5px]{e^x…
示例
$$
#此處使用 0.5 倍行高作為邊距,附加 2 像素的實線邊框(Ctrl+Alt+Y 可見)
\bbox[#2f3542, 0.5em, border:2px solid #f1f2f6]{ \color{#f1f2f6}{e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1)}}
$$
結果
KaTeX parse error: Undefined control sequence: \bbox at position 2: \?b?b?o?x?[#2f3542, 0.5em…
18. 更改文字顏色
使用 \color{顏色}{文字} 來更改特定的文字顏色,
更改文字顏色需要瀏覽器支持 ,如果瀏覽器不知道你所需的顏色,那么文字將被渲染為黑色,對于較舊的瀏覽器(HTML4 & CSS2),以下顏色是被支持的:
| 輸入 | 顯示 | 輸入 | 顯示 |
|---|---|---|---|
| black | s a m p l e \color{black}{sample} sample | grey | s a m p l e \color{grey}{sample} sample |
| silver | s a m p l e \color{silver}{sample} sample | white | s a m p l e \color{white}{sample} sample |
| maroon | s a m p l e \color{maroon}{sample} sample | red | s a m p l e \color{red}{sample} sample |
| yellow | s a m p l e \color{yellow}{sample} sample | lime | s a m p l e \color{lime}{sample} sample |
| olive | s a m p l e \color{olive}{sample} sample | green | s a m p l e \color{green}{sample} sample |
| teal | s a m p l e \color{teal}{sample} sample | auqa | s a m p l e \color{auqa}{sample} sample |
| blue | s a m p l e \color{blue}{sample} sample | navy | s a m p l e \color{navy}{sample} sample |
| purple | s a m p l e \color{purple}{sample} sample | fuchsia | s a m p l e \color{fuchsia}{sample} sample |
對于較新的瀏覽器(HTML5 & CSS3),HEX 顏色將被支持:
輸入 \color {#rgb} {text} 來自定義更多的顏色,其中 #rgb 或 #rrggbb 的 r g b 可輸入 0-9 和 a-f 來表示紅色、綠色和藍色的純度(飽和度),
示例
\begin{array}
{|rrrrrrrr|}
\hline
\verb+#000+ & \color{#000}{text} & & & \verb+#00F+ & \color{#00F}{text} & & \\
& & \verb+#0F0+ & \color{#0F0}{text} & & & \verb+#0FF+ & \color{#0FF}{text} \\
\verb+#F00+ & \color{#F00}{text} & & & \verb+#F0F+ & \color{#F0F}{text} & & \\
& & \verb+#FF0+ & \color{#FF0}{text} & & & \verb+#FFF+ & \color{#FFF}{text} \\
\hline
\end{array}
結果
#000
t
e
x
t
#00F
t
e
x
t
#0F0
t
e
x
t
#0FF
t
e
x
t
#F00
t
e
x
t
#F0F
t
e
x
t
#FF0
t
e
x
t
#FFF
t
e
x
t
\begin{array}{|rrrrrrrr|}\hline \verb+#000+ & \color{#000}{text} & & & \verb+#00F+ & \color{#00F}{text} & & \\ & & \verb+#0F0+ & \color{#0F0}{text} & & & \verb+#0FF+ & \color{#0FF}{text} \\ \verb+#F00+ & \color{#F00}{text} & & & \verb+#F0F+ & \color{#F0F}{text} & & \\ & & \verb+#FF0+ & \color{#FF0}{text} & & & \verb+#FFF+ & \color{#FFF}{text} \\\hline\end{array}
#000#F00?texttext?#0F0#FF0?texttext?#00F#F0F?texttext?#0FF#FFF?texttext??
示例
\begin{array}{|rrrrrrrr|}
\hline
\verb+#000+ & \color{#000}{text} & \verb+#005+ & \color{#005}{text} & \verb+#00A+ & \color{#00A}{text} & \verb+#00F+ & \color{#00F}{text} \\
\verb+#500+ & \color{#500}{text} & \verb+#505+ & \color{#505}{text} & \verb+#50A+ & \color{#50A}{text} & \verb+#50F+ & \color{#50F}{text} \\
\verb+#A00+ & \color{#A00}{text} & \verb+#A05+ & \color{#A05}{text} & \verb+#A0A+ & \color{#A0A}{text} & \verb+#A0F+ & \color{#A0F}{text} \\
\verb+#F00+ & \color{#F00}{text} & \verb+#F05+ & \color{#F05}{text} & \verb+#F0A+ & \color{#F0A}{text} & \verb+#F0F+ & \color{#F0F}{text} \\
\hline
\verb+#080+ & \color{#080}{text} & \verb+#085+ & \color{#085}{text} & \verb+#08A+ & \color{#08A}{text} & \verb+#08F+ & \color{#08F}{text} \\
\verb+#580+ & \color{#580}{text} & \verb+#585+ & \color{#585}{text} & \verb+#58A+ & \color{#58A}{text} & \verb+#58F+ & \color{#58F}{text} \\
\verb+#A80+ & \color{#A80}{text} & \verb+#A85+ & \color{#A85}{text} & \verb+#A8A+ & \color{#A8A}{text} & \verb+#A8F+ & \color{#A8F}{text} \\
\verb+#F80+ & \color{#F80}{text} & \verb+#F85+ & \color{#F85}{text} & \verb+#F8A+ & \color{#F8A}{text} & \verb+#F8F+ & \color{#F8F}{text} \\
\hline
\verb+#0F0+ & \color{#0F0}{text} & \verb+#0F5+ & \color{#0F5}{text} & \verb+#0FA+ & \color{#0FA}{text} & \verb+#0FF+ & \color{#0FF}{text} \\
\verb+#5F0+ & \color{#5F0}{text} & \verb+#5F5+ & \color{#5F5}{text} & \verb+#5FA+ & \color{#5FA}{text} & \verb+#5FF+ & \color{#5FF}{text} \\
\verb+#AF0+ & \color{#AF0}{text} & \verb+#AF5+ & \color{#AF5}{text} & \verb+#AFA+ & \color{#AFA}{text} & \verb+#AFF+ & \color{#AFF}{text} \\
\verb+#FF0+ & \color{#FF0}{text} & \verb+#FF5+ & \color{#FF5}{text} & \verb+#FFA+ & \color{#FFA}{text} & \verb+#FFF+ & \color{#FFF}{text} \\
\hline
\end{array}
結果
#000 t e x t #005 t e x t #00A t e x t #00F t e x t #500 t e x t #505 t e x t #50A t e x t #50F t e x t #A00 t e x t #A05 t e x t #A0A t e x t #A0F t e x t #F00 t e x t #F05 t e x t #F0A t e x t #F0F t e x t #080 t e x t #085 t e x t #08A t e x t #08F t e x t #580 t e x t #585 t e x t #58A t e x t #58F t e x t #A80 t e x t #A85 t e x t #A8A t e x t #A8F t e x t #F80 t e x t #F85 t e x t #F8A t e x t #F8F t e x t #0F0 t e x t #0F5 t e x t #0FA t e x t #0FF t e x t #5F0 t e x t #5F5 t e x t #5FA t e x t #5FF t e x t #AF0 t e x t #AF5 t e x t #AFA t e x t #AFF t e x t #FF0 t e x t #FF5 t e x t #FFA t e x t #FFF t e x t \begin{array}{|rrrrrrrr|}\hline \verb+#000+ & \color{#000}{text} & \verb+#005+ & \color{#005}{text} & \verb+#00A+ & \color{#00A}{text} & \verb+#00F+ & \color{#00F}{text} \\ \verb+#500+ & \color{#500}{text} & \verb+#505+ & \color{#505}{text} & \verb+#50A+ & \color{#50A}{text} & \verb+#50F+ & \color{#50F}{text} \\ \verb+#A00+ & \color{#A00}{text} & \verb+#A05+ & \color{#A05}{text} & \verb+#A0A+ & \color{#A0A}{text} & \verb+#A0F+ & \color{#A0F}{text} \\ \verb+#F00+ & \color{#F00}{text} & \verb+#F05+ & \color{#F05}{text} & \verb+#F0A+ & \color{#F0A}{text} & \verb+#F0F+ & \color{#F0F}{text} \\\hline \verb+#080+ & \color{#080}{text} & \verb+#085+ & \color{#085}{text} & \verb+#08A+ & \color{#08A}{text} & \verb+#08F+ & \color{#08F}{text} \\ \verb+#580+ & \color{#580}{text} & \verb+#585+ & \color{#585}{text} & \verb+#58A+ & \color{#58A}{text} & \verb+#58F+ & \color{#58F}{text} \\ \verb+#A80+ & \color{#A80}{text} & \verb+#A85+ & \color{#A85}{text} & \verb+#A8A+ & \color{#A8A}{text} & \verb+#A8F+ & \color{#A8F}{text} \\ \verb+#F80+ & \color{#F80}{text} & \verb+#F85+ & \color{#F85}{text} & \verb+#F8A+ & \color{#F8A}{text} & \verb+#F8F+ & \color{#F8F}{text} \\\hline \verb+#0F0+ & \color{#0F0}{text} & \verb+#0F5+ & \color{#0F5}{text} & \verb+#0FA+ & \color{#0FA}{text} & \verb+#0FF+ & \color{#0FF}{text} \\ \verb+#5F0+ & \color{#5F0}{text} & \verb+#5F5+ & \color{#5F5}{text} & \verb+#5FA+ & \color{#5FA}{text} & \verb+#5FF+ & \color{#5FF}{text} \\ \verb+#AF0+ & \color{#AF0}{text} & \verb+#AF5+ & \color{#AF5}{text} & \verb+#AFA+ & \color{#AFA}{text} & \verb+#AFF+ & \color{#AFF}{text} \\ \verb+#FF0+ & \color{#FF0}{text} & \verb+#FF5+ & \color{#FF5}{text} & \verb+#FFA+ & \color{#FFA}{text} & \verb+#FFF+ & \color{#FFF}{text} \\\hline\end{array} #000#500#A00#F00#080#580#A80#F80#0F0#5F0#AF0#FF0?texttexttexttexttexttexttexttexttexttexttexttext?#005#505#A05#F05#085#585#A85#F85#0F5#5F5#AF5#FF5?texttexttexttexttexttexttexttexttexttexttexttext?#00A#50A#A0A#F0A#08A#58A#A8A#F8A#0FA#5FA#AFA#FFA?texttexttexttexttexttexttexttexttexttexttexttext?#00F#50F#A0F#F0F#08F#58F#A8F#F8F#0FF#5FF#AFF#FFF?texttexttexttexttexttexttexttexttexttexttexttext??
19. 添加洗掉線
使用洗掉線功能必須宣告 $$ 符號,
在公式內使用 \require{cancel} 來允許片段洗掉線的顯示,
宣告片段洗掉線后,使用 \cancel{字符}、\bcancel{字符}、\xcancel{字符} 和 \cancelto{字符} 來實作各種片段洗掉線效果,
示例
$$
\require{cancel}
\begin{array}{rl}
\verb|y+\cancel{x}| & y+\cancel{x} \\
\verb|\cancel{y+x}| & \cancel{y+x} \\
\verb|y+\bcancel{x}| & y+\bcancel{x} \\
\verb|y+\xcancel{x}| & y+\xcancel{x} \\
\verb|y+\cancelto{0}{x}| & y+\cancelto{0}{x} \\
\verb+\frac{1\cancel9}{\cancel95} = \frac15+& \frac{1\cancel9}{\cancel95} = \frac15 \\
\end{array}
$$
結果
KaTeX parse error: Undefined control sequence: \require at position 2: \?r?e?q?u?i?r?e?{cancel} \begin…
20. 包圍公式
分別使用 circle 和 roundedbox 包圍的公式
示例
$$
\require{enclose}
\begin{array}{c}
\enclose{circle}{f(\top),\, f^2(\top),\, f^3(\top) \,\cdots\, f^n(\top)} \\
\enclose{roundedbox}{f(\bot),\, f^2(\bot),\, f^3(\bot) \,\cdots\, f^n(\bot)} \\
\end{array}
$$
結果
$$
$$
\require{enclose}
\begin{array}{c}
\enclose{circle}{f(\top),, f^2(\top),, f^3(\top) ,\cdots, f^n(\top)} \
\enclose{roundedbox}{f(\bot),, f^2(\bot),, f^3(\bot) ,\cdots, f^n(\bot)} \
\end{array}
使用 box 框住所有公式
示例
$$
\require{enclose}
\enclose{box}{
\begin{array}{c}
f(\top),\, f^2(\top),\, f^3(\top) \,\cdots\, f^n(\top) \\
f(\bot),\, f^2(\bot),\, f^3(\bot) \,\cdots\, f^n(\bot) \\
\end{array}
}
$$
結果
$$
$$
\require{enclose}
\enclose{box}{
\begin{array}{c}
f(\top),, f^2(\top),, f^3(\top) ,\cdots, f^n(\top) \
f(\bot),, f^2(\bot),, f^3(\bot) ,\cdots, f^n(\bot) \
\end{array}
}
21. 箭頭
| 符號 | 運算式 | 符號 | 運算式 |
|---|---|---|---|
| ← | \lefrarrow | ? | \longleftarrow |
| → | \rightarrow | ? | \longrightarrow |
| ? | \leftrightarrow | ? | \longleftrightarrow |
| ? | \Leftarrow | ? | \Longleftarrow |
| ? | \Rightarrow | ? | \Longrightarrow |
| ? | \Leftrightarrow | ? | \Longleftrightarrow |
22. 方程式
示例
$$
\begin{equation}
E=mc^2
\end{equation}
$$
結果
KaTeX parse error: No such environment: equation at position 8: \begin{?e?q?u?a?t?i?o?n?}? E=mc^2 \end{eq…
23. 分隔符
各種括號用 () [] { } \langle\rangle 等命令表示,注意花括號通常用來輸入命令和環境的引數,所以在數學公式中它們前面要加 \,可以在上述分隔符前面加 \big \Big \bigg \Bigg 等命令來調整大小,
示例
$$
\max \limits_{a<x<b} \Bigg\{f(x)\Bigg\}
$$
結果
max
?
a
<
x
<
b
{
f
(
x
)
}
\max \limits_{a<x<b} \Bigg\{f(x)\Bigg\}
a<x<bmax?{f(x)}
示例
\quad #空格
$$
\max \limits_{a<x<b} \Bigg\{\quad f(x)\quad\Bigg\}
$$
max ? a < x < b { f ( x ) } \max \limits_{a<x<b} \Bigg\{\quad f(x)\quad\Bigg\} a<x<bmax?{f(x)}
24. 分段函式
示例
$$
f(n) =
\begin{cases}
n/2, & \text {if $n$ is even}\\
3n+1, & \text {if $n$ is odd}
\end{cases}
$$
結果
f
(
n
)
=
{
n
/
2
,
if
n
is even
3
n
+
1
,
if
n
is odd
f(n) = \begin{cases} n/2, & \text {if $n$ is even}\\ 3n+1, & \text {if $n$ is odd} \end{cases}
f(n)={n/2,3n+1,?if n is evenif n is odd?
25. 如何輸入一個左側對齊的條件運算式
若想讓文字在左側對齊顯示,則有如下方式:
示例
$$
\left.
\begin{array}{l}
\text{if $n$ is even:} & n/2 \\
\text{if $n$ is odd:} & 3n+1 \\
\end{array}
\right\}
=f(n)
$$
結果
if n is even: n / 2 if n is odd: 3 n + 1 } = f ( n ) \left. \begin{array}{l} \text{if $n$ is even:} & n/2 \\ \text{if $n$ is odd:} & 3n+1 \\ \end{array} \right\} =f(n) if n is even:if n is odd:?n/23n+1?}=f(n)
26. 方程組
示例
$$
\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. # 注意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.
????a1?x+b1?y+c1?z=d1?a2?x+b2?y+c2?z=d2?a3?x+b3?y+c3?z=d3??
27. 如何使條件運算式適配行高
在一些情況下,條件運算式中某些行的行高為非標準高度,此時使用 \\[2ex] 陳述句代替該行末尾的 \\ 來讓編輯器適配,
- 例子:
不適配[2ex]
$$
f(n) =
\begin{cases}
\frac{n}{2}, & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd} \\
\end{cases}
$$
適配[2ex]
$$
f(n) =
\begin{cases}
\frac{n}{2}, & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd} \\
\end{cases}
$$
- 顯示:
| 不適配[2ex] | 適配[2ex] |
|---|---|
| $f(n) = \begin{cases} \frac{n}{2}, & \text{if n n n is even} \ 3n+1, & \text{if n n n is odd} \ \end{cases}$ | $f(n) = \begin{cases} \frac{n}{2}, & \text{if n n n is even} \ 3n+1, & \text{if n n n is odd} \ \end{cases}$ |
一個 [ex] 指一個 “X-Height”,即 x 字母高度,可以根據情況指定多個 [ex],如 [3ex]、[4ex] 等,
其實可以在任意換行處使用 \\[2ex] 陳述句,只要你覺得合適,
28. 陣列與表格使用參考之如何輸入一個陣列或表格
通常,一個格式化后的表格比單純的文字或排版后的文字更具有可讀性,
陣列和表格均以 \begin{array} 開頭,并在其后定義列數及每一列的文本對齊屬性,c l r 分別代表居中、左對齊及右對齊,若需要插入垂直分割線,在定義式中插入 | ,若要插入水平分割線,在下一行輸入前插入 \hline ,
與矩陣相似,每行元素間均須要插入 & ,每行元素以 \\ 結尾,最后以 \ end{array} 結束陣列,
使用單個陣列或表格時無需宣告 $ 或 $$ 符號,
示例
\begin{array}{c|lcr}
n & \text{左對齊} & \text{居中對齊} & \text{右對齊} \\
\hline
1 & 0.24 & 1 & 125 \\
2 & -1 & 189 & -8 \\
3 & -20 & 2000 & 1+10i \\
\end{array}
結果
n
左對齊
居中對齊
右對齊
1
0.24
1
125
2
?
1
189
?
8
3
?
20
2000
1
+
10
i
\begin{array}{c|lcr} n & \text{左對齊} & \text{居中對齊} & \text{右對齊} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1+10i \\ \end{array}
n123?左對齊0.24?1?20?居中對齊11892000?右對齊125?81+10i??
左對齊居中對齊右對齊
29. 陣列與表格使用參考之如何輸入一個嵌套的陣列或表格
多個陣列\表格可 互相嵌套 并組成一組陣列或表格,
使用嵌套前必須宣告 $$ 符號,
示例
$$
\begin{array}{c} % 總表格
\begin{array}{cc} % 第一行內分成兩列
\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}
&
\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} % 第一行表格組結束 \\
\begin{array}{c|cccc} % 第二行 Delta 值陣列
\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} \begin{array}{cc} \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} & \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} \\ \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}
min0123?00000?10111?20122?30123???max0123?00123?11123?22223?33333???Δ0123?00123?11012?22101?33210???
案例
1. 線性模型
示例
$$
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=0∑n?θj?xj?
2. 均方誤差
示例
$$
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(θ)=2m1?i=0∑m?(yi?hθ?(xi))2
3. 批量梯度下降
示例
$$
\frac{\partial J(\theta)}{\partial\theta_j} = -\frac{1}{m}\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} = -\frac{1}{m}\sum_{i=0}^m (y^i - h_\theta (x^i))x^i_j
?θj??J(θ)?=?m1?i=0∑m?(yi?hθ?(xi))xji?
4. 推導程序
示例:
$$
\begin{align}
\frac{\partial J(\theta)}{\partial \theta_j}
& = - \frac{1}{m} \sum_{i=0}^m (y^i-h_\theta(x^i))\frac{\partial}{\partial\theta_j}(y^i-h_\theta(x^i))\\
& = -\frac{1}{m}\sum_{i=0}^m(y^i-h_\theta(x^i))\frac{\partial}{\partial\theta_j}(\sum_{j=0}^n\theta_j x^i_j - y^i)\\
& = - \frac{1}{m}\sum_{i=0}^m(y^i-h_\theta (x^i))x^i_j
\end{align}
$$
結果
KaTeX parse error: No such environment: align at position 8: \begin{?a?l?i?g?n?}? \frac{\partial…
參考檔案
Cmd Markdown 公式指導手冊
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/267390.html
標籤:其他
上一篇:JavaScript制作日歷
