Smile for the Camera: a new cybercrime short story ebook.

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




{% based on list style
     % in the event of multiple cites (as in the vestibulum2
     % sample entry), \glsentryuseri{##1} needs to be expanded
     % before being passed to \cite.
     (See \expandafter\cite\expandafter{\thiscite})}{}%
    \space ##2}%



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




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:

description={suscipit cursus sem},user1={article-minimal}}
description={risus mi, egestas ac},user1={article-full}}

description={varius, faucibus quis, leo},user1={whole-journal}}


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

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).