Latest news 2019-10-04: Competition to win a copy of the children’s illustrated book “Quack, Quack, Quack. Give My Hat Back!”. Closing date: 1st Nov 2019 23:59 +00:00.

# Gallery: Mini-Glossary (bib2gls)

If you have a small screen, you may prefer to switch on the small image setting.

This is an alternative approach to the \makeglossaries mini-glossary example that uses the post-link hook to keep track of which entries have been referenced within the custom minigloss environment. In this case, the mini-glossary uses the same order as the main list at the end of the document.

This example requires the file example-glossaries-symbolnames.bib. If it’s not supplied with glossaries-extra.sty, you can create it from example-glossaries-symbolnames.tex (supplied with glossaries.sty v4.33) using the convertgls2bib application supplied with bib2gls:

convertgls2bib example-glossaries-symbolnames.tex example-glossaries-symbolnames.bib


As with the other examples, this works through the use of an internal etoolbox list that’s reset at the start of the provided minigloss environment. In this case, a custom hook \miniglosshook is prepended to the general post-link hook \glsxtrpostlinkhook that’s defined by glossaries-extra. The custom hook does nothing outside of the minigloss environment, but within it the hook adds the label of the entry that has just been referenced to the internal list (\miniglosslist):

\def\miniglosslist{}%


In the other examples, the hyperlink target for the entries referenced within the minigloss environment is in the complete list at the end of the document, as per normal behaviour. In this example, I’ve redefined \glolinkprefix to make the referenced entries within the environment link to the mini-glossary instead. To ensure a unique target name I’ve defined a counter (minigloss) that’s incremented at the start of the environment and used that in the target name:

\stepcounter{minigloss}%


The mini-glossary is now displayed using the starred version of \printunsrtglossary with code that filters out all terms that aren’t contained in the internal list:

\printunsrtglossary*[title={Symbols},style=long,nonumberlist]
{%
\renewcommand*{\printunsrtglossaryentryprocesshook}[1]{%
\xifinlist{##1}{\miniglosslist}{}{\printunsrtglossaryskipentry}%
}%
}%


The complete document is shown below. (The comment lines below are arara directives. You can remove them if you don’t use arara.)

% arara: pdflatex
% arara: bib2gls
% arara: pdflatex
\documentclass{article}

\usepackage[record,nogroupskip]{glossaries-extra}

\newcommand{\miniglosshook}{}

\newcounter{minigloss}

\newenvironment{minigloss}%
{%
\stepcounter{minigloss}%
\def\miniglosslist{}%
\ignorespaces
}%
{%
\printunsrtglossary*[title={Symbols},style=long,nonumberlist]
{%
\renewcommand*{\printunsrtglossaryentryprocesshook}[1]{%
\xifinlist{##1}{\miniglosslist}{}{\printunsrtglossaryskipentry}%
}%
}%
\bigskip
\ignorespacesafterend
}

\begin{document}
Reference \gls{sym.gamma} in this paragraph.

\begin{minigloss}
$$f(\gls{sym.alpha}) = \gls{sym.zeta}\gls{sym.alpha} + \gls{sym.beta}[^2]$$
\end{minigloss}

Reference \gls{sym.delta} here.

\begin{minigloss}
\begin{align*}
f(\gls{sym.xi}) &= \gls{sym.delta}\gls{sym.epsilon} + \gls{sym.beta}[^2]\\
g(\gls{sym.chi}) &= \gls{sym.omega}\gls{sym.tau} + \gls{sym.alpha}
\end{align*}
\end{minigloss}

Reference \gls{sym.sigma} here.

\printunsrtglossaries
\end{document}


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

pdflatex minigloss-bib2gls
bib2gls minigloss-bib2gls
pdflatex minigloss-bib2gls