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 typeset some chemical equations in my thesis, and I would like to have the chemical equations have a unique counter from regular equations.

I also need to have some of them align over the -> . I know I can use \cee{} from the mhchem package within the align environment, but I don't know to separate the counters.

I tried fiddling with creating a new environment, but couldn't get it to work right at all (first time trying that out...). I would love to have an aligned environment "chemical" that did all this.

Thanks in advance for any help!

share|improve this question
1  
What did you try? How didn't it work? –  Seamus Jun 27 '12 at 13:27
    
Well, I tried something like this: \newenvironment{chemical}% {\renewcommand{\theequation}{\thereaction}% \begin{align}}% {\end{align} \renewcommand{\theequation}{\arabic{equation}}} where \thereaction is related to a custom "reaction" counter. But I couldn't figure out how to force the align environment to temporarily increment the reaction counter instead of the equation counter, so I was stuck. –  Brian Jun 27 '12 at 13:38
1  
I was referring specifically to the reactions environment, which gives you the alignment and the separate numbering. –  Jellby Jun 27 '12 at 15:19
1  
You can use \usepackage[method=mhchem]{chemmacros} and ignore its formula building macros (i.e., the complete part III of the manual). You can then still use chemmacros's reaction environments (section 12 of the manual). –  cgnieder Jun 27 '12 at 15:41
1  
See also the other question about numbering mhchem reactions... –  cgnieder Jun 27 '12 at 16:42
show 4 more comments

1 Answer

So, I figured out how to get what I wanted working by creating a new environment (modeled on the subequations implementation). I additionally created a "subreaction" environment as well.

\documentclass{report}

\usepackage[version=3]{mhchem}
\usepackage{amsmath}
\usepackage[english]{babel}

\newcounter{reaction}
\renewcommand\thereaction{C\,\thechapter.\arabic{reaction}}

\renewcommand{\thereaction}{C\,\thechapter.\arabic{reaction}}
\newcommand{\thealignedreaction}{C\,\thechapter.\arabic{equation}}

\makeatletter
\newenvironment{reactionalign}{%
    \mathchardef\c@mainequation\c@equation
    \protected@edef\themainequation{\theequation}%
    \let\theequation\thealignedreaction
    \global\c@equation\c@reaction
    }%
    {
    \global\c@equation\c@mainequation
    \global\@ignoretrue
    }
\makeatother


\newcommand{\thesubreaction}{\themainreaction\alph{equation}}

\makeatletter   
\newenvironment{subreactions}{%
    \refstepcounter{reaction}%
    \mathchardef\c@mainequation\c@equation
    \protected@edef\themainequation{\theequation}%
    \mathchardef\c@mainreaction\c@reaction
    \protected@edef\themainreaction{\thereaction}%
    \let\theequation\thesubreaction
    \global\c@equation\z@
    }{%
    \global\c@reaction\c@mainreaction
    \global\c@equation\c@mainequation
    \global\@ignoretrue
    }
\makeatother

%%%%%%%%%%%%%

\begin{document}
\chapter{Example}
\begin{equation}
    A = B
\end{equation}

\begin{subreactions}
    \begin{align}
        \cee{2H2 + O2 &-> 2H2O}\\
        \cee{CH4 + 2O2 &-> 2H2O + CO2}
    \end{align}
\end{subreactions}

\begin{reactionalign}
    \begin{align}
        \cee{H2O2 + H2 &-> 3H2O}\\
        \cee{2C2H6 + 7O2 -> 4CO2 + 6H2O}
    \end{align}
\end{reactionalign}

\begin{equation}
    C = D
\end{equation}
\end{document}

This works perfectly, preserving the correct last value of the equation counter, while working well with the reaction counter too.

Sorry for the wall-o-code. I couldn't figure out how to post a MWE (new to the forum).

I hope this helps people. And if someone can find a better way to implement this, let me know!

EDIT: This is the hard way to go about this. See comments above for more efficient options.

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.