About
Shop
LaTeX
Free Software
Books
News
Contact
Blog
News: Tune in to Radio Norfolk's Matthew Gudgin's Teatime Show between 6 and 7pm on Wednesday, July 12th for Keith Skipper's mardle with Nicola Cawley (aka Nicola Talbot).

Gallery (glossaries-extra): Units Sample

Image of
units sample
This example is copied from my article Glossaries, Nomenclature, Lists of Symbols and Acronyms. It uses the glossaries-extra package to take advantage of the post-link hook.

The entry representing a unit has the unit name (ohm) in the name field and the symbolic representation (\si{\ohm}) in the symbol field. (The command \si is provided by the siunitx package, which needs to be loaded.) The category unit is used to identify the entry as representing a unit. (The category field defaults to general if not set in \newglossaryentry.) This allows customisation of the link text (the text produced by commands like \gls) so that the unit (provided in the symbol field) can be automatically appended in parentheses on first use.

The default glossary style is list which doesn't display the symbol field, so I've used the index style instead.

An alternative version that only uses the base glossaries package can be found in Units (glossaries.sty).

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{glossaries-extra}

\makeglossaries

\newcommand*{\glsxtrpostlinkunit}{%
 \ifdefempty\glscustomtext{\glsxtrpostlinkAddSymbolOnFirstUse}{}}

\newglossaryentry{resistor}{name={resistor},
 description={component that implements electrical resistance}}

\newglossaryentry{ohm}{name=ohm,symbol={\si{\ohm}},
category=unit,% category label
description=unit of electrical resistance}

\begin{document}
A \gls{resistor} is an electrical component.
The \gls{ohm} is a unit of resistance.

Symbol: \glssymbol{ohm} and let's mention \gls{ohm} again.

\printglossary[style=index]
\end{document}


If you don't use arara, you need to run the following commands:
pdflatex sample-units
makeglossaries sample-units
pdflatex sample-units
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