1

I created an exam using the exam class. I have a small makefile that creates the solutions by adding the answers option to the documentclass. What I would like to change however, is that the title of the exam changes, if I compile with the answers option, such that it says e.g. "Solutions" in red. Is there a simple way (ideally built in the exam package) to achieve that?

2 Answers2

1

Together with the option answers, you can use the command \ifprintanswers. For example:

\documentclass[11pt,addpoints,answers]{exam}

(...)

\begin{document}

\ifprintanswers
    \centerline{\bf Final Exam -- Solutions}
\else
    \centerline{\bf Final Exam}
\fi

\begin{questions}
(...)
\end{questions}

\end{document}

You can see more details in the exam class documentation.

Andre
  • 969
0

I solved my problem with this post:

Before \begin{document} these three lines

\makeatletter
\@ifclasswith{exam}{answers}{\newcommand{\mytitle}[1]{\textcolor{red}{Solution: #1}}}{\newcommand{\mytitle}[1]{#1}}
\makeatother

Create a macro that depends on whether the answers option is set or not. At some later point, I can use the macro, e.g.

\mytitle{FINAL EXAM}

Which prints FINAL EXAM if the option is not set, and prints Solution: FINAL EXAM in red if the option is set.