Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I decided to enrich my list of symbols by adding a unit column with a newly defined key "unit".

\glsaddkey
 {unit}
 {}
 {\glsentryunit}
 {\Glsentryunit}
 {\glsunit}
 {\Glsunit}
 {\GLSunit}

A new entry looks like

\newglossaryentry{insu}{
    type=symbols,
    name=thermal resistance,
    symbol={\ensuremath{R\mathrm{c}}},
    description={ratio of the temperature difference across an insulator and the heat flux for a particular material or assembly of materials},
    unit={\ensuremath\protect\si{\watt}},
}

and produces following error with the last curly brace, that closes the \newglossaryentry.

> ! Undefined control sequence.
\@glo@tmp ->\ensuremath \protect \si {\watt }

Moving the code inside the unit key, for testing purpose, to the key symbol works like a charm, but unfortunately not the intended place. Changes around the protect and ensuremath have no effect. The asterisk variant of \glsaddkey* doesn't help either.

What is the conflict between adding a new key to a glossary entry and the \si command?

Here a short MWE:

\documentclass{scrreprt}%
\usepackage{siunitx}
\usepackage{glossaries}

\glsaddkey
 {unit}
 {}
 {\glsentryunit}
 {\Glsentryunit}
 {\glsunit}
 {\Glsunit}
 {\GLSunit}

\makeglossaries

\newglossaryentry{test}{
 name=Test,
 unit=\si{\meter},
 description=sample description}

%-------------------------

\begin{document}

\printglossaries
\gls{test}

\end{document}
share|improve this question
    
Why are you using \ensuremath and \protect with siunitx? The error here is happening has \watt is undefined outside of siunitx's commands: could you make a full minimal working example (MWE) so we can see exactly what is happening. –  Joseph Wright Jul 20 at 7:36

1 Answer 1

up vote 2 down vote accepted

The glossaries package expands the input for all entries by default. This won't work with 'local' definitions for commands, as used by siunitx for unit commands (which can me something entirely different in other context). Possible solutions are to use \glsnoexpandfields:

\glsnoexpandfields
\newglossaryentry{test}{
 type=symbols,
 name=Test,
 unit=\si{\metre},
 description=sample description}

or to inhibit expansion of just the unit

\newglossaryentry{test}{
 type=symbols,
 name=Test,
 unit=\unexpanded{\si{\metre}},
 description=sample description}

or turn off expansion for the field

\glssetnoexpandfield{unit}
share|improve this answer
    
Could I set the unexpanded flag already when defining the glsaddkey? –  Burcardo Jul 20 at 9:31
    
@Burcardo That's probably one for Nicola Talbot (hopefully will pop up soon!) –  Joseph Wright Jul 20 at 9:35
    
@Burcardo You can put \glssetnoexpandfield{unit} before or after \glsaddkey. You just need to make sure it's set before any instance of \newglossaryentry where the expansion needs to be suppressed. The starred version of \glsaddkey forces expansion on for that key even if \glsnoexpandfields is used (but can later be overridden with \glssetnoexpandfield{unit}). –  Nicola Talbot Jul 20 at 10:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.