Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.

Gallery: Citations in Glossary

image of glossary where a citation follows the description in parentheses
This example has citations associated with some entries. For simplicity I’ve just used the sample xampl.bib file that should be available on all TeX distributions.

The citation labels are stored in the user1 field (one of the custom fields). Since none of the predefined glossary styles are suitable, this example defines and uses its own custom style. (A much simpler approach can be obtained with the glossaries-extra package.) The style is based on the list style (\setglossarystyle{list}) but it’s modified to check if the useri field is set (useri is the internal field name corresponding to the user1 key). To allow for the possibility of a comma-separated list of citations, the value of the useri is fetched and stored in a control sequence using \glsletentryfield which is then expanded before being processed by \cite.

Remember that since the citations are in the glossary, the glossary has to be created before the bibliography.

The initial comment lines below are arara directives. You can remove them if you don’t use arara.

 % arara: pdflatex
 % arara: makeglossaries
 % arara: pdflatex
 % arara: bibtex
 % arara: pdflatex
 % arara: pdflatex
\documentclass{report}

\usepackage[colorlinks]{hyperref}
\usepackage[nopostdot,toc]{glossaries}

\makeglossaries

\loadglsentries{example-glossaries-cite}

\newglossarystyle{cites}
{% based on list style
  \setglossarystyle{list}%
    \renewcommand*{\glossentry}[2]{%
    \item[\glsentryitem{##1}%
          \glstarget{##1}{\glossentryname{##1}}]
       \glossentrydesc{##1}\glspostdescription
    \ifglshasfield{useri}{##1}{\space
     % in the event of multiple cites (as in the vestibulum2
     % sample entry), \glsentryuseri{##1} needs to be expanded
     % before being passed to \cite.
     \glsletentryfield{\thiscite}{##1}{useri}%
     (See \expandafter\cite\expandafter{\thiscite})}{}%
    \space ##2}%
}

\begin{document}

\chapter{Sample}

\forglsentries{\thislabel}{\gls{\thislabel}. }

\printglossary[style=cites,nopostdot=false,nogroupskip]

\bibliographystyle{plain}
\bibliography{xampl}

\end{document}

This document loads the hyperref package, which creates hyperlinks from the entries in the document (referenced using commands like \gls) to their definition in the glossary. These hyperlinks are displayed in red text. I’ve used \forglsentries for this example to iterate over all the defined entries. In practice, you would typically just use commands like \gls{label} in the text. For example:

Here is a reference to the term \gls{fusce}.

The entries have all been defined in the file example-glossaries-cite.tex, which you should find installed in the same location as the glossaries package (or in a sub-directory called test-entries). The entry definitions look like this:

\newglossaryentry{fusce}{name={fusce},
description={suscipit cursus sem},user1={article-minimal}}
    
\newglossaryentry{vivamus}{name={vivamus},
description={risus mi, egestas ac},user1={article-full}}

\newglossaryentry{imperdiet}{name={imperdiet},
description={varius, faucibus quis, leo},user1={whole-journal}}

\newglossaryentry{aenean2}{name={aenean},
description={tincidunt},user1={inbook-minimal}}

\newglossaryentry{crasid}{name={cras id},
description={justo quis nibh scelerisque dignissim},
user1={inbook-full}}

If you don’t use arara, you need to run the following commands:

pdflatex cites
makeglossaries cites
pdflatex cites 
bibtex cites
pdflatex cites
pdflatex cites

(See Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build.)

I’ve used the nopostdot option to remove the terminating full stop that is placed by default after the description. The entries all have a “1” after the description. This is the page number on which the entry was referenced. In this sample document all the entries were referenced on page 1. If you don’t want these numbers you can use the nonumberlist option.

Download: PDF (69.17K), source code (1.01K), sample glossary definitions (2.52K).