> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/wen-dang-jie-gou/05-glossaries.md).

# 术语表

## 引言

当撰写一篇包含某些特定领域概念的文档时，添加术语表可能会很方便。术语表是在某一知识领域中带有定义的术语列表。本文将说明如何创建一个。

**重要提示**: 你的项目的 [主文件](/latex/zh-cn/zhi-shi-ku/127-set-main-document.md) 应始终位于根目录（不在任何文件夹内），以确保所有编译步骤都在正确的目录中运行，并确保所需的辅助文件可用，例如在创建术语表或添加索引时。

让我们从一个简单的例子开始。

```latex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{glossaries}

\makeglossaries

\newglossaryentry{latex}
{
    name=latex,
    description={是一种特别适合
    用于科学文档的标记语言}
}

\newglossaryentry{maths}
{
    name=mathematics,
    description={数学就是数学家所做的事情}
}

\title{如何创建术语表}
\author{ }
\date{ }

\begin{document}
\maketitle

LaTeX 排版标记语言 \Gls{latex} 特别适合
包含 \gls{maths} 的文档。

\clearpage

\printglossaries

\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Glossaries+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Butf8%5D%7Binputenc%7D%0A%5Cusepackage%7Bglossaries%7D%0A%0A%5Cmakeglossaries%0A%0A%5Cnewglossaryentry%7Blatex%7D%0A%7B%0A++++name%3Dlatex%2C%0A++++description%3D%7BIs+a+markup+language+specially+suited+%0A++++for+scientific+documents%7D%0A%7D%0A%0A%5Cnewglossaryentry%7Bmaths%7D%0A%7B%0A++++name%3Dmathematics%2C%0A++++description%3D%7BMathematics+is+what+mathematicians+do%7D%0A%7D%0A%0A%5Ctitle%7BHow+to+create+a+glossary%7D%0A%5Cauthor%7B+%7D%0A%5Cdate%7B+%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%0AThe+%5CGls%7Blatex%7D+typesetting+markup+language+is+specially+suitable+%0Afor+documents+that+include+%5Cgls%7Bmaths%7D.+%0A%0A%5Cclearpage%0A%0A%5Cprintglossaries%0A%0A%5Cend%7Bdocument%7D)

下图显示了上面示例生成的术语表：

![Glossary1OLV2.png](/files/e1be63fa343157cd91bfde7e683e8573666dff68)

要创建术语表，必须导入 `glossaries` 包。通过在

```latex
\usepackage{glossaries}
```

导言区中加入这一行即可实现。命令 `\makeglossaries` 必须写在第一个术语条目之前。

每个术语条目都由命令 `\newglossaryentry` 创建，它接受两个参数，然后每个条目之后都可以在文档中通过命令 `\gls`进行引用。有关更完整的说明，请参见关于 [术语](#terms) 的小节。

命令 `\printglossaries` 是实际渲染每个条目中输入的词语和定义列表的命令，标题为“术语表”。在本例中它显示在文档末尾，但 `\printglossaries` 可用于任何其他位置。

## 术语和首字母缩略词

通常术语表中有两类条目：术语及其定义，或首字母缩略词及其含义。这两类可以在你的 LaTeX 文档中分别打印。

```latex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[acronym]{glossaries}

\makeglossaries

\newglossaryentry{latex}
{
        name=latex,
        description={是一种特别适合于
科学文档的标记语言}
}

\newglossaryentry{maths}
{
        name=mathematics,
        description={数学就是数学家所做的事情}
}

\newglossaryentry{formula}
{
        name=formula,
        description={一个数学表达式}
}

\newacronym{gcd}{GCD}{Greatest Common Divisor}

\newacronym{lcm}{LCM}{Least Common Multiple}

\begin{document}

LaTeX 排版标记语言 \Gls{latex} 特别适合
用于包含 \gls{maths} 的文档。\Glspl{formula} 会
在熟悉这些命令后能够被正确且轻松地排版。

给定一组数字，有一些基本方法可以计算
它的 \acrlong{gcd}，其缩写为 \acrshort{gcd}。这个
过程与用于 \acrfull{lcm} 的过程类似。

