Skip to main content
โšก Calmops

LaTeX Glossary and Index: Creating Reference Materials

Introduction

Professional documents often require glossaries and indexes to help readers navigate content. LaTeX provides robust tools for creating these reference materials automatically.

This guide covers creating glossaries and indexes in LaTeX documents.

The Glossaries Package

Basic Setup

\usepackage{glossaries}

\makeglossaries

\newglossaryentry{latex}
{
  name={LaTeX},
  description={A document preparation system},
  plural={LaTeX}
}

\newglossaryentry{pdf}
{
  name={PDF},
  description={Portable Document Format},
  plural={PDFs}
}

Using Glossary Entries

\begin{document}

The \gls{latex} system is powerful.
The \Gls{pdf} format is universal.
\glspl{pdf} are widely used.

\printglossaries

\end{document}

Compilation

pdflatex document
makeglossaries document
pdflatex document

Glossary Types

Acronyms

\usepackage{glossaries}

\makeglossaries

\newacronym{api}{API}{Application Programming Interface}
\newacronym{cli}{CLI}{Command Line Interface}
\newacronym{json}{JSON}{JavaScript Object Notation}

Usage

\gls{api}
\gls{cli}
\gls{json}

% Plural
\glspl{api}

% First use
\acrfull{api}  % Full form first time
\acrshort{api} % Short form
\acrlong{api}  % Long form

Custom Entries

\newglossaryentry{algorithm}
{
  name={algorithm},
  description={A step-by-step procedure},
  plural={algorithms},
  see=[see also]{procedure}
}

\newglossaryentry{machine learning}
{
  name={machine learning},
  description={Systems that learn from data},
  sort={machine learning}
}

Indexing with makeidx

Basic Index

\usepackage{makeidx}

\makeindex

\begin{document}

\index{LaTeX}
\index{formatting}
\index{packages!hyperref}

\printindex

\end{document}

Index Entries

\index{term}
\index{term!subterm}
\index{term|hyperpage}
\index{term|seealso{related}}
\index{term|textbf}
\index{term@\textit{term}}

\index{A|see{B}}
\index{A|seealso{B}}

Multiple Indexes with imakeidx

Setup

\usepackage{imakeidx}

\makeindex
\makeindex[name=subject,title=Subject Index]
\makeindex[name=name,title=Index of Names]

\index[subject]{Typesetting}
\index[name]{Knuth, Donald}

Compilation

pdflatex document
makeindex subject
makeindex name
pdflatex document

Glossary Styling

Custom Styles

\usepackage{glossaries}

\setglossarystyle{long}
\setglossarystyle{longheader}
\setglossarystyle{long3col}
\setglossarystyle{altlist}
\setglossarystyle{altlistgrouped}
\setglossarystyle{bookindex}
\setglossarystyle{index}
\setglossarystyle{indexgrouped}
\setglossarystyle{mcolindex}
\setglossarystyle{mcolindexgrouped}
\setglossarystyle{mcolalttree}
\setglossarystyle{alttree}
\setglossarystyle{tree}

Customization

% Change symbols
\defglsentryfmt[main]{\glsentrytext{\glslabel}}

% Add to groups
\glsaddstoragekey{group}{}{\glsentrygroup}

Index Styles

Style File

% mystyle.ist
headings_flag 1
heading_prefix "{\\bfseries "
heading_suffix "}"
group_skip ""

Using Custom Styles

\usepackage{imakeidx}

\makeindex[title=General Index,intoc=true]
\makeindex[name=subject,title=Subject Index,mystyle.ist]

Best Practices

Entry Organization

  1. Define terms in preamble
  2. Use consistent naming
  3. Add cross-references
  4. Sort properly

Index Tips

  • Index important terms
  • Use subentries for detail
  • Include variant spellings
  • Cross-reference related terms

Conclusion

LaTeX provides comprehensive tools for glossaries and indexes. Use glossaries for definitions and acronyms, and indexes for comprehensive topic navigation.

Resources

Comments