LaTeX
记录 —— 插入数学公式
分类
LaTeX
中数学公式的呈现可分为两类:行内公式与行间公式。
行内公式: 又被称为内联公式(text),即在声明文本的正文之内,也就是说是嵌入文字之间的,与文字在同一行。
行间公式: 又被称为外联公式(displayed),即与正文分开的公式,公式单独占据一行。
实现
这两种公式均有三种方式来实现。
行内公式:
- 使用
$...$
方式将公式包含在其中。 - 使用
\(...\)
将公式包含在其中。 - 使用
\begin {math}
和\end {math}
将公式包含在其中。
- 使用
行间公式:
- 使用
$$...$$
方式将公式包含在其中。 - 使用
\[...\]
将公式包含在其中。 - 使用
\begin {digplaymath}
与\end {displaymath}
将公式包含在其中。
- 使用
下例中以不同的方式进行了x + y = 10
这个公式的实现:
\documentclass{article}
\begin{document}
test test test $x + y = 10$ test test test
test test test \(x + y = 10\) test test test
test test test
\begin{math}
x + y = 10
\end{math}
test test test
test test test $$x + y = 10$$ test test test
test test test \[x + y = 10\] test test test
test test test
\begin{displaymath}
x + y = 10
\end{displaymath}
test test test
\end{document}
结果如下:
注:
LaTeX
中会将换行符忽略,若要实现在文档中换行,需在要换行处添加空行。这样在实现的文档中会另起一段,且若是默认情况下,在每一段开始,LaTeX
在处理时会自动添加4个字符的缩进。这里仅讨论关于在文档中添加数学公式的方法,对于换行等格式的控制暂不展开说明。