\clearpage

\printglossary[type=\acronymtype]

\printglossary

\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Glossaries+Terms+and+Acronyms+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Butf8%5D%7Binputenc%7D%0A%5Cusepackage%5Bacronym%5D%7Bglossaries%7D%0A%0A%5Cmakeglossaries%0A%0A%5Cnewglossaryentry%7Blatex%7D%0A%7B%0A++++++++name%3Dlatex%2C%0A++++++++description%3D%7BIs+a+mark+up+language+specially+suited+for+%0Ascientific+documents%7D%0A%7D%0A%0A%5Cnewglossaryentry%7Bmaths%7D%0A%7B%0A++++++++name%3Dmathematics%2C%0A++++++++description%3D%7BMathematics+is+what+mathematicians+do%7D%0A%7D%0A%0A%5Cnewglossaryentry%7Bformula%7D%0A%7B%0A++++++++name%3Dformula%2C%0A++++++++description%3D%7BA+mathematical+expression%7D%0A%7D%0A%0A%5Cnewacronym%7Bgcd%7D%7BGCD%7D%7BGreatest+Common+Divisor%7D%0A%0A%5Cnewacronym%7Blcm%7D%7BLCM%7D%7BLeast+Common+Multiple%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0AThe+%5CGls%7Blatex%7D+typesetting+markup+language+is+specially+suitable+%0Afor+documents+that+include+%5Cgls%7Bmaths%7D.+%5CGlspl%7Bformula%7D+are+%0Arendered+properly+an+easily+once+one+gets+used+to+the+commands.%0A%0AGiven+a+set+of+numbers%2C+there+are+elementary+methods+to+compute+%0Aits+%5Cacrlong%7Bgcd%7D%2C+which+is+abbreviated+%5Cacrshort%7Bgcd%7D.+This+%0Aprocess+is+similar+to+that+used+for+the+%5Cacrfull%7Blcm%7D.%0A%0A%5Cclearpage%0A%0A%5Cprintglossary%5Btype%3D%5Cacronymtype%5D%0A%0A%5Cprintglossary%0A%0A%5Cend%7Bdocument%7D)

下图显示了上面示例产生的部分输出：

![Glossary2OLV2.png](/files/69b0945cc7b25581bb3a0b37c0559e2c0fcf9317)

以下小节将说明如何创建每种列表类型。

### 术语

