LaTeX/Glossary
| Getting Started
Common Elements
Mechanics Technical Texts
Special Pages Special Documents Creating Graphics Programming Miscellaneous Help and Recommendations Appendices |
Many technical documents use terms or acronyms unknown to the general population. It is common practice to add a glossary to make such documents more accessible.
The glossaries package can be used to create glossaries. It supports multiple glossaries, acronyms, and symbols. This package replaces the glossary package and can be used instead of the nomencl package.[1] Users requiring a simpler solution should consider using the longtabu environment and hand-coding their entries.
Contents |
Jump start [edit]
Place \usepackage{glossaries} and \makeglossaries in your preamble (after \usepackage{hyperref} if present). Then define any number of \newglossaryentry and \newacronym glossary and acronym entries in your preamble (recommended) or before first use in your document proper. Finally add a \printglossaries call to locate the glossaries list within your document structure. Then pepper your writing with \gls{mylabel} macros (and similar) to simultaneously insert your predefined text and build the associated glossary. File processing must now include a call to makeglossaries followed by at least one further invocation of latex or pdflatex.
Using glossaries [edit]
To use the glossaries package, you have to load it explicitly:
|
\usepackage{glossaries} |
if you wish to use xindy (recommended) for the indexing phase, as opposed to makeindex (the default), you need to specify the xindy option:
|
\usepackage[xindy]{glossaries} |
For the glossary to show up in your Table of Contents, you need to specify the toc option:
|
\usepackage[toc]{glossaries} |
See also Custom TOC Entry at the bottom of this page.
Finally, place to following command in your document preamble in order to generate the glossary:
|
\makeglossaries |
Any links in resulting glossary will not be "clickable" unless you load the glossaries package after the hyperref package.
In addition, users who wish to make use of makeglossaries will need to have Perl installed — this is not normally present by default on Microsoft Windows platforms. That said, makeglossaries simply provides a convenient interface to makeindex and xindy and is not essential.
Defining glossary entries [edit]
To use an entry from glossary you first need to define it. There are few ways to define an entry depending on what you define and how it is going to be used.
Note that a defined entry won't be included in the printed glossary unless it is used in the document. This enables you to create a glossary of general terms and just \include it in all your documents.
Defining terms [edit]
To define a term in glossary you use \newglossaryentry macro:
|
\newglossaryentry{<label>}{<settings>} |
<label> is a unique label used to identify an entry in glossary, <settings> are comma separated key=value pairs used to define an entry.
For example, to define a computer entry:
|
\newglossaryentry{computer} |
The above example defines an entry that has the same label and entry name. This is not always the case as the next entry will show:
|
\newglossaryentry{naiive} |
When you define terms, you need to remember that they will be sorted by makeindex or xindy. While xindy is a bit more LaTeX aware, it does it by omitting latex macros (\"{\i}) thus incorrectly sorting the above example as nave. makeindex won't fare much better, because it doesn't understand TeX macros, it will interpret the word exactly as it was defined, putting it inside symbol class, before words beginning with naa. Therefore it's needed to extend our example and specify how to sort the word:
|
\newglossaryentry{naiive} |
You can also specify plural forms, if they are not formed by adding “s” (we will learn how to use them in next section):
|
\newglossaryentry{Linux} |
Or, for acronyms:
|
\newacronym[longplural=Frames per Second]{FPS}{fpsLabel}{Frame per Second} |
This will avoid the wrong long plural: Frame per Seconds.
Defining symbols [edit]
Defined entries can also be symbols:
|
\newglossaryentry{pi} |
You can also define both a name and a symbol:
|
\newglossaryentry{real number} |
Note that not all glossary styles show defined symbols.
Defining acronyms [edit]
To define a new acronym you use the \newacronym macro:
|
\newacronym{<label>}{<abbrv>}{<full>} |
where <label> is the unique label identifying the acronym, <abbrv> is the abbreviated form of the acronym and <full> is the expanded text. For example:
|
\newacronym{lvm}{LVM}{Logical Volume Manager} |
Defined acronyms can be put in separate list if you use acronym package option:
|
\usepackage[acronym]{glossaries} |
Using defined terms [edit]
When you have defined a term, you can use it in a document. There are many different commands used to refer to glossary terms.
General references [edit]
A general reference is used with \gls command. If, for example, you have glossary entries defined as those above, you might use it in this way:
|
\Gls{naiive} people don't know about |
Naïve people don't know about alternative computer opera- |
Description of commands used in above example:
|
\gls{<label>} |
This command prints the term associated with <label> passed as its argument. If the hyperref package was loaded before glossaries it will also be hyperlinked to the entry in glossary.
|
\glspl{<label>} |
This command prints the plural of the defined term, other than that it behaves in the same way as gls.
|
\Gls{<label>} |
This command prints the singular form of the term with the first character converted to upper case.
|
\Glspl{<label>} |
This command prints the plural form with first letter of the term converted to upper case.
|
\glslink{<label>}{<alternate text>} |
This command creates the link as usual, but typesets the alternate text instead. It can also take several options which changes its default behavior (see the documentation).
Referring acronyms [edit]
Acronyms behave a bit differently than normal glossary terms. On first use the \gls command will display "<full> (<abbrv>)". On subsequent uses only the abbreviation will be displayed.
To reset the first use of an acronym use:
|
\glsreset{<label>} |
or, if you want to reset the use status of all acronyms:
|
\glsresetall |
Displaying the Glossary [edit]
To display the sorted list of terms you need to add:
|
\printglossaries |
at the place you want the glossary and the list of acronyms to appear.
If all entries are to be printed the command
|
\glsaddall |
can be inserted before \printglossaries. You may also want to use \usepackage[nonumberlist]{glossaries} to suppress the location list within the glossary.
Separate Glossary and List of Acronyms [edit]
\printglossaries will display all the glossaries in the order in which they were defined.[2] If no custom glossaries are defined, the default glossary and the list of acronyms will be displayed.
The glossary and the list of acronyms can be displayed separately in different places[3]:
|
\usepackage[acronym]{glossaries} |
Custom Name [edit]
The name of the glossary section can be replaced with a custom name or translated to a different language:
|
\renewcommand*{\glossaryname}{List of Terms} |
Custom TOC Entry [edit]
When the toc option is added to the usepackage command, the glossary is embedded in the TOC as a section. Use the following code (and omit the toc parameter) to display the TOC as you wish (here as a subsection):
|
\addcontentsline{toc}{subsection}{Glossary} |
Remove the point [edit]
To omit the annoying dot at the end of each description, use this code:
|
\renewcommand*{\glspostdescription}{} |
Building your document [edit]
Building your document and its glossary requires three steps:
- build your LaTeX document — this will also generate the files needed by makeglossaries
- invoke makeglossaries — a script which selects the correct character encodings and language settings and which will also run xindy or makeindex if these are specified in your document file
- build your LaTeX document again — to produce a document with glossary entries
Thus:
latex doc makeglossaries doc latex doc
where latex is your usual build call (perhaps pdflatex) and doc is the name of your LaTeX master file.
If your entries are interlinked (entries themselves link to other entries with \gls calls), you will need to run steps 1 and 2 twice, that is, in the following order: 1, 2, 1, 2, 3.
If you encounter problems, view the doc.log and doc.glg files in a text editor for clues.
Example for use in windows with texmaker [edit]
Compile glossary - In windows with texmaker [edit]
First we need do download and install xindy for windows, this program install includes the perl interpretator for makeglossaries, and of course xindy for sorting, and add to your windows PATH.
You need to restart Texmaker, after the install of xindy, to update PATH references to xindy, and perl.
In Texmaker, go to User -> User Commands -> Edit User Commands.
Chose command 1
- Menuitem = makeglossaries
- Command = makeglossaries %
Now push Alt+Shift+F1and then ->F1
Document preamble [edit]
In preample should be. Note, hyperref should be loaded before the 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
Glossary definitions [edit]
Write all your glossaries/acronyms in a file: Ex: 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}
Incluce glossary defitions and print glossary [edit]
Include glossary defitions
\begin{document}
\include{INP-00-glossary}
Print glossaries, near end
\appendix
\bibliographystyle{plainnat}
\bibliography{bibtex}
\printindex
\printglossaries
\end{document}
References [edit]
- The glossaries documentation, http://tug.ctan.org/tex-archive/macros/latex/contrib/glossaries/
- Using LaTeX to Write a PhD Thesis, Nicola L.C. Talbot, [1]
- glossaries FAQ, Nicola L. C. Talbot, glossaries FAQ
- Glossaries, Nomenclature, Lists of Symbols and Acronyms, Nicola L. C. Talbot, link
The