# Chemnum: Chapter-related numbering?

First of all, I just started with LaTeX. So far, I got everything working, including chemnum.

However, I want to split my thesis into chapters. Numbering of the compounds is supposed to be 1.1, 1.2, 1.3 etc. Next chapter, it starts with 2.1, 2.2, 2.3.

Is there a way to do this with chemnum? Could not find anything.

• Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs Aug 17 '13 at 18:33
• This kind of numbering is actually not taken into account by chemnum. It actually seems strange to me: should the same compound have different numbers in different chapters? – cgnieder Aug 17 '13 at 18:36
• Sorry, I did not think a MWE could be useful here. In case of the identical compound in different chapters, the numbering should be the same. Example: Compound is introduced in Chapter 1 as 1.4, and would be labelled in Chapter 3 as 1.4. – screeny2 Aug 17 '13 at 18:47
• \begin{document} \chapter{One} \begin{figure}[h] \centering \cmpdref{cmpd1} \cmpdref{cmpd2} \includegraphics{test.eps} \caption{\cmpd{cmpd1} and \cmpd{cmpd2}} \end{figure} %I want this to give 1.1 and 1.2 \chapter{Two} \begin{figure}[h] \centering \cmpdref{cmpd1} \cmpdref{cmpd2} \includegraphics{test.eps} \caption{\cmpd{cmpd1} and \cmpd{cmpd2}} \end{figure} %This should give 2.1 and 2.2 – screeny2 Aug 17 '13 at 18:49
• @cgnieder I've seen this done, and while I would not recommend it there are people who like it. (I don't like per-chapter numbering at all.) – Joseph Wright Aug 17 '13 at 18:50

Supplement 2014/03/14:

Two days ago v1.0 of chemnum was released. There have been various changes. One of them is a built-in possibility for a case like this:

\documentclass{book}
\usepackage{chemnum}

\makeatletter
% new counter format for chemnum:
\newcmpdcounterformat{chapter}{\thechapter.\@arabic}
\makeatother

\setchemnum{
counter-within = chapter ,
counter-format = chapter % use new counter format
}

\begin{document}

\chapter{First}
\cmpd{a} and \cmpd{b}

\chapter{Second}
\cmpd{a} and \cmpd{c}

\end{document}


A temporary solution based on Heiko's answer:

\documentclass{book}
\usepackage{chemnum}

\ExplSyntaxOn
\cs_new:Npn \int_to_chapter:n
{ \thechapter . \int_to_arabic:n }

% add the new choice to the options:
\keys_define:nn { chemnum }
{
cmpd-counter .generate_choices:n =
{ arabic , alph , Alph , greek, Greek , roman , Roman , Symbol , chapter }
}
\ExplSyntaxOff

% choose the new option:
\cmpdsetup{cmpd-counter=chapter}

% reset counter every new chapter:
\usepackage{etoolbox}
\preto\chapter{\cmpdreset}

\begin{document}

\chapter{First}
\cmpd{a} and \cmpd{b}

\chapter{Second}
\cmpd{a} and \cmpd{c}

\end{document}

• This actually works! Thanks to all of you :) – screeny2 Aug 17 '13 at 20:21

A hack to add the chapter number:

\documentclass{book}
\usepackage{chemnum}

\begingroup
\makeatletter
\catcode\_=11 %
\catcode\:=11 %
\global\let\org@cmpd\cmpd
\gdef\cmpd#1{%
\begingroup
\cmpdsetup{cmpd-counter=Symbol}%
\def\int_to_Symbol:n{%
\thechapter.\int_to_arabic:n
}%
\org@cmpd{#1}%
\endgroup
}%
% reset numbers at chapters
\@firstofone{\endgroup
\let\c@chemnum@counter\g__chemnum_cmpd_int
}
\endgroup

\begin{document}
\chapter{First}
\cmpd{a} and \cmpd{b}
\chapter{Second}
\cmpd{a} and \cmpd{c}
\end{document}


Result:

Chapter 1: 1.1 and 1.2
Chapter 2: 1.1 and 2.1

• +1 Nice idea :) The counter is not reset at chapters, though. The code thus gives 2.3 instead of 2.1. – cgnieder Aug 17 '13 at 20:13
• Thanks! But indeed, it gives 2.3. Also do I have some additional Output like "1.1 cmpd1 1.1 cmpd2 1.1", and I don't know where that is coming from. Might as well be a mistake by me due to the lack of experience... – screeny2 Aug 17 '13 at 20:18