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

Gallery: Mini-Glossary (bib2gls)

image of sample document with an equation followed by a short list of symbols and a full glossary at the end
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{}%
\def\miniglosshook{\listxadd{\miniglosslist}{\glslabel}}%

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}%
\def\glolinkprefix{minigloss.\theminigloss.}%

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*{\glossarysection}[2][]{\miniglossheader{##1}}%
  \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[colorlinks]{hyperref}
\usepackage[record,nogroupskip]{glossaries-extra}

\GlsXtrLoadResources[src={example-glossaries-symbolnames}]

\newcommand{\miniglossheader}[1]{\par\noindent\textbf{#1:}\par}

\newcommand{\miniglosshook}{}
\preto\glsxtrpostlinkhook{\miniglosshook}

\newcounter{minigloss}

\newenvironment{minigloss}%
{%
  \stepcounter{minigloss}%
  \def\glolinkprefix{minigloss.\theminigloss.}%
  \def\miniglosslist{}%
  \def\miniglosshook{\listxadd{\miniglosslist}{\glslabel}}%
  \ignorespaces
}%
{%
  \printunsrtglossary*[title={Symbols},style=long,nonumberlist]
  {%
    \renewcommand*{\glossarysection}[2][]{\miniglossheader{##1}}%
    \renewcommand*{\printunsrtglossaryentryprocesshook}[1]{%
      \xifinlist{##1}{\miniglosslist}{}{\printunsrtglossaryskipentry}%
    }%
  }%
  \bigskip
  \ignorespacesafterend
}

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

\begin{minigloss}
\begin{equation}
f(\gls{sym.alpha}) = \gls{sym.zeta}\gls{sym.alpha} + \gls{sym.beta}[^2]
\end{equation}
\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

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

Download: PDF (55.26K), source code (1.39K).