> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-tw/shu-xue/01-mathematical-expressions.md).

# 數學表達式

## 簡介

LaTeX 的數學排版功能使它成為撰寫技術文件的極具吸引力選擇。本文將展示開始使用 LaTeX 撰寫數學所需的最基本指令。

在 LaTeX 中撰寫基本方程式很簡單，例如：

```latex
\documentclass{article}
\begin{document}

著名的畢氏定理 \(x^2 + y^2 = z^2\) 已
被證明對其他指數不成立。
這表示下一個方程式沒有整數解：

\[ x^n + y^n = z^n \]

\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+math+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0AThe+well+known+Pythagorean+theorem+%5C%28x%5E2+%2B+y%5E2+%3D+z%5E2%5C%29+was+%0Aproved+to+be+invalid+for+other+exponents.+%0AMeaning+the+next+equation+has+no+integer+solutions%3A%0A%0A%5C%5B+x%5En+%2B+y%5En+%3D+z%5En+%5C%5D%0A%0A%5Cend%7Bdocument%7D)

![數學方程式範例](/files/2c7d0ff38bf6c815b019829c45ad98e615adc462)

如你所見，方程式的顯示方式取決於分隔符，在此情況下 `\[...\]` 和 `\(...\)`.

## 數學模式

LaTeX 允許數學表達式有兩種撰寫模式： *行內* 行內數學模式和 *顯示* 顯示數學模式：

* *行內* 行內數學模式用來撰寫屬於段落一部分的公式
* *顯示* 顯示數學模式用來撰寫不屬於段落一部分的表達式，因此會另起一行

### 行內數學模式

你可以使用以下任何一種「分隔符」來以行內模式排版你的數學式：

* `\(...\)`
* `$...$`
* `\begin{math}...\end{math}`

它們都能運作，選擇哪一種只是個人口味問題，所以我們來看幾個例子。

```latex
\documentclass{article}
\begin{document}

\noindent 標準的 \LaTeX{} 實務是將行內數學式包在 \verb|\(...\)| 之間來撰寫：

\begin{quote}
在物理學中，質能等價性表述為
由方程式 \(E=mc^2\) 表示，該式由愛因斯坦於 1905 年提出。
\end{quote}

\noindent 不過，若你將行內數學式寫成（包在） \verb|\(...\)| 之間，也可以使用 \texttt{\$...\$} 達到相同效果：

\begin{quote}
在物理學中，質能等價性表述為
由方程式 $E=mc^2$ 表示，該式由愛因斯坦於 1905 年提出。
\end{quote}

\noindent 或者，你可以使用 \verb|\begin{math}...\end{math}|：

\begin{quote}
在物理學中，質能等價性表述為
由方程式 \begin{math}E=mc^2\end{math} 表示，該式由愛因斯坦於 1905 年提出。
\end{quote}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+inline+math+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cnoindent+Standard+%5CLaTeX%7B%7D+practice+is+to+write+inline+math+by+enclosing+it+between+%5Cverb%7C%5C%28...%5C%29%7C%3A%0A%0A%5Cbegin%7Bquote%7D%0AIn+physics%2C+the+mass-energy+equivalence+is+stated+%0Aby+the+equation+%5C%28E%3Dmc%5E2%5C%29%2C+discovered+in+1905+by+Albert+Einstein.%0A%5Cend%7Bquote%7D%0A%0A%5Cnoindent+Instead+if+writing+%28enclosing%29+inline+math+between+%5Cverb%7C%5C%28...%5C%29%7C+you+can+use+%5Ctexttt%7B%5C%24...%5C%24%7D+to+achieve+the+same+result%3A%0A%0A%5Cbegin%7Bquote%7D%0AIn+physics%2C+the+mass-energy+equivalence+is+stated+%0Aby+the+equation+%24E%3Dmc%5E2%24%2C+discovered+in+1905+by+Albert+Einstein.%0A%5Cend%7Bquote%7D%0A%0A%5Cnoindent+Or%2C+you+can+use+%5Cverb%7C%5Cbegin%7Bmath%7D...%5Cend%7Bmath%7D%7C%3A%0A%0A%5Cbegin%7Bquote%7D%0AIn+physics%2C+the+mass-energy+equivalence+is+stated+%0Aby+the+equation+%5Cbegin%7Bmath%7DE%3Dmc%5E2%5Cend%7Bmath%7D%2C+discovered+in+1905+by+Albert+Einstein.%0A%5Cend%7Bquote%7D%0A%5Cend%7Bdocument%7D)

![行內方程式範例](/files/03a052c419aa4311636073bdb364115fa80a5d4b)

### 顯示數學模式

使用以下其中一種結構來以顯示模式排版數學式：

* `\[...\]`
* `\begin{displaymath}...\end{displaymath}`
* `\begin{equation}...\end{equation}`

顯示數學模式有兩個版本，可產生有編號或無編號的方程式。讓我們看一個基本範例：

