Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!!

share|improve this question
    
@cgnieder: OK. I'll delete my comments shortly. –  Gonzalo Medina May 17 '12 at 15:06
add comment

2 Answers

up vote 4 down vote accepted

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) chemmacros:

\documentclass{article}
\usepackage{chemmacros}
\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

share|improve this answer
    
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 '12 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 '12 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 '12 at 19:07
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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