# Package mhchem Gives an Error

I recently tried to use mhchem and it works for some commands, but not for some. Here is a sample code.

\documentclass{article}
\usepackage[version=3]{mhchem}
\begin{document}
\ce{X-X}
\ce{C\bond{~-}C}
\end{document}


Gives me

! Undefined control sequence.
\mhchem@bond #1->\ifnum \pdf@strcmp
{#1}{-}=0\sbond \else \ifnum \pdf@strcmp...
l.7   \ce{C\bond{~-}C}


I followed the mhchem manual and I cannot seem to find a mistake. I installed this package on 2/8/2015 so I should be running the latest version. Any ideas on this one?

• I am using MiKTex 2.9 latex distribution. It works normally!!! – Say OL Feb 9 '15 at 9:59
• @OLSAY Me, too, but I get the error. – karlkoeller Feb 9 '15 at 10:03

This is a bug in mhchem, which doesn't either define the command \pdf@strcmp or load the package pdftexcmds explicitly, where it is defined, but relies on the driver code (graphics.cfg) to load it.

The bug can be seen when using MiKTeX with pdfLaTeX or XeTeX (not LuaLateX). When using TeX Live it can be noticed compiling with XeTeX.

As a workaround, it should suffice to load this package

\usepackage{pdftexcmds}


MWE

\documentclass{article}
\usepackage[version=3]{mhchem}

\usepackage{pdftexcmds}

\begin{document}
\ce{X-X}
\ce{C\bond{~-}C}
\end{document}


Output

• I have reported this issue to the package maintainer. – Joseph Wright Feb 9 '15 at 11:31
• This is the maintainer of mhchem. Thanks for investigating and reporting. I fixed the issue and uploaded version 3.19 (2015-02-09) to CTAN. It should make its way to your preferred mirror within 48 hours. – mh543 Feb 9 '15 at 21:39
• It works, thank you! Another computer I had and so do ShareLaTeX did compile the code normally. – Vinsen Feb 10 '15 at 2:03

For a local texlive installation from 2015 dvd, none of the method described above worked for me. From a thread, I learned that it was a bug in mhchem.

@Joseph ah sorry, it's mhchem that seems to cause it, not siunitx, but still, it looks to me like some L3 incompatibility -- I surely don't define \c_backslash_str myself... Ok, putting \RequirePackage{mhchem} before \documentclass seems to have solved it.

I followed the instruction to add \RequirePackage{mhchem} before \documentclass and now the problem is solved.

• An update of your TeX distribution would be a better solution – clemens Jul 16 '16 at 11:29