```latex
\documentclass{article}
\begin{document}
質能等價性由著名方程式描述

\[E=mc^2\]

由愛因斯坦於 1905 年提出。
在自然單位制（$c$ = 1）下，這個公式表達了恆等式

\begin{equation}
E=m
\end{equation}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+math+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AThe+mass-energy+equivalence+is+described+by+the+famous+equation%0A%0A%5C%5BE%3Dmc%5E2%5C%5D%0A%0Adiscovered+in+1905+by+Albert+Einstein.+%0AIn+natural+units+%28%24c%24+%3D+1%29%2C+the+formula+expresses+the+identity%0A%0A%5Cbegin%7Bequation%7D%0AE%3Dm%0A%5Cend%7Bequation%7D%0A%5Cend%7Bdocument%7D)

![Displayex.png](/files/5cdf9308f5389faa0501c33f1f9bec60ba3f4651)

## 另一個範例

以下範例使用了 `equation*` 環境，這是由 `amsmath` 套件提供的——請參見 [`amsmath` article](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md) 以了解更多資訊。

```latex
\documentclass{article}
\usepackage{amsmath} % for the equation* environment
\begin{document}

這是在文字中的一個簡單數學式 \(\sqrt{x^2+1}\)。
而且這也是相同的：
\begin{math}
\sqrt{x^2+1}
\end{math}
只是改用另一個指令。

這是一個沒有編號的簡單數學式
\[\sqrt{x^2+1}\]
與文字分開。

這也一樣：
\begin{displaymath}
\sqrt{x^2+1}
\end{displaymath}

\ldots 而這個也是：
\begin{equation*}
\sqrt{x^2+1}
\end{equation*}

\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Typesetting+maths+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D+%25+for+the+equation%2A+environment%0A%5Cbegin%7Bdocument%7D%0A%0AThis+is+a+simple+math+expression+%5C%28%5Csqrt%7Bx%5E2%2B1%7D%5C%29+inside+text.+%0AAnd+this+is+also+the+same%3A+%0A%5Cbegin%7Bmath%7D%0A%5Csqrt%7Bx%5E2%2B1%7D%0A%5Cend%7Bmath%7D%0Abut+by+using+another+command.%0A%0AThis+is+a+simple+math+expression+without+numbering%0A%5C%5B%5Csqrt%7Bx%5E2%2B1%7D%5C%5D+%0Aseparated+from+text.%0A%0AThis+is+also+the+same%3A%0A%5Cbegin%7Bdisplaymath%7D%0A%5Csqrt%7Bx%5E2%2B1%7D%0A%5Cend%7Bdisplaymath%7D%0A%0A%5Cldots+and+this%3A%0A%5Cbegin%7Bequation%2A%7D%0A%5Csqrt%7Bx%5E2%2B1%7D%0A%5Cend%7Bequation%2A%7D%0A%0A%5Cend%7Bdocument%7D)

![Amsexample.png](/files/55e0d36532fd40039ebe0111838bca281fa0a74b)

## 參考指南

下表列出一些常見的數學符號。更完整的清單請參見 [希臘字母與數學符號列表](/latex/zh-tw/shu-xue/11-list-of-greek-letters-and-math-symbols.md):

| 說明    | 程式碼                                               | 範例                                                              |
| ----- | ------------------------------------------------- | --------------------------------------------------------------- |
| 希臘字母  | `\alpha \beta \gamma \rho \sigma \delta \epsilon` | $$\alpha \ \beta \ \gamma \ \rho \ \sigma \ \delta \ \epsilon$$ |
| 二元運算子 | `\times \otimes \oplus \cup \cap`                 | $$\times \ \otimes \ \oplus \ \cup \ \cap$$                     |
| 關係運算子 | `< > \subset \supset \subseteq \supseteq`         | $$< \ >\ \subset \ \supset \ \subseteq \ \supseteq$$            |
| 其他    | `\int \oint \sum \prod`                           | $$\int \ \oint \ \sum \ \prod$$                                 |

不同類別的數學符號具有不同的格式特徵（例如，變數會以斜體顯示，但 [運算子](/latex/zh-tw/shu-xue/07-operators.md) 則不會），以及不同的 [間距](/latex/zh-tw/shu-xue/08-spacing-in-math-mode.md).

## 延伸閱讀

LaTeX 的數學模式非常靈活且強大，還有很多事情可以做到：

* [下標與上標](/latex/zh-tw/shu-xue/02-subscripts-and-superscripts.md)
* [中括號與小括號](/latex/zh-tw/shu-xue/03-brackets-and-parentheses.md)
* [分數與二項式](/latex/zh-tw/shu-xue/05-fractions-and-binomials.md)
* [對齊方程式](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md)
* [運算子](/latex/zh-tw/shu-xue/07-operators.md)
* [數學模式中的間距](/latex/zh-tw/shu-xue/08-spacing-in-math-mode.md)
* [積分、求和與極限](/latex/zh-tw/shu-xue/09-integrals-sums-and-limits.md)
* [數學模式中的顯示樣式](/latex/zh-tw/shu-xue/10-display-style-in-math-mode.md)
* [希臘字母與數學符號列表](/latex/zh-tw/shu-xue/11-list-of-greek-letters-and-math-symbols.md)
* [數學字型](/latex/zh-tw/shu-xue/12-mathematical-fonts.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-tw/shu-xue/01-mathematical-expressions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
