# Number mhchem reactions and create a \listofreactions

Is there a way to create an environment for reactions defined with mhchem that behaves similarly to equation in terms of numbering the reactions (including a \nonumber command)? Can I get a list of those reactions?

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

\newcounter{rxnum}

\newenvironment{reaction}{
\refstepcounter{rxnum}
\noindent
%???
}{
%???
\par\noindent
}

\begin{document}

\begin{reaction}
\ce{X + Y -> XY}
\end{reaction}

\begin{reaction}
\ce{XX + YY -> X2Y2} \\%<- newline just like in equation
\ce{A + B -> C}
\end{reaction}

\end{document}


This is a two part question. The first part is about creating an environment that behaves similarly to equation, but for reactions defined in mhchem. I had a look in source2e in the definition of equation (around l. 293 in source2e) but couldn't quite figure out how to transfer that onto my new environment.

The second part is about how to create a list of those reactions containing the reaction number, the page they occur on and optional a description that is only printed in the \listofreactions.

For example:

In the code I write

\begin{reaction}
\ce{X + Y ->XY}\descriptionforlist{XY formation reaction}\\
\ce{A +B -> C}
\ce{G + H -> J}\nonumber
\end{reaction}


Then in the list it should appear as

List of reaction

R 1: XY formation reaction                6

R 2:                                      6

-

Inspired by your question I recently added a \listofreactions to my package chemmacros:

\documentclass{article}
\usepackage{chemmacros}

\begin{document}

\listofreactions

\begin{reaction}[bla]
$A$ ->[ H2O ] $B$
\end{reaction}

\begin{reaction}
SO4^2- + Ba^2+ -> BaSO4 v
\end{reaction}

\end{document}


-
Excellent, thank you very much. This will be very useful for everyone dealing with math and chemisty simultaneously – Martin H Mar 4 '12 at 20:15

To develop an environment \begin{reaction}...\end{reaction} you can use the code below:

\documentclass{article}
\usepackage{amsmath,mhchem}
\newenvironment{reaction$$}{$$$$}{$$}
\newenvironment{reaction*$$}{$$\begin{equation*}$$}{$$\end{equation*}}
\begin{document}
\begin{reaction}
\ce{$A$ ->[\ce{+H2O}] $B$}
\end{reaction}
\begin{reaction}
\ce{SO4^2- + Ba^2+ -> BaSO4 v}
\end{reaction}
\end{document}


To develop a listofreactions use the titletoc package.

-
This however does use the same counter as equation. – Martin H Feb 18 '11 at 22:19

This is my solution now including a separate reaction counter and a new list of reactions. It is not fully tested yet but works in my simple test document

\documentclass{article}
\usepackage{amsmath,mhchem}
\usepackage{tocloft}
\newcommand{\reactionlistname}{List of reactions}
\newlistof{reactions}{rxs}{\reactionlistname}

\newcounter{reaction}
\newcounter{tmp}
\newenvironment{reaction}[1][\relax]{%
\setcounter{tmp}{\value{equation}}
\setcounter{equation}{\value{reaction}}
\renewcommand{\theequation}{\arabic{equation}}
$$\addcontentsline{rxs}{reactions}{\protect\numberline{\thereaction}#1} }{%$$
\setcounter{reaction}{\value{equation}}
\setcounter{equation}{\value{tmp}}
}

\begin{document}

\listofreactions

\begin{reaction}[bla]
\ce{$A$ ->[\ce{+H2O}] $B$}
\end{reaction}

\begin{reaction}
\ce{SO4^2- + Ba^2+ -> BaSO4 v}
\end{reaction}

\end{document}


-