# Multiple Exams in One File

I need to create an exam which consists of two parts A and B. From these two parts, I need to create three versions: one which contains part A and B, one which only contains part A and one which only contains part B. Each version needs to have a custom title page, its own page and question numbering, and a point table.

What I would like to have in the end is a single PDF file of the following structure:

• title page for A + B (page no. 1)
• questions from A numbered 1 to n
• questions from B numbered n + 1 to m
• title page for A (restart page and question numbering, set point sum back to 0)
• questions from A numbered 1 to n
• title page for B (restart page and question numbering, set point sum back to 0)
• questions from B numbered 1 to m

Currently, I use the following approach: one file contains the questions from A; one file contains those from B. A master file includes these files and uses custom counters to restart the page/question numbering when appropriate. This works okay but it would be nice if I could use some of the features in the exam class (e.g. optionally show solutions, boxes for the answers relative to the page height). I am aware that these features can be implemented manually but this is time consuming and the result is probably less user-friendly than using a well-maintained, well-documented external package/class.

This, finally, brings me to my question: can this be achieved using the exam class (especially, having multiple point sums in one file) or a different package?

Edit: Using the answers from the question which is linked in the comments I was able to get pretty close to what I need. I now have three file:

a.tex:

\question A's first question
\begin{parts}
\part[1] part 1
\part[2] part 2
\part
\begin{subparts}
\subpart[1] 3a
\subpart[2] 3b
\end{subparts}
\end{parts}

\question[2] A's second question


b.tex:

\question B's first question
\begin{parts}
\part[2] part b1
\part[2] part b2
\end{parts}

\question[1] B's second question
\question[2] B's third question


main.tex:

    \documentclass[a5paper, addpoints]{exam}

\pointsinrightmargin

\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}

\begin{document}
\begin{questions}
\begingradingrange{AB}
\uplevel{
% Title page for A + B
\partialgradetable{AB}[h][questions]
}

\input{a.tex}
\input{b.tex}
\endgradingrange{AB}
\clearpage
\setcounter{page}{1}

\begingradingrange{onlyA}
\uplevel{
% Title page for A
\partialgradetable{onlyA}[h][questions]
}
\input{a.tex}
\endgradingrange{onlyA}
\clearpage
\setcounter{page}{1}

\begingradingrange{onlyB}
\uplevel{
% Title page for B
\partialgradetable{onlyB}[h][questions]
}
\input{b.tex}
\endgradingrange{onlyB}
\clearpage
\end{questions}
\end{document}


Compiling main.tex creates three pages:

The first page is exactly how I want it to be. The question numbering - especially, in the grade table - on the second and third page, however, has to start with question 1 again.

I hope that this clarifies my question.

• A lot of requests for not providing a MWE to start with ;-) – user31729 Mar 6 '15 at 9:32
• Since A and B are completely independant, wouldn't it be much easier to simply merge the resulting pdfs? – Johannes_B Mar 6 '15 at 9:33
• @Johannes_B I don't tink so since he needs a sum of points – touhami Mar 6 '15 at 9:35
• see here it maybe helpful tex.stackexchange.com/questions/209504/… – touhami Mar 6 '15 at 9:37
• @JPW the second answer there doesn't do this? if not you shoud give a minimal code of what you have and what youneed. – touhami Mar 6 '15 at 12:20

## 1 Answer

Here is a solution

\documentclass[a5paper, addpoints]{exam}

\pointsinrightmargin

\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
%---------------------------------------------------
\newcounter{mtexo}
\newcommand{\setpart}{%
\setcounter{page}{1}\setcounter{mtexo}{0}%
\renewcommand{\thequestion}{\themtexo}}
%---------------------------------------------------
\begin{document}
\begin{questions}
%---------------------------------------------------
\let\mtquestion\question
\def\question{\refstepcounter{mtexo}\mtquestion}
%---------------------------------------------------
\begingradingrange{AB}
\uplevel{
% Title page for A + B
\partialgradetable{AB}[h][questions]
}

\input{a.tex}
\input{b.tex}
\endgradingrange{AB}
\clearpage
\setpart%\setcounter{page}{1}

\begingradingrange{onlyA}
\uplevel{
% Title page for A
\partialgradetable{onlyA}[h][questions]
}
\input{a.tex}
\endgradingrange{onlyA}
\clearpage
\setpart%\setcounter{page}{1}

\begingradingrange{onlyB}
\uplevel{
% Title page for B
\partialgradetable{onlyB}[h][questions]
}
\input{b.tex}
\endgradingrange{onlyB}
\clearpage
\end{questions}
\end{document}


you can add the \clearpage command to \setpart

• Redefining \thequestion indeed seems to do the trick. Thank you very much! – JPW Mar 9 '15 at 16:32