[Tex/LaTex] Exam Class: don’t print questions

exam

Suppose I am using the exam class. There is an option \printanswers to print solutions, otherwise solutions aren't printed. I would like to suppress questions and just print the solutions. Is this possible?

Edit

I've added a basic work-around, but perhaps there is a better way to do this? Here's a demo using the modified exam class, found here.

% Document
\documentclass[12pt]{exam2}

\usepackage[margin=1.0in]{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath}

\pagestyle{fancy}
\lhead{The author}
\rhead{The assignment}

\setcounter{section}{1}
\unframedsolutions

% Preamble
\printquestions
\printanswers

\begin{document}
\numberwithin{question}{section}

\begin{questions}

\begin{quest}
What is $\int_{0}^{5} x^2 dx$?

\end{quest}

\begin{solution}

This integral can be calculated as

\begin{align}
\int_{0}^{5} x^3 &= \Big[ \frac{x^3}{3} \Big|_{0}^{5} \notag \\
&= \frac{5^{3}}{3}
\end{align}

\end{solution}

\begin{quest} 
The next question would go here

\questp{a}{Part a of the question}
\questsp{i}{Subpart of a}
\questspnob{More information}

\end{quest}

\begin{solution}
The next answer would go here

\begin{parts}
\part Parts works in solution environment
\begin{subparts}
\subpart Here is a subpart
\end{subparts}
\end{parts}

\end{solution}

\end{questions}

\end{document}

Questions and answers

% Preamble: 
\printquestions
\printanswers

Questions and answers

Questions only

% Preamble:
\printquestions
%\printanswers

Questions

Answers only

% Preamble:
%\printquestions
\printanswers

Answers

Best Answer

I made the following changes to exam.cls.

First I added a \printquestions option.

\newif\ifprintanswers
\printanswersfalse
\DeclareOption{answers}{\printanswerstrue}
\DeclareOption{noanswers}{\printanswersfalse}

% BEGIN EDIT %
\newif\ifprintquestions
\printquestionsfalse
\DeclareOption{yesquestions}{\printquestionstrue}
\DeclareOption{noquestions}{\printquestionsfalse}
% END EDIT %

Then later on

\def\printanswers{\printanswerstrue}
\def\noprintanswers{\printanswersfalse}

\def\printquestions{\printquestionstrue}

Next, I modify the solution environment. If I don't print the questions, then I wanted the solution environment to act as a \question.

\newenvironment{solution}[1][0pt]{%
  \ifprintquestions % act as a solution
    \@insolutiontrue % cancelled by the end of the environment
    \@addpointsfalse % cancelled by the end of the environment
    \ifprintanswers
      \begingroup
      \Solution@Emphasis
      \begin{TheSolution}%
    \else
      \ifcancelspace
        % Do nothing
      \else
        \par
        \penalty 0
        \vspace*{#1}%
      \fi
      \setbox\z@\vbox\bgroup
    \fi
  \else %act as a question
    \question
  \fi
  }{%
  \ifprintquestions %act as a solution
    \ifprintanswers
      \end{TheSolution}%
      \endgroup
    \else
      \egroup
    \fi
    \fi
  }%

Next, I add a quest environment which can be hidden. However, this would need to be used instead of \question.

\newenvironment{quest}[1][0pt]%
  {%
    \ifprintquestions % act as a question
        \question
    \else % don't show the question
        %\par
        %\vspace*{-9mm} %
      \setbox\z@\vbox\bgroup
    \fi
  }{%
    \ifprintquestions
        % don't do anything
    \else % hide the group
      \egroup
    \fi
  }%

One annoying thing is that itemize lists, parts and subparts won't work in the environment I defined (I believe this is due to the \question call initializing some variables which I don't initialize. Therefore, I created some basic itemize list commands using the tabular environment.

% PART
\newcommand{\questp}[2]{%
\begin{tabular}{R{0.25cm} p{14.75cm}}
(#1) & #2 \\ 
\end{tabular}

{}
}

\usepackage{array,booktabs,ragged2e}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}}
\newcommand{\questsp}[2]{%
 \hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
(#1) & #2 \\
\end{tabular}

{}
}

% SUBPART
\newcommand{\questssp}[1]{%
\hspace*{8em}\begin{tabular}{p{10.75cm}}
#1 \\ 
\end{tabular}

{}
}

Some more part commands could be defined like this.

\newcommand{\questpnob}[1]{%
\begin{tabular}{R{0.25cm} p{13.15cm}}
 & #1 \\
\end{tabular}

{}
}

\newcommand{\questspnob}[1]{%
 \hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
& #1 \\
\end{tabular}

{}
}
Related Question