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.

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
share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

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}

enter image description here

It can also be used together with mhchem:

\documentclass{article}
\usepackage[method=mhchem]{chemmacros}

\begin{document}

\listofreactions

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

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

\end{document}
share|improve this answer
    
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
add comment

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.

share|improve this answer
    
This however does use the same counter as equation. –  Martin H Feb 18 '11 at 22:19
add comment

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

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.