LaTeX Glossary & Acronyms
Use the glossaries package. Define terms with \newglossaryentry, acronyms with \newacronym. Reference in body with \gls{name}.
Setup
\usepackage{glossaries}
\makeglossaries
% Define terms in preamble
\newglossaryentry{algorithm}{
name={algorithm},
description={A finite sequence of well-defined instructions}
}
% Define acronyms
\newacronym{NLP}{NLP}{Natural Language Processing}
\newacronym{ML}{ML}{Machine Learning}
\newacronym{API}{API}{Application Programming Interface}
\begin{document}
% In body text:
The \gls{algorithm} runs in linear time.
We use \gls{NLP} techniques (first use expands to full).
\gls{NLP} is widely used (subsequent uses just show short form).
% Print glossary at the end
\printglossaries
\end{document}Compile sequence
pdflatex main # first pass: writes glossary entries
makeglossaries main # sorts and processes entries
pdflatex main # reads sorted glossary
pdflatex main # final pass for cross-referencesAcronym variants
| Command | Output |
|---|---|
| \gls{NLP} | First use: "Natural Language Processing (NLP)"; later: "NLP" |
| \acrshort{NLP} | Always: "NLP" |
| \acrlong{NLP} | Always: "Natural Language Processing" |
| \acrfull{NLP} | Always: "Natural Language Processing (NLP)" |
| \Gls{NLP} | Capitalized first letter (sentence start) |
| \glspl{NLP} | Plural form (NLPs / Natural Language Processings) |
Simpler alternative: the acronym package
\usepackage{acronym}
\begin{acronym}
\acro{NLP}{Natural Language Processing}
\acro{ML}{Machine Learning}
\end{acronym}
% In body:
\ac{NLP} is widely used. % first use: "Natural Language Processing (NLP) is widely used."
We apply \ac{NLP} methods. % later: "We apply NLP methods."Less powerful than glossaries (no separate symbol/glossary lists, fewer features), but simpler to set up — no makeglossaries step required.
Common mistakes
- Skipping
makeglossaries. Glossary won't sort or appear. Run pdflatex → makeglossaries → pdflatex → pdflatex. - Forgetting
\makeglossariesin preamble. Without it, no glossary file is generated. - Mixing glossaries and glossaries-extra. Pick one — they share macros but have minor incompatibilities.
- Using
\glsat very start of paragraph after intro. First-use detection works on the whole document, so the "first use" might happen later than you expected. Use\acrfullif you want explicit first-use form.
Frequently Asked Questions
Use the glossaries package: \usepackage{glossaries} \makeglossaries. Define terms with \newglossaryentry. Reference in body with \gls{name}. Print the glossary with \printglossaries. Compile with: pdflatex → makeglossaries main → pdflatex → pdflatex.
glossaries is the original package. glossaries-extra is a modernized superset with better defaults, easier syntax, and more options. Both are maintained. For new documents, glossaries-extra is recommended unless you have specific reason to use the older one.
\newacronym{NLP}{NLP}{Natural Language Processing}. Three arguments: label, short form, long form. Then \acrshort{NLP} prints just 'NLP'; \acrlong{NLP} prints 'Natural Language Processing'; \acrfull{NLP} prints 'Natural Language Processing (NLP)'. \gls{NLP} auto-handles first-use (full) vs subsequent (short).
The first time you write \gls{NLP}, it expands to 'Natural Language Processing (NLP)'. Subsequent uses produce just 'NLP'. The package tracks first use automatically. \glsfirst forces full first-use form; \acrshort forces just the abbreviation.
Use multiple glossaries: \newglossary{symbols}{symbols} for symbols, \newglossary[alg]{acronyms}{acn} for acronyms. Or with glossaries-extra: \GlsXtrLoadResources for fine-grained control. Then \printglossaries prints all, or \printglossary[type=acronyms] for just one.
\gls already creates a hyperlink (with hyperref loaded). For a custom link with the long form: \glsdesc{NLP} → 'Natural Language Processing'. For just the short with first-use rules: \gls{NLP}. Combine with hyperref's link colors as usual.
Default behavior. The glossaries package sorts entries alphabetically by their 'sort' field (defaults to the entry name). Override sort with sort={...} in \newglossaryentry to customize order. The makeglossaries program does the actual sorting.
For just acronyms (not full glossaries), the acronym package is much simpler: \usepackage{acronym}, then \begin{acronym} \acro{NLP}{Natural Language Processing} \end{acronym}. Use \ac{NLP} which auto-handles first-use. Less powerful than glossaries but enough for many papers.
You likely missed the makeglossaries step. The full sequence: pdflatex → makeglossaries main → pdflatex → pdflatex. Most LaTeX editors (Overleaf, TeXShop) handle this automatically. On command line, you have to run makeglossaries manually.