如在 [引言](#introduction)中所见，术语通过命令 `\newglossaryentry`

```latex
\documentclass{article}
\usepackage{glossaries}

\makeglossaries

\newglossaryentry{maths}
{
    name=mathematics,
    description={数学就是数学家所做的事情}
}

\newglossaryentry{latex}
{
    name=latex,
    description={是一种特别适合于
科学文档的标记语言}
}

\newglossaryentry{formula}
{
    name=formula,
    description={一个数学表达式}
}

\begin{document}

LaTeX 排版标记语言 \Gls{latex} 特别适合
用于包含 \gls{maths} 的文档。\Glspl{formula} 会被渲染
在熟悉这些命令后能够被正确且轻松地显示。

\clearpage

\printglossary

\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+Glossary+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bglossaries%7D%0A%0A%5Cmakeglossaries%0A%0A%0A%5Cnewglossaryentry%7Bmaths%7D%0A%7B%0A++++name%3Dmathematics%2C%0A++++description%3D%7BMathematics+is+what+mathematicians+do%7D%0A%7D%0A%0A%5Cnewglossaryentry%7Blatex%7D%0A%7B%0A++++name%3Dlatex%2C%0A++++description%3D%7BIs+a+markup+language+specially+suited+for+%0Ascientific+documents%7D%0A%7D%0A%0A%0A%5Cnewglossaryentry%7Bformula%7D%0A%7B%0A++++name%3Dformula%2C%0A++++description%3D%7BA+mathematical+expression%7D%0A%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0AThe+%5CGls%7Blatex%7D+typesetting+markup+language+is+specially+suitable+%0Afor+documents+that+include+%5Cgls%7Bmaths%7D.+%5CGlspl%7Bformula%7D+are+rendered+%0Aproperly+an+easily+once+one+gets+used+to+the+commands.%0A%0A%5Cclearpage%0A%0A%5Cprintglossary%0A%0A%5Cend%7Bdocument%7D)

下图显示了上面示例创建的术语表：

![Glossary3OLV2.png](/files/6db11440421143139e372a6fb4d41f4832afa99c)

让我们更详细地看看传递给命令的每个参数的语法 `\newglossaryentry`。示例中定义的第一个术语是“mathematics”。

* `maths`。第一个参数是该术语的标签，用于在文档中通过 `gls`
* `name=mathematics`引用它。包含要定义的词，在本例中是“mathematics”。建议使用小写字母和单数形式。
* `description={数学就是数学家所做的事情}`。大括号中是当前术语的定义。

在定义了这些术语之后，在编写 LaTeX 文件时，可以使用下面这些命令之一来使用它们：

**\gls{ }**

打印术语的小写形式。例如，\gls{maths} 在使用时会打印出 mathematics。

**\Gls{ }**

与 \gls 相同，但首字母会以大写形式打印。例如：\Gls{maths} 会打印出 Mathematics

**\glspl{ }**

与 \gls 相同，但术语会以复数形式显示。例如，\glspl{formula} 会在你的最终文档中写出 formulas。

**\Glspl{ }**

与 \Gls 相同，但术语会以复数形式显示。例如，\Glspl{formula} 显示为 Formulas。

最后，要打印术语表，请使用命令

```latex
\printglossary
```

### 首字母缩略词

首字母缩略词是由一个短语的首字母组成的词。下面是 LaTeX 中首字母缩略词的一个示例

```latex
\documentclass{article}
\usepackage[acronym]{glossaries}

\makeglossaries

\newacronym{gcd}{GCD}{Greatest Common Divisor}

\newacronym{lcm}{LCM}{Least Common Multiple}

\begin{document}
给定一组数字，有一些基本方法可以计算
它的 \acrlong{gcd}，其缩写为 \acrshort{gcd}。这个过程
与用于 \acrfull{lcm} 的过程类似。

\clearpage

\printglossary[type=\acronymtype]

\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+Glossary+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bacronym%5D%7Bglossaries%7D%0A%0A%5Cmakeglossaries%0A%0A%5Cnewacronym%7Bgcd%7D%7BGCD%7D%7BGreatest+Common+Divisor%7D%0A%0A%5Cnewacronym%7Blcm%7D%7BLCM%7D%7BLeast+Common+Multiple%7D%0A%0A%5Cbegin%7Bdocument%7D%0AGiven+a+set+of+numbers%2C+there+are+elementary+methods+to+compute+%0Aits+%5Cacrlong%7Bgcd%7D%2C+which+is+abbreviated+%5Cacrshort%7Bgcd%7D.+This+process+%0Ais+similar+to+that+used+for+the+%5Cacrfull%7Blcm%7D.%0A%0A%5Cclearpage%0A%0A%5Cprintglossary%5Btype%3D%5Cacronymtype%5D%0A%0A%5Cend%7Bdocument%7D)

下图显示了上面示例产生的部分输出：

![Glossary4OLV2.png](/files/cbdffdfb47324bb08fa8a953fdeeff17d8e5b6b0)

要使用首字母缩略词，在导入 **glossaries** 包时必须使用一个额外参数。要添加到导言区的行是

```latex
\usepackage[acronym]{glossaries}
```

添加这行之后，命令 `\newacronym` 将声明一个新的首字母缩略词。为了举例，下面是命令的说明 `\newacronym{gcd}{GCD}{Greatest Common Divisor}`

* `gcd` 是标签，用于稍后在文档中引用这个首字母缩略词。
* `GCD` 缩略词本身。通常首字母缩略词用大写字母书写。
* `最大公约数` 是这个缩略词所代表的短语。

在将首字母缩略词加入导言区之后，就可以通过下面这些命令来使用它们：

**\acrlong{ }**

显示首字母缩略词所代表的短语。在大括号中放入该缩略词的标签。在示例中，\acrlong{gcd} 打印出 最大公约数。

