About 🛈
Shop 🛒Shop 🛒
LaTeX 🖹
Software 💾
Books 📚
Gallery 🖺
News 📢
Contact 📧
Blog 🖋
The site has just moved to a new web hosting provider. There may be some temporary disruption.

Gallery (bib2gls): Mini-Glossary Sample

Image of mini-glossary bib2gls sample

This is an alternative approach to the mini-glossary example which uses the post-link hook and 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 previous examples, this works through the use of an internal etoolbox list that's reset at the start of the environment. In this case, a custom hook \miniglosshook is prepended to the general post-link hook \glsxtrpostlinkhook that's provided by glossaries-extra. The custom hook does nothing outside of the custom 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 previous examples, the hyperlink target for the entries referenced within the minigloss 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 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 comment 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
These commands can be run from a terminal or command prompt or you might be able to run them by clicking on a button in your text editor.

Download: PDF, document source.

© 2018 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs