9

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
5

Using the chemmacros package:

\documentclass{article}
\usepackage{chemmacros}
\chemsetup{
  modules = {reactions} ,
  formula = mhchem
}
\begin{document}

\listofreactions

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

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

\end{document}

enter image description here

  • 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
4

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

\documentclass{article}
\usepackage{amsmath,mhchem}
\newenvironment{reaction}{\begin{equation}}{\end{equation}}
\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.

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

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}}
\begin{equation}
\addcontentsline{rxs}{reactions}{\protect\numberline{\thereaction}#1}
}{%
\end{equation}
\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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