11

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
0

4 Answers 4

9

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

1
  • 1
    Excellent, thank you very much. This will be very useful for everyone dealing with math and chemisty simultaneously
    – Martin H
    Mar 4, 2012 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
  • 2
    This however does use the same counter as equation.
    – Martin H
    Feb 18, 2011 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

1

As pointed out by @cgnieder it is possible to use chemmacros package.

My solution involves the change of the reference brackets and the introduction of an additional letter to denote them.

Please, note that \usepackage{chemmacros} is essential not to get an error.

\usepackage[version=4]{mhchem}
\usepackage{chemfig}
\usepackage{chemmacros}
\usechemmodule{reactions}

\chemsetup[reactions]{
  before-tag = R ,
  tag-open = ( ,
  tag-close = )
}

\begin{document}

\listofreactions

\begin{reactions}
    CH4 + H2O <=> CO + 3 H2
\end{reactions}

\end{document}

If you have more than one reaction, you can align them with respect to a specific point, by adding &, and also refer to every equation, for example:

\begin{reactions}
    \label{her:Volmer}
    H3O+ + e- + $\ast$ &-> H$\ast$ + H2O \quad \text{(Volmer)} \\
    \label{her:Heyrovsky}
    H3O+ + H$\ast$ + e- &-> H2 + H2O \quad \text{(Heyrovsky)} \\
    \label{her:Tafel}
    2 H$\ast$ + e- &-> H2 \quad \text{(Tafel)}
\end{reactions}

Output

1
  • You should also add \chemsetup{formula=mhchem} otherwise chemmacros won't use mhchem
    – cgnieder
    Jan 28, 2022 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .