Check out the Latest Articles:
Preparing exams in latex

In the past days I was busy writing up an (actually typesetting) an exam for the course I was TA-ing during Autumn. Although not very time consuming, I realized that knowing a couple of tricks might make you a lot more productive! Here are some of the tricks that I found while writing the exam in latex.

Define a simple structure for each question that you put in there. You should have such a block for each question.

% ————————————————————————–
\section*{Question 1 (5 points) }
Here you can ask the weird question …
%Time: \textit{5 minutes}
\newline \textcolor{blue}{Answer:
This is the right answer to the weird question!}
\vspace{40mm}

Use latex counters (really cool!) to generate the question number. This way you are sure to have all the questions numbered correctly even if you move them around or add/remove some.

% ————————————————————————–
% Set-up question number auto-generation.
% Just use \arabic{question} to insert the question number (auto-incremented value) and use \stepcounter{question} to go to next value.
% Each time a question is commented out, the questions will be re-numbered correctly.

\newcounter{question}
\setcounter{question}{0}

% ————————————————————————–
% The above question block becomes:
% ————————————————————————–

\stepcounter{question}
\section*{Question \arabic{question} (5 points) }
Here you can ask the weird question …
%Time: \textit{5 minutes}
\newline \textcolor{blue}{Answer:
This is the right answer to the weird question!}
\vspace{40mm}

Use conditionals (if-then-else) to easily toggle on and off the generation of the answers in the final .pdf. When working on the exam questions it’s good to have the answers there so that you can calibrate the time required for each question, but you don’t want the answers there for the final print-outs! Also, having the answers in there can be quite helpful during grading.

\usepackage{ifthen}


%————————————————————————–
% We can use the \answers command defined below to control if the answers to the questions are generated or not in the PDF
% Should we include the answers in the PDF or not?
% Setting the value to _false _ will not generate answers while setting it to _true_ will generate the answers

\newcommand{\answers}[0]{false}

% ————————————————————————–
% The above question block becomes:
% ————————————————————————–

\stepcounter{question}
\section*{Question \arabic{question} (5 points) }
Here you can ask the weird question …
%Time: \textit{5 minutes}
\ifthenelse{\equal{\answers}{true}}{\newline \textcolor{blue}{Answer:
This is the right answer to the weird question!}}{}
\vspace{40mm}

Comment out questions that you don’t need rather then deleting them – who knows when you might need them! Also for commenting out questions use LaTeX block commenting rather than per-line comments!

\usepackage{verbatim}

% ————————————————————————–
% The above question block becomes:
% ————————————————————————–

\begin{comment}
\stepcounter{question}
\section*{Question \arabic{question} (5 points) }
Here you can ask the weird question …
%Time: \textit{5 minutes}
\ifthenelse{\equal{\answers}{true}}{\newline \textcolor{blue}{Answer:
This is the right answer to the weird question!}}{}
\vspace{40mm}

\end{comment}

Doing the total points from all the active question is also simple. We define two counters – one for the total points and one for the total number of questions, as well as the command “points” that sums up things in the two new counters.

\newcounter{totalpoints}
\setcounter{totalpoints}{0}
\newcounter{totalquestions}
\setcounter{totalquestions}{0}
\newcommand{\points}[1]{#1\addtocounter{totalpoints}{#1}\addtocounter{totalquestions}{1}}

% ————————————————————————–
% The above question block becomes:
% ————————————————————————–
\stepcounter{question}
\section*{Question \arabic{question} (\points{5} points) }
Here you can ask the weird question …
%Time: \textit{5 minutes}
\ifthenelse{\equal{\answers}{true}}{\newline \textcolor{blue}{Answer:
This is the right answer to the weird question!}}{}
\vspace{40mm}

% ————————————————————————–
% after all the other questions
% ————————————————————————–

The exam has a total of \value{totalquestions} questions that are worth \value{totalpoints} points.

[Photo credit: http://www.flickr.com/photos/osucommons/3946087716/, under no known copyright restrictions]


If you want to spread the word:
Twitt about this!

  1. Stefan Ciobaca on Thursday 21, 2010

    You could also use the exercise package: http://www.ctan.org/tex-archive/macros/latex/contrib/exercise/ ;-)

  2. Timotei Dolean on Thursday 21, 2010

    Thanks for the tips. This will surely shorten my time typesetting the documents in latex.

  3. Timotei Dolean on Thursday 21, 2010

    Btw, how about addin float number as points? I can’t manage to add 5,5 or 5.5 points instead of 5, and it wouldn’t do the right thing.

  4. salo on Thursday 21, 2010

    My implementation for adding the points relies on the counter commands which unfortunately support only integer values.
    Maybe the exercise package suggested by @Stefan might have extra support …

    Also you might think of increasing the total number of points by 10x so you get rid of the half points.



Bad Behavior has blocked 1226 access attempts in the last 7 days.