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.

Is there a package that supports the addition or subtraction of chemical equations, perhaps with automatic tabbing and a alignment. Whilst it is obvious I could set up tables or use mathmode's align feature, it seems so much more efficient to have a package handle the tabbing automatically, since it is rather predictable in this application. mhchem does not seem to have such a feature...

enter image description here

enter image description here

Another advantage is you could maintain the readability of your equations and you would not have the added clutter associated with tables, especially tabs &, which diminish the readability of your .tex document. And of course, the line should be automatically inserted before the last row.

share|improve this question

4 Answers 4

Cancellation of species

To elaborate on Canageek's answer, yes, you can use the cancel package with mhchem, however it's a bit tricky. Specifically, using cancel inside the \ce{} environment will break the automagic formatting of mhchem, turning your species italic.

There are two ways around this:

  1. You can wrap your species in \mathrm and then wrap that in \cancel{} (the easiest way)

  2. You can break your equation into multiple \ce{} environments, and place the relevant species in $\cancel{}$ (\cancel{} is supposed to be used in mathmode). This is not a good solution as it makes your equation discontiguous and messes up spacing.

    which means that you need to wrap each cancelled species in its own \ce{} and then place that inside a \cancel{}.

Here's what each option looks like:

different variants of cancelled chemical equations

Here's the code (please excuse the non-mwe nature of the code)

\documentclass[a4paper]{article}

\usepackage[version=3]{mhchem}
\usepackage{cmbright}
\usepackage{cancel}

\begin{document}

Standard:

\ce{HCOOH_{(aq)} + H2O_{(l)} <=> H3O^{+}_{(aq)} + HCOO^{-}_{(aq)}}\\

\texttt{$\backslash{}$cancel} inside \texttt{$\backslash{}$ce}:

\ce{\cancel{HCOOH_{(aq)}} + H2O_{(l)} <=> H3O^{+}_{(aq)} + \cancel{HCOO^{-}_{(aq)}}}\\

\texttt{$\backslash{}$mathrm} inside \texttt{$\backslash{}$cancel} inside \texttt{$\backslash{}$ce}:

\ce{\cancel{\mathrm{HCOOH_{(aq)}}} + H2O_{(l)} <=> H3O^{+}_{(aq)} + \cancel{\mathrm{HCOO^{-}_{(aq)}}}}\\

\texttt{$\backslash{}$cancel} outside \texttt{$\backslash{}$ce}:

$\cancel{\ce{HCOOH_{(aq)}}}$ \ce{+ H2O_{(l)} <=> H3O^{+}_{(aq)} +} $\cancel{\ce{HCOO^{-}_{(aq)}}}$
\end{document}

As you can see, this diminishes readability profoundly :(

You can change the colour of the cancellation line via \renewcommand{\CancelColor}, which is a bit of a pain.

Alignment

I was not sure if your reference to align in mathmode meant that you were using mathmode in align to manually set chemical equations, rather than mhchem, but mhchem has the \cee environment, which acts like a the \ce environment but allows you to use & as an alignment point in an align environment. It seems fairly simple.

Putting it all together:

aligned equations

With the following code:

\documentclass[a4paper]{article}

\usepackage[version=3]{mhchem}
\usepackage{cmbright}
\usepackage{cancel}

\begin{document}


    \begin{align*}
    \centering
    \cee{\cancel{\mathrm{HCOOH_{(aq)}}} + H2O_{(l)} &<=> H3O^{+}_{(aq)} + \cancel{\mathrm{HCOO^{-}_{(aq)}}}}\\
    \cee{\cancel{\mathrm{HCOO^{-}_{(aq)}}} + H2O_{(l)} &<=> \cancel{\mathrm{HCOOH_{(aq)}}} + OH^{-}_{(aq)}}\\
    \hline{}
    \cee{H2O_{(l)} + H2O_{(l)} &<=> H3O^{+} + OH^{-}_{(aq)}}    
    \end{align*}

\end{document}

Getting the \hline to a more sensible length and adjusting the spacing between formulae is left as an exercise to the interested reader (I don't know, but someone else probably does. It's a start.)

Hope this is of some use.

share|improve this answer
    
Would it be possible to borrow some code from siunitx to get a similar effect, where you can use /cancel inside of the environment without breaking it? Or are the two environments too dissimilar? –  Canageek Oct 1 '11 at 14:34
2  
@Canageek - I don't know. A long-term solution would consist of a new version of mhchem. A simple fix is to define a new cancel command for use in the \ce environment. For example: \newcommand{\canceq}[1]{\cancel{\mathrm{#1}}}. So now you can just use \canceq{HCOO^{-}} which is somewhat nicer. –  Richard Terrett Oct 1 '11 at 14:54

I came about a way to achieve what you want, provided by Clemens Niederberger, that uses his chemmacros package and cancel and can be found on mychemistry.eu.

\documentclass{article}
\usepackage{chemmacros,cancel}

\let\oldcancel\cancel
\renewcommand\cancel[1][black]{%
  \def\CancelColor{\color{#1}}%
  \oldcancel}

\begin{document}

\begin{align*}
  \ch{\cancel[blue]{HCOOH\aq} + H2O\lqd{}  &<=> H3O^+\aq{} + \cancel[red]{HCOO^-\aq}} \\
  \ch{\cancel[red]{HCOO^-\aq} + H2O\lqd{} &<=> \cancel[blue]{HCOOH\aq} + OH^-\aq}\\[-1ex]
  \cline{1-2}
  \ch{H2O\lqd{} + H2O\lqd{} &<=> H3O^+\aq{} + OH^-\aq}    
\end{align*}

\end{document}

The result looks like this:

enter image description here

share|improve this answer

I don't know about the addition and subtraction of chemical formula themselves, but there is the cancel package which can probably provide the ah, cancelling.

share|improve this answer

You mention readability of the code. You could redefine (or activate) single characters to help here. The following is definitely not optimal, but redefines | and > to mean + and \rightarrow with the appropriate column alignment from an array:

\documentclass{article}
\usepackage[version=3]{mhchem}% http://ctan.org/pkg/mhchem
\usepackage{array}% http://ctan.org/pkg/array

\begin{document}
\[
  \catcode`\|=\active \newcommand{|}{&+&}
  \catcode`\>=\active \renewcommand{>}{&\rightarrow&}
\begin{array}{*{19}{@{\,}c}}
  &&&&   \ce{10e-} | \ce{16H+} | \ce{2MnO_4-} > \ce{2Mn^2+} | \ce{8H_2O} \\
  &&&&&& \ce{5H_2O} | \ce{5H_2SO_3} > \ce{5SO_4^2-} | \ce{20H+} | \ce{10e-} \\ \hline
  \ce{10e-} | \ce{16H+} | \ce{2MnO_4-} | \ce{5H_2O} | \ce{5H_2SO_3} >  
    \ce{2Mn^2+} | \ce{8H_2O} | \ce{5SO_4^2-} | \ce{20H+} | \ce{10e-}
\end{array}
\]

Alignment of chemical compounds

Of course, the regular cancelling (via the cancel package) still holds, if required. The problem I'm having, hence noting this as sub-optimal, is from the mhchem package that actively changes + and - (to superscripts), forcing the use of | for the addition of chemical compounds. This needs some further investigation.

share|improve this answer

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.