> 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-cn/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/cb3b0370129e0206d1a154f0a09a8d2f0f8e9326)

如你所见，方程的显示方式取决于分隔符，在这种情况下 `\[...\]` 和 `\(...\)`.

## 数学模式

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/2119f0730179b3f1fb7ffa6fbab4c0dbaeae8664)

### 显示数学模式

使用以下任意一种结构以显示模式排版数学公式：

* `\[...\]`
* `\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/090f817d97d886273fda0f4a60b4474936d26d69)

## 另一个示例

下面的示例使用了 `equation*` 环境，由以下内容提供： `amsmath` 宏包——请参见 [`amsmath` article](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md) 以了解更多信息。

```latex
\documentclass{article}
\usepackage{amsmath} % 用于 equation* 环境
\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/d94a591a53b73dd3b3e85fcbba689c1ae54e3a60)

## 参考指南

下面是一些常见数学符号的表格。更完整的列表请参见 [希腊字母和数学符号列表](/latex/zh-cn/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-cn/shu-xue/07-operators.md) 则不是），并且不同的 [间距](/latex/zh-cn/shu-xue/08-spacing-in-math-mode.md).

## 进一步阅读

LaTeX 的数学模式非常灵活且强大，还可以做很多事情：

* [下标和上标](/latex/zh-cn/shu-xue/02-subscripts-and-superscripts.md)
* [括号](/latex/zh-cn/shu-xue/03-brackets-and-parentheses.md)
* [分数和二项式](/latex/zh-cn/shu-xue/05-fractions-and-binomials.md)
* [对齐公式](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md)
* [运算符](/latex/zh-cn/shu-xue/07-operators.md)
* [数学模式中的间距](/latex/zh-cn/shu-xue/08-spacing-in-math-mode.md)
* [积分、求和与极限](/latex/zh-cn/shu-xue/09-integrals-sums-and-limits.md)
* [数学模式中的显示样式](/latex/zh-cn/shu-xue/10-display-style-in-math-mode.md)
* [希腊字母和数学符号列表](/latex/zh-cn/shu-xue/11-list-of-greek-letters-and-math-symbols.md)
* [数学字体](/latex/zh-cn/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-cn/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.
