[Tex/LaTex] How to reset the question number for different sections in exam class without getting multiply defined labels

examwarnings

This is the minimal working example:

\documentclass[a4paper,11pt]{exam}
\begin{document}

\section{ONE}
\begin{questions}  
\question First question
\question Second questoion
\end{questions}

\section{TWO}
\begin{questions}  
\question First question
\question Second questoion
\end{questions}


\end{document}

The problem I have with this is that there is a warning for multiply defined labels.
Which in a very big document sometimes makes the compilation hang.

Is there a fix for that?

Best Answer

I'm not sure if this is the right way to do this but I found a way to fix this recently, any other ideas and comments on what I did are very welcome.

I changed two lines in the exam.cls which are

line2566

\edef\@queslabel{question@\arabic{question}}%

to

\edef\@queslabel{question@\arabic{section}@\arabic{subsection}@\arabic{question}}%

and

line2893

\edef\@partlabel{part@\arabic{question}@\arabic{partno}}%

to

\edef\@partlabel{part@\arabic{section}@\arabic{subsection}@\arabic{question}@\arabic{partno}}%

I only changed this two since they were the ones giving me the warnings and I don't use subparts or subsubparts. I guess if needed, those should be changed too.

Related Question