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.
Code: Select all
\documentclass[11pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[version=3]{mhchem}
\makeatletter
\newcounter{reaction}
%%% >> for article <<
%\renewcommand\thereaction{C\,\arabic{reaction}}
%%% << for article <<
%%% >> for report and book >>
\renewcommand\thereaction{C\,\thechapter.\arabic{reaction}}
\@addtoreset{reaction}{chapter}
%%% << for report and book <<
\newcommand\reactiontag{\refstepcounter{reaction}\tag{\thereaction}}
\newcommand\reaction@[2][]{\begin{equation}\ce{#2}%
\ifx\@empty#1\@empty\else\label{#1}\fi%
\reactiontag\end{equation}}
\newcommand\reaction@nonumber[1]{\begin{equation*}\ce{#1}%
\end{equation*}}
\newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother
\begin{document}
\begin{equation}
a+b
\end{equation}
\reaction{CO2 + C}
\reaction*{CO2 + C}
\reaction[react:co]{CO2 + C}
\begin{equation}
a+b
\end{equation}
\end{document}
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.