# Create New Type of Align Environment with Unique Counter

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!

-
What did you try? How didn't it work? –  Seamus Jun 27 '12 at 13:27
I was referring specifically to the reactions environment, which gives you the alignment and the separate numbering. –  Jellby Jun 27 '12 at 15:19
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
See also the other question about numbering mhchem reactions... –  cgnieder Jun 27 '12 at 16:42

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}
$$A = B$$

\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}

$$C = D$$
\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!