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

Gallery (glossaries): Units Sample

Image of
unit 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




  first={\glsentrysymbol{#2} (#3)},

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

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

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.


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.

Download: PDF, document source.

Last modified: 2017-06-15.

The free resources on this site are funded by book sales, not by adverts. If you would like to help keep this site free of annoying third-party ads, please consider buying a book.

© 2017 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 Site Map FAQs