6

I would like to use mhchem's \ce command to typeset a transition metal cluster. If I use \ce{[Ru(cod)($2\text{-}$methylallyl)2]}, I get the correct output, but it is very much a hack. I have tried to use \ce{[Ru(cod)(2-methylallyl)2]} but this incorrectly sets the first 2 as a subscript. What is the correct way to handle this?

\documentclass{article}
\usepackage{mhchem}
\begin{document}
  Compare \ce{[Ru(cod)($2\text{-}$methylallyl)2]} with \ce{[Ru(cod)(2-methylallyl)2]}.
\end{document}
5

This is a good question! mhchem's manual doesn't mention escaping from its formula parsing which not only sets the 2 as subscript but also transforms the dash (-) into a single bond.

It does mention one way implicitly: using $...$. Thus the usual way to prevent mhchem's parsing is indeed to switch to math mode, i.e., use $...$ inside \ce{}. So your hack is not so much a hack, really, but for many cases the way to go. It is unfortunate, though, to escape to math mode just to go back to text mode with \text{} again. In cases like yours an \mbox{} is probably better or at least easier and less to type:

\ce{[Ru(cod)(\mbox{2-}methylallyl)2]}

Another way would be to omit the $...$ and to use \text{} directly: mhchem's formulas all are already in math mode! The documentation doesn't advertise this (which sometimes causes unexpected errors).

\ce{[Ru(cod)(\text{2-methylallyl})2]}

There is actually another implicit way to prevent a number being set as a subscript: make mhchem believe that it is a stoichiometric factor by leaving a blank before the number:

\ce{[Ru(cod)( 2-methylallyl)2]}

This, however, will lead to an unwanted space after the dash! This is the space that mhchem inserts after stoichiometric factors which can be verified by setting \mhchemoptions{skip-after-amount=}. Since - is not a letter (i.e. it hasn't catcode 11) it is interpreted as part of the stoichiometric factor.

A comparison of the different cases:

enter image description here

\documentclass{article}
\usepackage{mhchem}

\begin{document}

\begin{tabular}{ll}
 \verb!\ce{[Ru(cod)(2-methylallyl)2]}! & \ce{[Ru(cod)(2-methylallyl)2]} \\
 \verb!\ce{[Ru(cod)($2\text{-}$methylallyl)2]}! & \ce{[Ru(cod)($2\text{-}$methylallyl)2]} \\
 \verb!\ce{[Ru(cod)( 2-methylallyl)2]}! & \ce{[Ru(cod)( 2-methylallyl)2]} \\
 \verb!\mhchemoptions{skip-after-amount=}!: \\
 \verb!\ce{[Ru(cod)( 2-methylallyl)2]}! & \mhchemoptions{skip-after-amount=}\ce{[Ru(cod)( 2-methylallyl)2]} \\
 \verb!\catcode`\-=11!: \\
 \verb!\ce{[Ru(cod)( 2-methylallyl)2]}! & \catcode`\-=11 \ce{[Ru(cod)( 2-methylallyl)2]} \\
 \verb!\ce{[Ru(cod)(\mbox{2-}methylallyl)2]}! & \ce{[Ru(cod)(\mbox{2-}methylallyl)2]} \\
 \verb!\ce{[Ru(cod)(\text{2-methylallyl})2]}! & \ce{[Ru(cod)(\text{2-methylallyl})2]}
\end{tabular}

\end{document}

Edit 2017/05/30

The problem doesn't show with the current version of mhchem:

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

\begin{document}

\verb!\ce{[Ru(cod)(2-methylallyl)2]}! \ce{[Ru(cod)(2-methylallyl)2]}

\end{document}

enter image description here

  • 4
    For comparison: with chemmacros you would write \ch{[Ru(cod)( "2-methylallyl" )2]} – clemens May 6 '13 at 18:34
4

With mhchem v4.00, you can write

\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}
  \ce{[Ru(cod)(2-methylallyl)2]}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.