2

Is it somehow possible to add the chapter number to the reaction counter of chemmacros and to reset it if chapter increases? In equation and figure etc. the chapter is added before the counter, like 1.2 with first number the chapter and second number the figure etc. in report/book and KOMA scrreprt/scrbook.

MWE:

\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{chemmacros}
\chemsetup{modules=reactions}
\begin{document}
\chapter{Reactions without chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat booth with counter resetting}
With (x.1).y
\begin{equation}
    f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z, but incremented.
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}
\end{document}
3

The chemmacros package has \renewtagform exactly for this (see page 35 of the package documentation). To be used for example as follows:

\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{chemmacros}
\chemsetup{modules=reactions}

\renewtagform{reaction}[\thechapter.]{(}{)}

% Phelype Oleinik's answer added: 
\makeatletter
\@addtoreset{reaction}{chapter}
\makeatother

\begin{document}
\chapter{Reactions without chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat booth with counter resetting}
With (x.1).y
\begin{equation}
    f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z, but incremented.
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}
\end{document}
  • As this solution does not need additional packages and is complete, I mark it as the correct one. – Niklas Feb 6 '18 at 22:07
3

With the chngcntr package:

\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{chemmacros}
\chemsetup{modules=reactions}

\usepackage{chngcntr}
\counterwithin{reaction}{chapter}

\begin{document}

\chapter{Reactions chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
With x.z
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat both with counter resetting}
With (x.1).y
\begin{equation}
    f(x)=e^{\frac{1}{x}}
\end{equation}
With x.z
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}

\end{document} 

enter image description here enter image description here

3

No additional packages or \makeatletter definitions necessary:

\documentclass{scrreprt}
% \usepackage{amsmath} already loaded by `chemmacros'
\usepackage{chemmacros}
\chemsetup{modules=reactions}
\numberwithin{reaction}{chapter}% provided by the `amsmath' package

\begin{document}

\chapter{Reactions without chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat booth with counter resetting}
With (x.1).y
\begin{equation}
    f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z, but incremented.
\begin{reaction}
    H2O + H3O+ -> H2O2 + H+
\end{reaction}

\end{document}

enter image description here

2

There is the command \@addtoreset which resets one counter when another is increased.

Just add this to your preamble:

\makeatletter
\@addtoreset{reaction}{chapter}
\makeatother

It will reset the reaction counter when the chapter counter is increased.

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.