News (2017-08-02): Latest blog post The Private Enemy Giveaway.

# Gallery (glossaries): Units Sample

This example is a modification of the Units (glossaries-extra) example. In this case the symbolic representation is stored in the name field, the unit name is stored in the symbol field and the first field is used to make the first use show the symbol field followed by the symbolic representation in parentheses. To prevent problems caused by expansions issues, \glsnoexpandfields is used to switch off the automatic expansion. A user command (\newunit) to make it easier to define entries and to ensure consistency. Since indexing applications can interpret commands like \si{\ohm}, this custom command sets the sort key to the label. The symbol field is also set to the label, which works fine for the Ω entry but not for the Å entry as entry labels can't contain special or non-ASCII characters (unless XeLaTeX or LuaLaTeX are used), which means the label must be Angstrom (or angstrom) and not Ångström. This means that the symbol field needs to be set in the option argument of \newunit.

This version may be used with the extension package glossaries-extra or with just the base glossaries package. I've used a different glossary style long4col for variation.

An alternative approach is to use \newacronym (or \newabbreviation provided by glossaries-extra.sty) with a custom glossary style.

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{siunitx}
\usepackage[style=long4col]{glossaries}

\makeglossaries

\glsnoexpandfields

\newcommand*{\newunit}[4][]{%
\newglossaryentry{#2}{name={#3},sort={#2},
first={\glsentrysymbol{#2} (#3)},
description={#4},symbol={#2},#1}%
}

\newunit{ohm}{\si{\ohm}}{unit of electrical resistance}

\newunit[symbol={\AA ngstr\"om}]{angstrom}{\si{\angstrom}}{unit of length}

\begin{document}
The \gls{ohm} is a unit of resistance and the
\gls{angstrom} is a unit of length.

Let's mention \gls{ohm} and \gls{angstrom} again.

\printglossaries
\end{document}


If you don't use arara, you need to run the following commands:
pdflatex sample-units2
makeglossaries sample-units2
pdflatex sample-units2

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.