2

I'm trying to build a glossary where some terms are constants with units, and I'm hitting the problem than the units of siunitx are not defined.

\documentclass{article}
\usepackage{glossaries-extra}
\usepackage{siunitx}

\makenoidxglossaries \newglossaryentry{working entry}{type=main, name={$e = 1.6e-19$ C}, description={electron charge}} \newglossaryentry{failing entry}{name={$e = \qty{1.6e-19}{\coulomb}$}, description={electron charge}}

\begin{document} \printunsrtglossary \end{document}

fails with:

! Undefined control sequence.
\@gls@value ->$e = \qty {1.6e-19}{\coulomb 
                                           }$
l.7 ...\coulomb}$}, description={electron charge}}

! ==> Fatal error occurred, no output PDF file produced!

It's not a problem of the expansion of the field, because according to the glossaries manual, the name field is not expanded (and any combination of \glssetnoexpandfield, \unexpanded, \protect and similar didn't help).

Rather I suspect after reading this somewhat related answer that the siunitx units macros are not defined in the preambule. According to question like this one it used to work, but maybe something changed between siunitx 2 and siunitx 3.

The answer was solving the problem of the abbreviated units not being loaded yet with this code:

%load abbreviations:
\ExplSyntaxOn
\__siunitx_load_abbreviations:
\ExplSyntaxOff

So I'm wondering if there exist something similar for siunitx 3 for loading the whole units before defining the glossary entries.

elyuku
  • 33
  • 1
    You can just delay the loading by wrapping the two gls lines in \AtBeginDocument{...} – daleif Mar 03 '22 at 13:20
  • Wow thanks, that was actually simple! It worked, so if you want to make it an answer, I could accept it. – elyuku Mar 03 '22 at 14:28

1 Answers1

2

In order to let users adjust macros in the preamble, siunitx loads it self at the start of the document. I have no idea what goes wrong with \newglossaryentry or why it is expanding contents right away.

You can delay them using

\AtBeginDocument{
\newglossaryentry{working entry}{type=main, name={$e = 1.6e-19$ C}, description={electron charge}}
\newglossaryentry{failing entry}{name={$e = \qty{1.6e-19}{\coulomb}$}, description={electron charge}}
}
daleif
  • 54,450