**\acrshort{ }**

打印参数中传入其标签的首字母缩略词。例如，\acrshort{gcd} 显示为 GCD。

**\acrfull{ }**

同时打印首字母缩略词及其定义。在示例中，\acrfull{lcm} 的输出为 最小公倍数 (LCM)。

要打印首字母缩略词列表，请使用命令

```latex
\printglossary[type=\acronymtype]
```

首字母缩略词列表需要由 `\printglossary` 生成的临时文件才能工作，因此你必须在 `\printglossary[type=\acronymtype]` 之前添加该命令并编译文档，一旦你第一次编译了文档，就可以删除该行 `\printglossary`.

## 更改术语表标题

如果你想把术语表的默认标题改成别的，这很简单；在打印术语表时必须添加两个参数。下面是一个示例。

```latex
\documentclass{article}
\usepackage{glossaries}

\makeglossaries

\newglossaryentry{maths}
{
    name=mathematics,
    description={数学就是数学家所做的事情}
}

\newglossaryentry{latex}
{
    name=latex,
    description={是一种特别适合于
科学文档的标记语言}
}

\newglossaryentry{formula}
{
    name=formula,
    description={一个数学表达式}
}

\begin{document}

LaTeX 排版标记语言 \Gls{latex} 特别适合
用于包含 \gls{maths} 的文档。\Glspl{formula} 会被渲染
在熟悉这些命令后能够被正确且轻松地显示。

\clearpage

\printglossary[title=Special Terms, toctitle=List of terms]

\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+Glossary+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bglossaries%7D%0A%0A%5Cmakeglossaries%0A%0A%0A%5Cnewglossaryentry%7Bmaths%7D%0A%7B%0A++++name%3Dmathematics%2C%0A++++description%3D%7BMathematics+is+what+mathematicians+do%7D%0A%7D%0A%0A%5Cnewglossaryentry%7Blatex%7D%0A%7B%0A++++name%3Dlatex%2C%0A++++description%3D%7BIs+a+markup+language+specially+suited+for+%0Ascientific+documents%7D%0A%7D%0A%0A%0A%5Cnewglossaryentry%7Bformula%7D%0A%7B%0A++++name%3Dformula%2C%0A++++description%3D%7BA+mathematical+expression%7D%0A%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0AThe+%5CGls%7Blatex%7D+typesetting+markup+language+is+specially+suitable+%0Afor+documents+that+include+%5Cgls%7Bmaths%7D.+%5CGlspl%7Bformula%7D+are+rendered+%0Aproperly+an+easily+once+one+gets+used+to+the+commands.%0A%0A%5Cclearpage%0A%0A%5Cprintglossary%5Btitle%3DSpecial+Terms%2C+toctitle%3DList+of+terms%5D%0A%0A%5Cend%7Bdocument%7D)

下图显示了上面示例产生的部分输出：

![Glossary5OLV2.png](/files/cabe39162764559ad61cb58f5d83eedcacdcfb44)

注意命令 `\printglossary` 有两个以逗号分隔的参数：

* `title=Special Terms` 是显示在术语表顶部的标题。
* `toctitle=List of terms` 这是要显示在目录中的条目。参见 [下一节](#show-the-glossary-in-the-table-of-contents).

## 在目录中显示术语表

要让术语表出现在目录中，请将

```latex
\usepackage[toc]{glossaries}
```

添加到文档的导言区

```latex
\documentclass{article}
\usepackage[toc]{glossaries}

\makeglossaries

\newglossaryentry{maths}
{
    name=mathematics,
    description={数学就是数学家所做的事情}
}

\newglossaryentry{latex}
{
    name=latex,
    description={是一种特别适合于
科学文档的标记语言}
}

\newglossaryentry{formula}
{
    name=formula,
    description={一个数学表达式}
}

\begin{document}

\tableofcontents

\section{First Section}
LaTeX 排版标记语言 \Gls{latex} 特别适合
用于包含 \gls{maths} 的文档。\Glspl{formula} 会被渲染
在熟悉这些命令后能够被正确且轻松地显示。

\clearpage

\printglossary[title=Special Terms, toctitle=List of terms]

