--- tags: sysprog --- # HackMD -- LaTeX 語法與示範 課程作業會出現大量的數學式,而作業要求之一即 ==不使用圖片顯示文字訊息==,當然也包含繁複的數學式。因此,以下我們會引導大家在 HackMD 中使用 [LaTeX](https://zh.wikipedia.org/zh-tw/LaTeX) 表達數學式。 :::info 右鍵點選 * 顯示出來並沒有`$`,但切記在 HackMD 中,必須以`$`包圍住才會認得是 LaTeX 語法喔! ::: ## 數學式的開始與結束都是`$` * 如我們想表達: `N(b, d) = (b − 1) M` * 需要標注 `$N(b,d)=(b-1)M$` * 使用 LaTeX 後變成: $N(b,d)=(b-1)M$ 另外,==`$`需緊鄰著數學式==,也就是中間不能有任何空白鍵,否則一樣無法辨識為 LaTeX 語法! * 一樣以 $N(b,d)=(b-1)M$ 為例 * `$`插入空白: * $ N(b,d)=(b-1)M$ (開始的`$`後插入空白) * $N(b,d)=(b-1)M $ (結束的`$`前插入空白) * $ N(b,d)=(b-1)M $ (前後的`$`都插入空白) 除了`$`以外的符號都可以加入空白以增加可讀性,而不影響顯示結果 透過右鍵看 LaTeX Code 可以看出下面兩個式子的差異 * 一樣以 $N(b,d)=(b-1)M$ 為例 * 任意插入 $n$ 個空白: * $N ( b , \ \ \ \ d )=( b - 1 )M$ ## $\LaTeX$ 排版 ### 如何插入空白 雖然空白可以增加可讀性,但若我們真的希望顯示結果是有空白的話呢? * 如我們希望用 LaTeX 表示: 7 months + 5 months = 1 year * 前後加上`$`後: $7months + 5 months = 1 year$ 完全不是預期的結果! 而且不論加上多少空白,還是會跟上面一模一樣...... **解法: 加入`\`** 這其實跟寫程式要印出特殊符號的方法一樣,就是再加一個`\` * 馬上試試看: $7\ months + 5\ months = 1\ year$ * $Lily \ \ \ \ \ brother$ 完美呈現!! :::info `\`在 LaTeX 中常用到,當要加入特殊符號時一定會出現! 用以區分純英文單字和特殊符號 如: * $alpha$ 與 $\alpha$ ::: ### 如何插入換行 除了空白,排版不能或缺的當然還有換行囉! 換行:`\\` 如:以下數學式為加入換行排版後的呈現: $\dfrac{1}{2}$ $二分之一: \\ \dfrac{1}{2}$ ### 如何對齊方程式 再次以同樣的式子為例,若沒加入對齊: $$ \int_{a}^{b}x(t)dt = \dfrac{b - a}{N} \\ =\sum_{k=1}^{N}x(t_k)\cdot\dfrac{b-a}{N} $$ * **以等號對齊**: `\begin{split}...\end{split}` * 在方程式的開頭加上 `\begin{split}`,結尾加上 `\end{split}`,等號前加上 `&` $\mathrm{Integrals\ are\ numerically\ approximated\ as\ finite\ series}:\\ \begin{split} \int_{a}^{b}x(t)dt &= \dfrac{b - a}{N} \\ &=\sum_{k=1}^{N}x(t_k)\cdot\dfrac{b-a}{N} \end{split} \\ where\ t_k = a + (b-a)\cdot k/N$ * `&` 是標記從哪裡開始對齊的標記點 > 你可以自由移動 ==`&`== 改變對齊的符號 * **多行切割**: `\begin{multline*}...\end{multline*}` 若式子太長,分段切割顯示才好閱讀,否則字會超出版面 中間要換行的地方一樣插入 `\\` * 沒換行:$p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3 - 12x^2y^4 - 12xy^5 + 2y^6 - a^3b^3 - a^2b - ab + c^5d^3 + c^4d^3 - cd$ * 有換行: $\begin{multline*}p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3 \\ - 12x^2y^4 - 12xy^5 + 2y^6 - a^3b^3 - a^2b - ab + c^5d^3 + c^4d^3 - cd\end{multline*}$ * **置中對齊**: `\begin{gather*}...\end{gather*}` * 沒置中對齊: $2x - 5y = 8 \\ 3x^2 + 9y = 3a + c$ * 有置中對齊: $\begin{gather*} 2x - 5y = 8 \\ 3x^2 + 9y = 3a + c \end{gather*}$ ## 常用數學式 以下會列舉出在作業中可能常用到的數學式 ### 次方`^` 想表達 a 的 b 次方: `a^b` 如: $2^5 = 32$ 當次方項多於一個字時,需使用`{}`包住 * 如: 2 的 10 次方 * $2^10 = 1024$ (沒有使用`{}`) * $2^{10} = 1024$ * 文字: 2 的 n - 1 次方 * $2^{n-1}$ 當底數是多於一個字時 * 如: $1.02^{365} = 1377.4$ $1.01^{365} = 37.8$ > 每日多百分之二的努力,一年後可得千倍收穫!! ### 直式除法 `\dfrac{分子}{分母}` 想表達二分之一: $ \dfrac{1}{2} $ 二分之一: $\dfrac{1}{2}$ `{}` 一樣可填入任意文字數字 ### 循環小數 `\overline{循環部分}` AB 循環: $ \overline{AB} $ `{}` 填入循環部分 如: $0.00\overline{123}$ ### 底標 `_` $M_i$: $ M_i $ 底標多個字時一樣使用 `{}` $M_{this\ is\ a\ M}$ ### 矩陣 表達一個 $3 \times 3$ 矩陣: $\left( \begin{array}{ccc} y_1 & 2 & 3\\ y_2 & 5 & 6 \\ 7 & 8 & 9 \\ \end{array} \right)$ `\left(` `\begin{array}{ccc}` `y_1 & 2 & 3 \\` `y_2 & 5 & 6 \\` `7 & 8 & 9 \\` `\end{array}` `\right)` * `\left(`: * 左半邊括號,不一定要是`(`,也可以是`[` `|` * `\begin{array}`: * 矩陣開始 * `{ccc}`: * 定義有幾個 column * `1 & 2 & 3 \\`: * 依序填入矩陣內容,每行以 `\\` 結尾 * `\end{array}`: * 矩陣結束 * `\right)`: * 右半邊括號,如左半邊,可以是別種類型的括號 ### 積分 `\int_{a}^{b}` $\int_{a}^{b}x(t)dt$: `\int_{a}^{b}x(t)dt` ### limit `\lim_{N\to\infty}` 有兩種呈現方式: * $\lim_{N\to\infty}$ `\lim_{N\to\infty}` * $\displaystyle\lim_{N\to\infty}$ `\displaystyle\lim_{N\to\infty}` * 加入 `displaystyle` `\to` 即為 $\to$ ### sums `\sum_{k=1}^{N}` 有兩種呈現方式: * $\sum_{k=1}^{N}x(t_k)$ `\sum_{k=1}^{N}x(t_k)` * $\displaystyle\sum_{k=1}^{N}x(t_k)$ `\displaystyle\sum_{k=1}^{N}x(t_k)` * 多加入 `\displaystyle` ### multiple dot `\cdot` 如以下例子: $$ \sum_{k=1}^{N}x(t_k)\cdot\dfrac{b - a}{N} $$ 須使用 `\cdot` 來表示,鍵盤上輸入 `.` 會是小數點 ### multiple x `\times` 若想再方程式中打上乘號(x),若單純輸入 x 會被視為字母 如下: * $a x b$: `a x b` * $a \times b$: `a \times b` ### 更多的 $\LaTeX$ 排版語法 可參見 [$\LaTeX$ 語法筆記](https://hackmd.io/@RintarouTW/%E6%84%9A%E5%8D%83%E6%85%AE%E3%81%AE%E7%AD%86%E8%A8%98%E6%9C%AC/%2F%40RintarouTW%2FLaTeX_%25E8%25AA%259E%25E6%25B3%2595%25E7%25AD%2586%25E8%25A8%2598) ## 參考連結 * [List of LaTeX mathematical symbols](https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols) * [Detexify, find symbols by drawing](https://detexify.kirelabs.org/classify.html) * [Integrals, sums and limits](https://www.sharelatex.com/learn/Integrals,_sums_and_limits#!#Sums_and_products) * [Aligning equations with amsmath](https://www.sharelatex.com/learn/Aligning_equations_with_amsmath) * [LaTeX Equation Editor](https://latexeditor.lagrida.com/)
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.