3

I am trying to programmatically convert a very large number of documents that have chemical compounds represented within math equations. I am converting from some flavor of RUNOFF (I think..it isn't well documented). I am having a few related problems displaying compounds both in and outside of equations. The mhchem package is great until I encounter decimal values within a compounds formula (as shown below). What I need is for the compound to be displayed in normal (non-italicized) type. There are four lines in the body below that illustrate my issues. The first line results in the compound being italicized. The second illustrates a related problem, that being that the portion enclosed in parenthesis is italicized. The third is how the \ce command handles a decimal point. The fourth shows a workaround for using the \ce command. The third and fourth lines also result in the equation number being flush with the equation instead of over on the right margin -- why?

\documentclass{article}
\usepackage{ulem}
\usepackage{fixltx2e}
\usepackage[version=3]{mhchem}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\begin{document}
\begin{equation} X_{Li_{2}(SO_{4})_{0.5}} \end{equation}

Li_{2}(SO_{4})_{0.5}

\begin{equation} X_{\ce{Li2(SO4)0.5} \end{equation}

\begin{equation} X_{\ce{Li2(SO4)_{0.5}} \end{equation}
\end{document}

I've started looking into perhaps doing some Lua or modifying mhchem.sty. I've also tried using \text{}, \textnormal{}, etc. within my equation but apparently I haven't done it correctly yet. I am not terribly experienced with LaTeX and was hoping that somebody with more experience than me might step forward with something tidy.

Thanks for any help!!

1
  • @cgnieder: OK. I'll delete my comments shortly. May 17, 2012 at 15:06

2 Answers 2

5

Your code isn't working as it stands: the second line is not in math mode or inside \ce so _ must issue an error.

Li_{2}(SO_{4})_{0.5}

In the third and fourth line the groups are not balenced but miss a }. After correcting this:

\begin{equation} X_{\ce{Li2(SO4)0.5}} \end{equation}

\begin{equation} X_{\ce{Li2(SO4)_{0.5}}} \end{equation}

the behaviour of the third is documented mhchem behaviour to display adducts so the forth is not a workaround but the way to go.

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

\ce{Li2(SO4)_{0.5}}

Adduct: \ce{Na2SO4.10H2O}

\begin{equation}
 X_{\ce{Li2(SO4)_{0.5}}}
\end{equation}

\end{document}

enter image description here

Alternatively one can use (my own) chemformula:

\documentclass{article}
\usepackage{chemformula}
\begin{document}

\ch{Li2(SO4)_{0.5}}

Adduct: \ch{Na2SO4 * 10 H2O}

\begin{equation}
 X_{\ch{Li2(SO4)_{0.5}}}
\end{equation}

\end{document}

enter image description here

3
  • missed braces. i feel dumb!! i had worked out enclosing all my subscripted numbers in math mode last week before I started using mhchem and had since forgotten that. brain is just cooked a bit too much I guess. thanks very much for helping me.
    – Huliax
    May 17, 2012 at 18:58
  • btw, I looked over chemmacros a bit and I like them better. I'll bring it up with the customer and see if they have a preferences.
    – Huliax
    May 17, 2012 at 19:00
  • @Huliax Note that the syntax of chemmacros is different in details. Also it is more strict about its syntax.
    – cgnieder
    May 17, 2012 at 19:07
1

For example:

\ce{$3.043$ Fe2O3}

just use maths-escape mode, using $$ to embrace the number. There should not be any white spaces between $ and the number otherwise the compiling would go wrongly, though this is not the case in normal equations.

Ref: http://tumutanzi.com/archives/11825

You must log in to answer this question.

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