\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+Glossary+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Btoc%5D%7Bglossaries%7D%0A%0A%5Cmakeglossaries%0A%0A%5Cnewglossaryentry%7Bmaths%7D%0A%7B%0A++++name%3Dmathematics%2C%0A++++description%3D%7BMathematics+is+what+mathematicians+do%7D%0A%7D%0A%0A%5Cnewglossaryentry%7Blatex%7D%0A%7B%0A++++name%3Dlatex%2C%0A++++description%3D%7BIs+a+markup+language+specially+suited+for+%0Ascientific+documents%7D%0A%7D%0A%0A%0A%5Cnewglossaryentry%7Bformula%7D%0A%7B%0A++++name%3Dformula%2C%0A++++description%3D%7BA+mathematical+expression%7D%0A%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0A%5Ctableofcontents%0A%0A%5Csection%7BFirst+Section%7D+%0AThe+%5CGls%7Blatex%7D+typesetting+markup+language+is+specially+suitable+%0Afor+documents+that+include+%5Cgls%7Bmaths%7D.+%5CGlspl%7Bformula%7D+are+rendered+%0Aproperly+an+easily+once+one+gets+used+to+the+commands.%0A%0A%5Cclearpage%0A%0A%5Cprintglossary%5Btitle%3DSpecial+Terms%2C+toctitle%3DList+of+terms%5D%0A%0A%5Cend%7Bdocument%7D)

下图显示了上面示例产生的两页内容。注意命令

```latex
\printglossary[title=Special Terms, toctitle=List of terms]
```

为目录（“List of terms”）和文本中相应的标题（“Special Terms”）生成了不同的标题：

![Glossary6OLV2.png](/files/fb8da7ac09f3362902355a5f05107056949dd2c5)

## 编译术语表

要编译包含术语表的文档，在 [Overleaf](http://overleaf.com) 中你不需要做任何特殊操作，但如果你在编译后向术语表添加了新术语，请确保点击 *清除缓存文件* （首先在 logs 选项下）。

如果你正在编译文档，例如一个名为 `glossaries.tex`，使用 pdflatex **在你的本地机器上**，你必须使用这些命令：

`pdflatex glossaries.tex`

`makeglossaries glossaries`

`pdflatex glossaries.tex`

## 参考指南

**术语表可用样式**

命令 `\setglossarystyle{style}` 必须插入到 `\printglossaries`之前。下面是可用样式列表：

* list。将定义的术语以粗体字体写出
* altlist。在术语后插入换行并缩进描述。
* listgroup。根据首字母对术语分组。
* listhypergroup。在索引顶部添加超链接。

## 进一步阅读

更多信息请参见：

* [索引](/latex/zh-cn/wen-dang-jie-gou/04-indices.md)
* [表格和图形列表](/latex/zh-cn/tu-xing-he-biao-ge/03-lists-of-tables-and-figures.md)
* [目录](/latex/zh-cn/wen-dang-jie-gou/02-table-of-contents.md)
* [节与章](/latex/zh-cn/wen-dang-jie-gou/01-sections-and-chapters.md)
* [超链接](/latex/zh-cn/wen-dang-jie-gou/09-hyperlinks.md)
* [国际语言支持](/latex/zh-cn/yu-yan/03-international-language-support.md)
* [章节和公式交叉引用](/latex/zh-cn/wen-dang-jie-gou/03-cross-referencing-sections-equations-and-floats.md)
* [大型项目中的管理](/latex/zh-cn/wen-dang-jie-gou/07-management-in-a-large-project.md)
* [多文件 LaTeX 项目](/latex/zh-cn/wen-dang-jie-gou/08-multi-file-latex-projects.md)
* [WikiBooks 上的术语表文章](http://en.wikibooks.org/wiki/LaTeX/Glossary)
* [glossaries 宏包：初学者指南](http://theoval.cmp.uea.ac.uk/~nlct/latex/packages/glossaries/glossariesbegin.html)


---

# 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://ayakaleaf-pro.ayaka.space/latex/zh-cn/wen-dang-jie-gou/05-glossaries.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.
