The glossaries package
Manages a glossary and a list of acronyms: terms are defined once with \newglossaryentry or \newacronym, used with \gls and listed with \printglossaries.
Loading the package
\usepackage[acronym]{glossaries}Each term gets a label, a name and a description in the preamble. In the text \gls{label} prints the name. For an acronym the first use prints the long form with the short form in parentheses, and every later use prints the short form.
The lists contain only the terms that were used, sorted alphabetically and with the page numbers of their uses. An external program does the sorting: after the first LaTeX run, makeglossaries processes the files that \makeglossaries created, and a second LaTeX run reads the result.
Main commands
\makeglossaries | Preamble: switches on the files for the external sorting. |
\newglossaryentry{kernel}{name={kernel}, description={...}} | Defines a glossary term. |
\newacronym{pdf}{PDF}{Portable Document Format} | Defines an acronym: label, short form, long form. |
\gls{pdf} | Uses a term. \Gls starts with a capital letter, \glspl prints the plural. |
\acrshort{pdf}, \acrlong{pdf}, \acrfull{pdf} | Force the short, long or full form of an acronym. |
\printglossaries | Prints all lists. \printglossary[type=\acronymtype] prints only the acronyms. |
\usepackage[acronym,toc]{glossaries} | acronym creates a separate list of acronyms, toc adds the lists to the table of contents. |
\glsaddall | Lists all defined terms, also the ones that were not used. |
Complete example
\documentclass{article}
\usepackage[acronym]{glossaries}
\makeglossaries
\newglossaryentry{kernel}{name={kernel},
description={The core commands of LaTeX that every document loads}}
\newacronym{pdf}{PDF}{Portable Document Format}
\begin{document}
\section{Output}
The \gls{kernel} writes a \gls{pdf} file. The second use is short: \gls{pdf}.
\printglossaries
\end{document}Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → makeglossaries → pdflatex.
Pitfalls
- Without the
makeglossariesstep,\printglossariesprints nothing and there is no error message. - Load the package after
hyperref. Loaded before it, the terms in the text are not linked to their entries. makeglossariesis a Perl script. Where Perl is missing,makeglossaries-litedoes the same with Lua, and\makenoidxglossarieswith\printnoidxglossarieslets LaTeX sort the entries without any external program.\glsin a heading counts as the first use and ends up in the table of contents. Use\glsentrytext{label}there.
Related pages
- How-to Glossary and list of acronyms in LaTeX
- Package
acronym - Package
nomencl - Package
hyperref