3

The following MWE where a glossary entry with a chemical formula defined with mhchem renders as expected with 0 errors:

\documentclass{article}

\usepackage[modules={all}]{chemmacros}

\usepackage[version=4]{mhchem}

\usepackage[colorlinks=true]{hyperref}

\usepackage[xindy]{glossaries}
\makeglossaries

\newacronym{DMSO}{DMSO}{dimethyl sulfoxide \ce{(CH3)2SO}}

\begin{document}

\glsunsetall

Solvent: \gls{DMSO}

\printglossaries

\end{document}

enter image description here


However, when I change \ce to \ch in \newacronym (e.g. switch to chemformula):

\documentclass{article}

\usepackage[modules={all}]{chemmacros}

\usepackage[version=4]{mhchem}

\usepackage[colorlinks=true]{hyperref}

\usepackage[xindy]{glossaries}
\makeglossaries

\newacronym{DMSO}{DMSO}{dimethyl sulfoxide \ch{(CH3)2SO}}

\begin{document}

\glsunsetall

Solvent: \gls{DMSO}

\printglossaries

\end{document}

I receive the following error:

! Undefined control sequence. \@glo@first ->dimethyl sulfoxide \ch{(CH3)2SO}\glsspace(DMSO)l.12 ...O}{DMSO}{dimethyl sulfoxide \ch{(CH3)2SO}}

The problem persists with both pdflatex and xelatex (the latter has different set of packages, obviously, but gives the same error). What am I doing wrong?

3
  • 1
    I don't have chemmacros installed but I suspect it's an expansion problem. Either put \protect before \ch or switch off expansion using \glsnoexpandfields . Jan 10, 2018 at 15:34
  • @NicolaTalbot Thank you very much, \glsnoexpandfields in preample did it! I think you can convert your comment to an answer.
    – andselisk
    Jan 10, 2018 at 15:44
  • 1
    Okay. I've added an answer. Jan 10, 2018 at 16:09

1 Answer 1

3

If any fields contain fragile commands, you need to switch off the default expansion using \glsnoexpandfields (before defining the terms).

(By default, all fields except name, description and symbol have their values expanded when defining terms to allow for commands that define terms programmatically. The name, description and symbol fields have the expansion switched off by default for historical reasons.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .