# Since few days: Trouble with mhchem using \listoftables or \listoffigures

I'm having trouble with the mhchem package. When I have a figure with a separate TOC entry that involves a \ce{} environment, I get error messages saying that the control sequence \aaaa is not defined. Few days ago another one have had the same problems, solved by reinstalling MiKTeX, but this does not work for me. At home, with an older version of the packages the MWE works, but in the new version it does not. Here's my MWE:

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[version=3]{mhchem}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\begin{figure}[htbp]
\centering
test
\caption[\ce{SiO2}]{\ce{SiO2}}
\label{fig:test}
\end{figure}
\end{document}


Thanks for any help! The same Version of the document was running without any problems a few days ago!

• Welcome to TeX.sx! You probably need to protect \ce: \caption[\protect\ce{SiO2}]{\ce{SiO2}} – clemens Mar 27 '14 at 10:43
• Doesn´t work for me... The problem is related to a really long document with many many formulas ... It would be a mess, if i would have to edit every single caption. – KaLi Mar 27 '14 at 10:55
• works for your MWE (the *.lof file needs to be rewritten of course, so two compilations are necessary before the error disappears) – clemens Mar 27 '14 at 11:03
• Did you have the error for the non-edited MWE and then no error with \protect? Really? What am I doing wrong? – KaLi Mar 27 '14 at 12:10
• yes I had the error with your MWE and it vanished with \protect and compiling twice. In the first compilation the old lof file is used and thus the error still occurs. In the second compilation the new lof file is used which compiles correctly. – clemens Mar 27 '14 at 12:13

My guess is that there is some mistyping in a new version of the package. I enclose a patch of what I think should be used there.

%! *latex malmhchem.tex
%   two runs
\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[version=3]{mhchem}
\begin{document}
\def\aaaa#1{\ce{#1}}
\chapter{Chemistry}
\section{My mhchem}
Some text.
\tableofcontents
\listoffigures
\listoftables
\begin{figure}[!htbp]
\centering Testing phase.
\caption[\ce{SiO2}]{\ce{SiO2}}
\label{fig:test}
\end{figure}
\end{document}


• Wow, you´re great - it works!! Thanks a lot! (It is the really first time that I had to post a question by myself in 5 years of using LateX...) – KaLi Mar 27 '14 at 13:33

Ooooops! Version 3.17 fixes that and will become available soon.

2014-03-27 mhchem v3.17
• fix of the 3.16 expansion fix – sorry, my quality control failed