Gallery: Mini-Glossary
Here are two ways of providing an environment calledminigloss
that automatically displays a list of terms that
have been used within it at the end of the environment. The first
uses the unset buffering mechanism and the second uses the
auto-indexing hook. Both cases list the symbols in order of use in
the mini-list. See Mini-Glossary (bib2gls) for an example that uses the same order for the mini-list as the main list.
Unset Buffer
This example provides an environment that uses the unset buffering
mechanism to pick up any instances of \gls
within the
environment, and displays a list of all those terms:
\newcommand{\miniglosshandler}[1]{\glsentryname{#1} & \glsentrydesc{#1}\\} \newenvironment{minigloss}% {% \GlsXtrStartUnsetBuffering*\ignorespaces }% {% \par\noindent\textbf{Symbols:}\par\centering \begin{tabular}{ll} \GlsXtrForUnsetBufferedList{\miniglosshandler} \end{tabular} \par \bigskip \GlsXtrStopUnsetBuffering \ignorespacesafterend }
The buffering mechanism is actually designed to keep track of
all instances of \glsunset
for situations where changing
the first use flag can cause a problem. Since \gls
internally uses \glsunset
this method can also be used to
keep track of which terms were referenced. Note that this comes with
some limitations:
- The first use flag is now not set until the
buffering is stopped, which means that if a term wasn’t referenced
before the start of the buffering then all instances of
\gls
within the buffering area will be treated as the first use of that term. - Commands that don’t internally call
\glsunset
, such as\glssymbol
won’t be added to the buffer’s internal list. - The buffer’s internal list will be in the order of each
instance of
\glsunset
.
The starred form of \GlsXtrStartUnsetBuffering
is used
to prevent duplicates appearing in the list. Hyperlinks go to the
main glossary at the end of the document.
The initial comment lines below are arara directives. You can remove them if you don’t use arara.
% arara: pdflatex % arara: makeglossaries % arara: pdflatex \documentclass{article} \usepackage[colorlinks]{hyperref} \usepackage[nogroupskip]{glossaries-extra} \makeglossaries \loadglsentries{example-glossaries-symbolnames} \newcommand{\miniglosshandler}[1]{\glsentryname{#1} & \glsentrydesc{#1}\\} \newenvironment{minigloss}% {% \GlsXtrStartUnsetBuffering*\ignorespaces }% {% \par\noindent\textbf{Symbols:}\par\centering \begin{tabular}{ll} \GlsXtrForUnsetBufferedList{\miniglosshandler} \end{tabular} \par \bigskip \GlsXtrStopUnsetBuffering \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. \printglossaries \end{document}
If you don’t use arara, you need to run the following commands:
pdflatex minigloss makeglossaries minigloss pdflatex minigloss
(See Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build.)
Download: PDF (51.14K), source code (859B).
Auto-Indexing Hook
The auto-indexing hook \glsxtrdowrglossaryhook
can
similarly be used to construct an internal list of entries that have
been indexed. The list and hook are locally defined within the
minigloss
environment.
\newcommand{\miniglosswrhook}[1]{% \xifinlist{#1}{\miniglosslist}{}{\listxadd{\miniglosslist}{#1}}% } \newcommand{\miniglosshandler}[1]{\glsentryname{#1} & \glsentrydesc{#1}\\} \newenvironment{minigloss}% {% \def\miniglosslist{}% \let\glsxtrdowrglossaryhook\miniglosswrhook \ignorespaces }% {% \par\noindent\textbf{Symbols:}\par\centering \begin{tabular}{ll} \forlistloop{\miniglosshandler}{\miniglosslist}% \end{tabular} \par \bigskip \ignorespacesafterend }
This has the advantage of not
interfering with the first use flag and can pick up commands like
\glstext
, as long as the command uses the indexing
hook.
% arara: pdflatex % arara: makeglossaries % arara: pdflatex \documentclass{article} \usepackage[colorlinks]{hyperref} \usepackage[nogroupskip]{glossaries-extra} \makeglossaries \loadglsentries{example-glossaries-symbolnames} \newcommand{\miniglosswrhook}[1]{% \xifinlist{#1}{\miniglosslist}{}{\listxadd{\miniglosslist}{#1}}% } \newcommand{\miniglosshandler}[1]{\glsentryname{#1} & \glsentrydesc{#1}\\} \newenvironment{minigloss}% {% \def\miniglosslist{}% \let\glsxtrdowrglossaryhook\miniglosswrhook \ignorespaces }% {% \par\noindent\textbf{Symbols:}\par\centering \begin{tabular}{ll} \forlistloop{\miniglosshandler}{\miniglosslist}% \end{tabular} \par \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. \printglossaries \end{document}
Download: PDF (51.14K), source code (980B).