# Upper case using mhchem and glossaries

I'm having the following trouble using mhchem in my glossaries. I'd like to not have to worry about whether I've used an acronym already when I start out a sentence, but I'm finding that \Gls does not seem to work very well with mhchem in glossaries. I can work around by trying to keep track of whether or not I've used the acronym yet, but I'd love to be able to make an edit in my \newacronym definitions to make it work. Any suggestions would be appreciated!

\documentclass{article}
\makeglossaries % Prepare the glossary
\usepackage[version=3]{mhchem}

\newacronym{CO2}{\ce{CO2}}{carbon dioxide}
\newacronym{CH4}{CH$_4$}{methane}
\newacronym{H2SO4}{\NoCaseChange{\ce{H2SO4}}}{sulfuric acid}

\begin{document}
%I'd like the following to work, but it doesn't...
\Gls{CO2} in the environment \ldots
\Gls{CO2} now generates an error

\Gls{CH4} in the environment \ldots
\Gls{CH4} works fine.

%\gls works fine
Calculation of the corresponding \gls{CO2} emissions to cover the surplus in electricity demand.

%I also tried
\Gls{H2SO4} is an acid. We use \gls{H2SO4} everyday.
\Gls{H2SO4} generates an error \ldots
\gls{H2SO4} is okay.

\printglossary[type=acronym,title={List of Abbreviations}]
%\printglossaries

\end{document}

• \newacronym{CO2}{{}\ce{CO2}}{carbon dioxide} should work – cgnieder Jul 31 '15 at 18:04
• Just to expand on @clemens' comment: in the first case, \Gls is trying to do \MakeTextUppercase\ce{CO2} (so \MakeTextUppercase is trying to grab just \ce as the argument, which causes an error). In the third case, \Gls is trying to do \MakeTextUppercase\NoCaseChange{\ce{H2SO4}} (so \MakeTextUppercase is trying to grab \NoCaseChange as the argument, which causes an error). Internally \Gls is using \makefirstuc, which is described in more detail in the mfirstuc manual. – Nicola Talbot Jul 31 '15 at 19:06
• @NicolaTalbot why does \newacronym{CO2}{\empty\ce{CO2}}{carbon dioxide} go wrong (similarly with \relax)? Since \MakeTextUppercase\empty compiles just fine I suspect the cause to be somewhere else… – cgnieder Sep 7 '15 at 19:09
• @clemens It seems to be a problem with \makefirstuc since \makefirstuc{\empty\ce{CO2}} fails. It's probably something to do with the mechanism that's trying to determine if \empty has an argument. \makefirstuc{\empty{}\ce{CO2}} works fine, and there's also no problem if I replace \ce with another command, such as \makefirstuc{\empty\textbf{CO2}}. I'll look into it, but I think the simplest thing to do in this case is just \newacronym{CO2}{{}\cs{CO2}}{carbon dioxide}. – Nicola Talbot Sep 8 '15 at 8:20
• @clemens I've found the problem. It'll be fixed in the next release. D'you want to convert your comment into an answer? It's the simplest solution. – Nicola Talbot Sep 8 '15 at 9:42

Giving the underlying uppercasing macro (\makefirstuc) an empty group as first “token” for its work will do:
\newacronym{CO2}{{}\ce{CO2}}{carbon dioxide}

Without it \ce is the argument to \makefirstuc and things go wrong.