# Labeling problems with exam class usage when using multiple chapters

Using the exam document class I'm trying to create a questions/answers-sheet for a book. When working on the first chapter, everything worked nicely. When I came to the second chapter, I realized I would have problems with the question numbering, since there are questions with the same numbers. The specific warnings I got was:

LaTeX Warning: Label question@1' multiply defined.


The basic layout of the body of my document is as follows:

\section*{Chapter 1}
\setcounter{section}{1}
\begin{questions}
\numberwithin{question}{section}
\setcounter{question}{0}
\question

\begin{solution}

\end{solution}
\end{questions}

\section*{Chapter 2}
\setcounter{section}{2}
\begin{questions}
\numberwithin{question}{section}
\setcounter{question}{0}
\question

\begin{solution}

\end{solution}
\end{questions}


Compilation still works, but my editor is giving me a page full of warnings. There has to be a better more correct way, than what I'm doing right now. Could you recommend me a different way to make such a document?

-
Welcome to the site, Martin. Please could you provide a complete .tex file (starting with \documentclass etc) so that I can reproduce your error on my machine? –  John Wickerson May 11 '13 at 12:08
Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. –  Peter Jansson May 11 '13 at 12:17
@JohnWickerson I can't upload the full document. I have made a similar document, which produces the same warning: gist.github.com/MartinRogalla/5559828 –  Misha Rogalla May 11 '13 at 12:26
@MartinRogalla we don't need a full document we just need the example in the question fixing (you only need to add three more lines) –  David Carlisle May 11 '13 at 12:36

Looking at the source exam class would need quite a few changes to use repeated numbers as it uses the number counter internally in several places. However to help anyone else answering and to address other problems in the posted document here is a start at a solution.

You shouldn't use star form for numbered sections, and \numberwith should only be used once. the fact that it wasn't having an effect and you had to manually reset the question counter is related to your use of the * form. Nested counters reset when the parent counter is incremented with \stepcounter (or better \refstepcounter) setting the section counter via \setcounter does not do this (and also means you can not use \label and \ref to refer to the section.

update Perhaps the easiest way to restart the equation numbering without breaking the rest of the features is to maintain the counter with unique numbers eg 101, 1002, in the first section and 201, 202 in the second, and then just arrange that this gets printed as 1.1,1.2,2.1,2.1 in the heading:

\documentclass{exam}
\usepackage{amsmath}

\makeatletter

\def\@seccntformat#1{%
\expandafter\ifx\csname the#1\endcsname\thesection Chapter~\fi
\csname the#1\endcsname
\setcounter{question}{\thesection00}%

\renewcommand\thequestion{%
\the\numexpr(\value{question}-49)/100\relax.%
\the\numexpr\value{question}-(100*((\value{question}-49)/100))\relax}

\makeatother

\begin{document}

\begin{questions}
\fullwidth{\section{}}
\question aaa

\begin{solution}
xxx
\end{solution}

\fullwidth{\section{}}

\question bbb

\begin{solution}
yyy
\end{solution}
\end{questions}

\end{document}
`
-