[Tex/LaTex] SI unit in acronym glossary

acronymsglossaries

I have a question. I want to use SI unit X in my acronym definitions. For example:

\newacronym{M}{\si{\Molar}}{molar}

Sadly this doesn't work. Is there a way to do use SI units in the acronym definition? I know about the possibility to use \newglossaryentry, but I want to have all my acronyms in one list.
When I remove all the \si parts, it works. But I'd like to have the spacing right.

Best Answer

(It would help if you provide a minimal working example (MWE) that people can work with.)

The problem is caused by the default expansion that's performed when the entry is defined. This can be fixed by using \glsnoexpandfields to switch off the expansion:

\documentclass{article}

\usepackage{siunitx}
\usepackage{glossaries}

\DeclareSIUnit\Molar{\textsc{m}}

\makeglossaries

\glsnoexpandfields

\newacronym{M}{\si{\Molar}}{molar}

\begin{document}

\gls{M}

\printglossaries
\end{document}

Alternative, protect the fragile commands:

\documentclass{article}

\usepackage{siunitx}
\usepackage{glossaries}

\DeclareSIUnit\Molar{\textsc{m}}

\makeglossaries

\newacronym{M}{\protect\si{\protect\Molar}}{molar}

\begin{document}

\gls{M}

\printglossaries
\end{document}
Related Question