> 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/wen-jian-jie-gou/05-glossaries.md).

# 詞彙表

## 簡介

當撰寫一份包含某些特定領域概念的文件時，加入詞彙表可能會很方便。詞彙表是在特定知識領域中的術語清單，並附有這些術語的定義。本文將說明如何建立詞彙表。

**重要注意事項**：您的專案的 [主檔案](/latex/zh-tw/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

\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/df9776913695976bda4b20e2afed17e5e094c883)

要建立詞彙表，必須匯入 `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}{最大公因數}

\newacronym{lcm}{LCM}{最小公倍數}

\begin{document}

\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/2d8bc77d66f3984aa0208e3773bff47ec4b0b198)

以下各小節將說明如何建立每一種清單類型。

### 術語

如在 [引言](#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}

\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/6f0119a19f635533b4f4a23f1f3bcbdabc06079d)

讓我們更詳細地看看傳遞給命令的每個參數語法 `\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}{最大公因數}

\newacronym{lcm}{LCM}{最小公倍數}

\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/98dc267db1e4a8e2da6dffef60dcf9304ef9e9d6)

要使用縮寫詞，在匯入 **glossaries** 套件時必須使用額外的參數。要加入前言區的行是

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

一旦加入這一行，命令 `\newacronym` 就會宣告一個新的縮寫詞。作為範例，以下是命令 `\newacronym{gcd}{GCD}{最大公因數}`

* `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}

\Gls{latex} 排版標記語言特別適合
用於包含 \gls{maths} 的文件。\Glspl{formula} 會被
在熟悉這些命令後正確且輕鬆地呈現。

\clearpage

\printglossary[title=特殊術語, toctitle=術語清單]

\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/653b5a18e7428c46e319552bc41c256ec3bfe382)

請注意命令 `\printglossary` 有兩個以逗號分隔的參數：

* `title=特殊術語` 是顯示在詞彙表上方的標題。
* `toctitle=術語清單` 這是在目錄中顯示的項目。請參閱 [下一節](#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{第一節}
\Gls{latex} 排版標記語言特別適合
用於包含 \gls{maths} 的文件。\Glspl{formula} 會被
在熟悉這些命令後正確且輕鬆地呈現。

\clearpage

\printglossary[title=特殊術語, toctitle=術語清單]

\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=特殊術語, toctitle=術語清單]
```

為目錄（「術語清單」）與文本中對應的標題（「特殊術語」）產生了不同的標題：

![Glossary6OLV2.png](/files/17030150c68bcd777d93f7a9f3f0efc471a39085)

## 編譯詞彙表

若要編譯包含詞彙表的文件，使用 [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-tw/wen-jian-jie-gou/04-indices.md)
* [表格與圖形清單](/latex/zh-tw/tu-biao-yu-biao-ge/03-lists-of-tables-and-figures.md)
* [目錄](/latex/zh-tw/wen-jian-jie-gou/02-table-of-contents.md)
* [章節](/latex/zh-tw/wen-jian-jie-gou/01-sections-and-chapters.md)
* [超連結](/latex/zh-tw/wen-jian-jie-gou/09-hyperlinks.md)
* [國際語言支援](/latex/zh-tw/yu-yan/03-international-language-support.md)
* [章節與方程式交叉參照](/latex/zh-tw/wen-jian-jie-gou/03-cross-referencing-sections-equations-and-floats.md)
* [大型專案中的管理](/latex/zh-tw/wen-jian-jie-gou/07-management-in-a-large-project.md)
* [多檔案 LaTeX 專案](/latex/zh-tw/wen-jian-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://overleaf-pro.ayaka.space/latex/zh-tw/wen-jian-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.
