LaTeX/術語表
許多技術文件使用普通人群不瞭解的術語或縮略詞。通常的做法是新增一個術語表,以使此類文件更容易理解。
可以使用glossaries包建立術語表。它支援多個術語表、縮略詞和符號。此包替換了glossary包,可以用作nomencl包的替代方案。[1]需要更簡單解決方案的使用者應考慮使用以下方法手動編碼其條目描述環境,或longtabutabu包提供的環境。
在你的前言中(如果存在,則在\usepackage{hyperref}之後)放置\usepackage{glossaries}和\makeglossaries。然後在你的前言(推薦)或文件正文中第一次使用之前定義任意數量的\newglossaryentry和\newacronym術語表和縮略詞條目。最後新增一個\printglossaries呼叫以在你的文件結構中定位術語表列表。然後用\gls{mylabel}宏(以及類似的宏)來同時插入你預定義的文字並構建相關的術語表。檔案處理現在必須包括對makeglossaries document_name_without_extension的呼叫,然後至少再呼叫一次latex或pdflatex。
要使用glossaries包,您必須顯式載入它
\usepackage{glossaries}
|
如果你想使用xindy(高階索引工具[2])用於索引階段,而不是makeindex(預設值),您需要指定xindy選項
\usepackage[xindy]{glossaries}
|
為了使術語表顯示在您的目錄中,您需要指定toc選項
\usepackage[toc]{glossaries}
|
另請參閱本頁面底部的自定義名稱。
最後,將以下命令放在你的文件前言中以生成術語表
\makeglossaries
|
除非你在hyperref包之後載入glossaries包,否則生成的術語表中的任何連結都將不可點選。
此外,希望使用makeglossaries的使用者需要安裝Perl——這通常不是Microsoft Windows平臺上的預設設定。也就是說,makeglossaries僅提供了一個方便的介面到makeindex和xindy並且不是必需的。
要使用術語表中的條目,您首先需要定義它。根據您定義的內容以及如何使用它,有幾種方法可以定義條目。
請注意,除非在文件中使用,否則已定義的條目不會包含在列印的術語表中。這使您可以建立一個通用術語的術語表,並將其\include到所有文件中。
要在術語表中定義術語,請使用\newglossaryentry宏
\newglossaryentry{<label>}{<settings>}
|
<label>是用於標識術語表中條目的唯一標籤,<settings>是逗號分隔的key=value對,用於定義條目。
例如,要定義一個計算機條目
\newglossaryentry{computer}
{
name=computer,
description={is a programmable machine that receives input,
stores and manipulates data, and provides
output in a useful format}
}
|
上面的示例定義了一個標籤和條目名稱相同的條目。這並不總是這樣,因為下一個條目將顯示
\newglossaryentry{naiive}
{
name=na\"{\i}ve,
description={is a French loanword (adjective, form of naïf)
indicating having or showing a lack of experience,
understanding or sophistication}
}
|
當您定義術語時,您需要記住它們將按以下排序makeindex或xindy。雖然xindy更瞭解 LaTeX,但它透過省略 latex 宏(\"{\i})來實現,從而錯誤地將上述示例排序為nave.
makeindex效果也不會好很多,因為它不理解 TeX 宏,它會完全按照定義的方式解釋該詞,將其放在符號類中,在以naa開頭的單詞之前。因此,需要擴充套件我們的示例並指定如何對單詞進行排序
\newglossaryentry{naiive}
{
name=na\"{\i}ve,
description={is a French loanword (adjective, form of naïf)
indicating having or showing a lack of experience,
understanding or sophistication},
sort=naiive
}
|
您還可以指定複數形式,如果它們不是透過新增“s”來形成的(我們將在下一節中學習如何使用它們)
\newglossaryentry{Linux}
{
name=Linux,
description={is a generic term referring to the family of Unix-like
computer operating systems that use the Linux kernel},
plural=Linuces
}
|
或者,對於首字母縮略詞
\newacronym[longplural={Frames per Second}]{fpsLabel}{FPS}{Frame per Second}
|
這將避免錯誤的長複數:Frame per Seconds。
到目前為止,術語表條目被定義為鍵值列表。有時,描述比僅僅一段話更復雜。例如,您可能希望有多個段落、專案符號列表、圖形、表格等。對於此類術語表條目,請使用命令longnewglossaryentry其中描述跟隨鍵值列表。然後,計算機條目如下所示
\longnewglossaryentry{computer}
{
name=computer
}
{is a programmable machine that receives input,
stores and manipulates data, and provides
output in a useful format}
|
已定義的條目也可以是符號
\newglossaryentry{pi}
{
name={\ensuremath{\pi}},
description={ratio of circumference of circle to its
diameter},
sort=pi
}
|
您還可以同時定義名稱和符號
\newglossaryentry{real number}
{
name={real number},
description={include both rational numbers, such as $42$ and
$\frac{-23}{129}$, and irrational numbers,
such as $\pi$ and the square root of two; or,
a real number can be given by an infinite decimal
representation, such as $2.4871773339\ldots$ where
the digits continue in some way; or, the real
numbers may be thought of as points on an infinitely
long number line},
symbol={\ensuremath{\mathbb{R}}}
}
|
請注意,並非所有術語表樣式都顯示已定義的符號。
要定義一個新的首字母縮略詞,您可以使用 \newacronym 宏
\newacronym{<label>}{<abbrv>}{<full>}
|
其中 <label> 是標識首字母縮略詞的唯一標籤,<abbrv> 是首字母縮略詞的縮寫形式,<full> 是擴充套件文字。例如
\newacronym{lvm}{LVM}{Logical Volume Manager}
|
如果使用,則可以將已定義的首字母縮略詞放在單獨的列表中acronym包選項
\usepackage[acronym]{glossaries}
|
定義術語後,您可以在文件中使用它。有許多不同的命令用於引用術語表術語。
常規引用與 \gls 命令一起使用。例如,如果您將術語表條目定義為上述條目,則可以使用以下方式使用它
\Gls{naiive} people don't know about
alternative \gls{computer} operating systems:
\glspl{Linux}, BSDs and GNU/Hurd.
|
天真的人不知道替代計算機操- |
上述示例中使用的命令說明
\gls{<label>}
|
此命令列印與其引數傳遞的 <label> 關聯的術語。如果在 glossaries 之前載入了 hyperref 包,它也將超連結到術語表中的條目。
\glspl{<label>}
|
此命令列印已定義術語的複數形式,除此之外,它的行為方式與 gls 相同。
\Gls{<label>}
|
此命令列印術語的單數形式,並將第一個字元轉換為大寫。
\Glspl{<label>}
|
此命令列印複數形式,並將術語的第一個字母轉換為大寫。
\glslink{<label>}{<alternate text>}
|
此命令照常建立連結,但會排版替代文字。它還可以採用一些選項來更改其預設行為(請參閱文件)。
\glssymbol{<label>}
|
此命令列印在 \newglossaryentry{<label>}{symbol={glssymbol 的輸出}, ...} 中定義的內容。
\glsdesc{<label>}
|
此命令列印在 \newglossaryentry{<label>}{description={glsdesc 的輸出}, ...} 中定義的內容。
首字母縮略詞的行為與普通術語表術語略有不同。在第一次使用時,\gls 命令將顯示“<full> (<abbrv>)”。在隨後的使用中,只會顯示縮寫。如果這種情況沒有發生,則需要設定 \setacronymstyle{long-short}。
要重置首字母縮略詞的第一次使用,請使用命令
\glsreset{<label>}
|
或者,如果要重置所有首字母縮略詞的使用狀態
\glsresetall
|
類似地,要取消設定首字母縮略詞的第一次使用,以便僅顯示縮寫,請使用
\glsunset{<label>}
|
或者,對於所有首字母縮略詞
\glsunsetall
|
如果您只想列印首字母縮略詞的長版本而不帶縮寫“<full>”,請使用
\acrlong{<label>}
|
如果您只想列印首字母縮略詞的長版本以及縮寫“<full> (<abbrv>)”,請使用
\acrfull{<label>}
|
如果您只想列印縮寫“<abbrv>”,請使用
\acrshort{<label>}
|
要顯示排序的術語列表,您需要新增
\printglossaries
|
在您希望術語表和首字母縮略詞列表出現的位置。
如果要列印所有條目,則可以在 \printglossaries 之前插入命令。
\glsaddall
|
您可能還想使用 \usepackage[nonumberlist]{glossaries} 來抑制術語表中的位置列表。
\printglossaries 將按定義順序顯示所有術語表。[3] 如果沒有定義自定義術語表,則將顯示預設術語表和首字母縮略詞列表。
術語表和首字母縮略詞列表可以分別顯示在不同位置[4]
\usepackage[acronyms]{glossaries}
\printglossary[type=\acronymtype] % prints just the list of acronyms
Some text between the list of acronyms and the glossary.
\printglossary % if no option is supplied the default glossary is printed.
|
對同一術語同時擁有首字母縮略詞和術語表條目可能很有用。要連結這兩個條目,請使用以下方式定義首字母縮略詞,其中包含對術語表條目的引用
\newglossaryentry{gls-OWD} {
name={One-Way Delay},
description={The time a packet uses through a network from one host to another},
}
\newacronym[see={[Glossary:]{gls-OWD}}]{OWD}{OWD}{One-Way Delay\glsadd{gls-OWD}}
|
Refer to acronym with \gls{OWD} and the glossary with \gls{gls-OWD}
為了簡化操作,我們可以使用此命令(修改自官方文件中的示例)
Syntax: \newdualentry[glossary options][acronym options]{label}{abbrv}{long}{description}
\usepackage{xparse}
\DeclareDocumentCommand{\newdualentry}{ O{} O{} m m m m } {
\newglossaryentry{gls-#3}{name={#5},text={#5\glsadd{#3}},
description={#6},#1
}
\makeglossaries
\newacronym[see={[Glossary:]{gls-#3}},#2]{#3}{#4}{#5\glsadd{gls-#3}}
}
|
然後,為術語表和首字母縮略詞列表定義新的(雙重)條目,如下所示
\newdualentry{OWD} % label
{OWD} % abbreviation
{One-Way Delay} % long form
{The time a packet uses through a network from one host to another} % description
|
術語表部分的名稱可以用自定義名稱替換或翻譯成不同的語言。將選項 title 新增到 \printglossary 以指定術語表的標題。新增選項 toctitle 以指定在目錄中使用的標題(如果未使用,則 title 用作預設值)。[5]
\printglossary[title=List of Terms,toctitle=Terms and abbreviations]
|
要省略每個描述結尾處的句點,請使用以下程式碼
\usepackage[nopostdot]{glossaries}
|
許多預建樣式可用,並且可以使用以下方法輕鬆更改
% Must be issued before \printglossaries
\setglossarystyle{<newstyle>}
|
常用的樣式包括
- 列表
My Term Has some long description 7, 9
- altlist(在術語後插入換行符並縮排描述)
My Term Has some long description 7, 9
- altlistgroup 或 listgroup(group 根據術語的首字母新增分組)
M My First Term Has some long description 7, 9 My Second Term Has some long description 7, 9
- altlisthypergroup 或 listhypergroup(hyper 在每個術語表頂部新增一個超連結“索引”以跳轉到一個組)
A|B|C|D|F|G|I|M|O|R|S|C|D|G|M|P A A First term Has some long description 7, 9 B Barely missed first Has some long description 7, 9
要將術語表新增到最終文件中,需要
- 構建您的 LaTeX 文件——這也會生成術語表所需的 aux 檔案makeglossaries
- 呼叫makeglossaries——一個指令碼,它選擇正確的字元編碼和語言設定,並且也會執行xindy或makeindex如果這些在您的文件檔案中指定
- 再次構建您的 LaTeX 文件——以生成包含術語表條目的文件
因此
latex doc makeglossaries doc latex doc
其中latex是您通常的構建呼叫,可能是 pdflatex、lualatex 和doc是您的 LaTeX 主檔案的檔名(不含副檔名)。選項 -d out 可用於指定 aux 和其他中間檔案的位置。如果您的條目相互連結(條目本身使用 \gls 呼叫連結到其他條目),則需要執行步驟 1 和 2 兩次,即按以下順序:1、2、1、2、3。
任何問題都將在doc.log和doc.glg檔案中報告。
在 TeX Live 中,以及從 2015 年 6 月開始在 MikTeX 中,xindy 已經包含在內。
MikTeX 安裝目錄路徑中存在空格的問題。可以透過以下編輯解決:http://tex.stackexchange.com/questions/251221/miktex-and-xindy-problems/251801#251801
您需要在安裝xindy後重新啟動 Texmaker,以更新對xindy和 Perl 二進位制檔案的 PATH 引用。
然後,在 Texmaker 中,轉到使用者 -> 使用者命令 -> 編輯使用者命令。
選擇命令 1
- 選單項 = makeglossaries
- 命令 = makeglossaries %
現在按下Alt+Shift+F1,然後 ->F1
注意,對於 Texmaker 的“使用構建目錄”選項:makeglossaries 需要找到 aux 檔案。值得慶幸的是,雖然 Texmaker 在這裡沒有提供幫助,但 makeglossaries 的選項-d <dir> 提供了子目錄的情況。因此,在這種情況下,命令應為
命令 = makeglossaries -d build %。
應在前言中包含(注意,hyperref 應在glossaries 之前載入)
\usepackage[nomain,acronym,xindy,toc]{glossaries} % nomain, if you define glossaries in a file, and you use \include{INP-00-glossary}
\makeglossaries
\usepackage[xindy]{imakeidx}
\makeindex
將所有術語表/首字母縮略詞寫入一個檔案:例如:INP-00-glossary.tex
\newacronym{ddye}{D$_{\text{dye}}$}{donor dye, ex. Alexa 488}
\newacronym[description={\glslink{r0}{F\"{o}rster distance}}]{R0}{$R_{0}$}{F\"{o}rster distance}
\newglossaryentry{r0}{name=\glslink{R0}{\ensuremath{R_{0}}},text=F\"{o}rster distance,description={F\"{o}rster distance, where 50\% ...}, sort=R}
\newglossaryentry{kdeac}{name=\glslink{R0}{\ensuremath{k_{DEAC}}},text=$k_{DEAC}$, description={is the rate of deactivation from ... and emission)}, sort=k}
在前言中包含術語表定義(在“\begin{document}”之前)
\loadglsentries[main]{INP-00-glossary}
% or using \input:
%\input{INP-00-glossary}
\begin{document}
列印術語表,靠近結尾
\appendix
\bibliographystyle{plainnat}
\bibliography{bibtex}
\printindex
\printglossaries
\end{document}
- ↑ http://www.ctan.org/pkg/nomencl
- ↑ “xindy”和“makeindex”的區別
- ↑ http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/glossaries/glossaries-user.html#dx1-35001
- ↑ http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/glossaries/glossaries-user.html#dx1-43001
- ↑ 2014.01.13 時的 glossaries.sty v4.02 使用者手冊 http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/glossaries/glossaries-user.html#sec:printglossary
- 使用 LaTeX 撰寫博士論文,Nicola L.C. Talbot,[1]
- glossaries 常見問題解答,Nicola L. C. Talbot,glossaries 常見問題解答
- 術語表、命名法、符號和首字母縮略詞列表,Nicola L. C. Talbot,連結

