## LaTeX forum ⇒ General ⇒ chemical equation numbering

LaTeX specific issues not fitting into one of the other forums of this category.
yotama9
Posts: 61
Joined: Thu Sep 24, 2009 2:59 pm

### chemical equation numbering

Hi guys.

Is there a way to automatically number chemical equations? I want to number them the same way as mathemtical formula i.e.:

\begin {equation}   E = mc^2   \label {Einsteins'} \end {equation}

so I want something like:
\begin {chem equation}   H^+ + OH^- \arrow H_2 O   \label {Einsteins'} \end {chem equation}

*I'm using the mhchem package.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
I assume you have already read the mhchem manual.

Best regards
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm
If you want equations, use equations! If you want some kind of float, take a look at chemscheme. Also take a look at bpchem and chemcompounds.
Joseph Wright

yotama9
Posts: 61
Joined: Thu Sep 24, 2009 2:59 pm
I want to separate my equations from my schemes. I don't want the schemes to be floats. I want them where I put them. I only want that I would be able to number and reference chemical scehmes as easily as I would mathematics formula.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
Beside Joseph's advice I think you should take a look at the mhchem manual (»Tips and Tricks«, p. 10f). Just take this code and you got it.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

yotama9
Posts: 61
Joined: Thu Sep 24, 2009 2:59 pm
localghost wrote:Beside Joseph's advice I think you should take a look at the mhchem manual (»Tips and Tricks«, p. 10f). Just take this code and you got it.

You (not only localghost) are insisting on giving me the wrong solutions. I want to create a new counter for my chemical formulas. I cannot think on a better way to explain it.

On the documentations of mhchem the example add the chemical equations counting to the mathematical equations counter which is not good as I won't be able to reffer them.

yotama9
Posts: 61
Joined: Thu Sep 24, 2009 2:59 pm
I found a solution.
It's not perfect but it does the trick.

I read the Tabula Rasa post and I did something similar:

I created the following command:
\newcounter{reaction}\addtocounter{reaction}{1}\newcommand{\reaction}[1]{	\begin{flushleft}	\centering	{#1}	\end{flushleft}	\begin{flushright}	reaction(\arabic{chapter}.\arabic{reaction} \stepcounter{reaction})	\end{flushright}}

I got to problems with it now.
It is ugly solution, meaning the flushleft part
I get one extra line between the reaction and the number.

Any thoghts?

Thanks.

p.s. If someone was offended by my previous post I'm deeply sorry. I do appreciate the help and effort.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
I'm still convinced that the example from the mhchem manual is the most proper solution. But I had an idea and collected some code snippets from the latex.ltx file and the report class file. I modified them and got the result below.
\documentclass[11pt,a4paper,english]{report}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage{babel}\usepackage{amsmath,amssymb} \makeatletter\@definecounter{reaction}\def\reaction{$$\refstepcounter{reaction}}\def\endreaction{\eqno \hbox{\@reacnum}$$\@ignoretrue}\def\@reacnum{{\normalfont \normalcolor (\thereaction)}}\@addtoreset{reaction}{chapter}\renewcommand\thereaction{C\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@reaction}\makeatother \begin{document}   \chapter{One}   An equation   \begin{equation}     E=mc^2   \end{equation}    A reaction   \begin{reaction}\label{rctn:water}     H^+ + OH^- \leftrightharpoons H_2O   \end{reaction}   The reference to reaction \eqref{rctn:water}.    \medskip   Another equation   \begin{equation}     E=mc^2   \end{equation}\end{document}

This creates a new reaction environment derived from the equation environment. Therefore it behaves exactly the same way. The reaction counter has been marked with a »C« to separate it optically. I'm not sure if this is what you want.

Note that at the moment this only works with the report class and doesn't represent a general solution but only a first basic approach. For other classes there might be some accommodations needed. I didn't take a look but this might be done much easier with the mathtools package from the mh bundle.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

yotama9
Posts: 61
Joined: Thu Sep 24, 2009 2:59 pm
localghost, I read the mhchem documentation more then one time and I couldn't find an explanation on how number my chemical formulas. Can you please type in a short example?

What does bind your solution for the report document class only? As you can guess, I'm hardly a medium level latex user. I can't understand the code (I can guess the function though). I thought at first to use the equation environment but I didn't know how to separate the counting.

Thanks.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
yotama9 wrote:[…] I read the mhchem documentation more then one time and I couldn't find an explanation on how number my chemical formulas. Can you please type in a short example? […]

I thought I already directed you to the relevant place in the manual. In order not to lengthen this matter take a look at the code below.

This is exactly the code given on page 10 of the mhchem manual. But it is still not a full automatism. You have to choose the appropriate lines according to your document class (see comments).
yotama9 wrote:[…] What does bind your solution for the report document class only? As you can guess, I'm hardly a medium level latex user. I can't understand the code (I can guess the function though). I thought at first to use the equation environment but I didn't know how to separate the counting. […]

The reason is very simple. As mentioned in my last reply I collected some code from the source of the report class. The major part is from the LaTeX kernel. My example may work with the book class (and I'm pretty sure it will). But it doesn't work with the article class because this class doesn't support chapters. There would be the possibility for an if-else-branch but at the moment I haven't got the time to figure out an appropriate implementation.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1