1

I am trying to customize the question environment of exam.cls. I want to have a command like \printquestions to hide/unhide the questions, while retaining the points and question labels.

I have used environ package to create an enviroment around each question content to do this.

\newif\ifkeepquestion \keepquestiontrue
\NewEnviron{qsn}{\ifkeepquestion\BODY\fi}

\begin{document}

\begin{questions}
\pointsdroppedatright

%1
\question[10]
\begin{qsn}
Describe the effect on the balloon industry.
\end{qsn}
\droppoints

\end{questions}

\end{document}

Is there is any direct way to hide the content "Describe the effect on the balloon industry." inside the exam.cls, rather than relying on Environ package.

I tried to look into the \newenvironment{questions} of exam.cls file, where it uses \list command and \item to create the content. Can we modify the \item definition to either hide or unhide the content, based on \ifkeepquestion

2

1 Answer 1

0

This will show the question number (and the points) but not the question itself. The question itself will not break over pages and will exhibit hanging indentation (I forget whether that is normal).

Apparently, \question sets local values which will not be preserved if placed inside an environment. You would need to dig into the code, find them and set them globally.

\documentclass{exam}

\newif\ifkeepquestion \keepquestionfalse
\newsavebox{\questionbox}

\newenvironment{qsn}{\begin{lrbox}{\questionbox}\minipage[t]{\linewidth}}%
{\endminipage\end{lrbox}\ifkeepquestion \usebox\questionbox  \fi}

\begin{document}
\begin{questions}
\pointsdroppedatright

\question[10]\begin{qsn}
Describe the effect on the balloon industry.
\end{qsn}
\droppoints

\end{questions}
\end{document}

This modifies \question inside the savebox just to steal the points argument. It includes a number of patches (outside the savebox) needed to get \droppoints to work.

\documentclass{exam}
\usepackage{showframe}
\usepackage{etoolbox}

\newif\ifkeepquestion \keepquestiontrue
\newsavebox{\questionbox}
\newcommand{\pointsarg}{}% reserve global name

\makeatletter
\newenvironment{qsn}{\begin{lrbox}{\questionbox}%
  \minipage[t]{\linewidth}%
    \renewcommand{\question}[1][0]{\xdef\pointsarg{##1}}}% local definition
{\endminipage\end{lrbox}%
  \question[\pointsarg]%
  \ifkeepquestion
    \usebox\questionbox
  \fi}

\patchcmd{\@readpoints}{\def\@points}{\gdef\@points}{}{FAILED}
\patchcmd{\item@points@pageinfo}{\def\padded@point@block}{\gdef\padded@point@block}{}{1}
\patchcmd{\item@points@pageinfo}{\def\padded@point@block}{\gdef\padded@point@block}{}{2}
\makeatother

\begin{document}
\begin{questions}
\pointsdroppedatright

\begin{qsn}\question[10] Describe the effect on the balloon industry.  
Yada yada yada yada yada yada yada yada yada yada yada yada yada yada yada yada yada yada yada.
\end{qsn}

\droppoints

\end{questions}
\end{document}
4
  • I don't want to use \begin{qsn} around the question content. As you pointed out, one has to go through the exam.cls file. But as I mentioned, the questions environment uses \list and \item commands. I just want to know is there's any way to collect the content of the question
    – Raja
    Oct 19, 2021 at 4:29
  • The problem with \item is that it doesn't treat the following text as an argument. It just ends the previous item with a \par, sets the margins and writes the label field in that margin. This is why text breaks normally in a list. It is normal text. Oct 19, 2021 at 14:15
  • It turns out that the points argument is handled by \@doitem and \@readpoints, in case you want to look through the code. Oct 19, 2021 at 15:48
  • Yes, it's \@doitem that switches between \@readpoints and \item@points@pageinfo. Can there be any mechanism, where one can capture the argument/content during \item command declaration in \item@points@pageinfo? Should I need to modify \def\question to \def\question[#1]#2 to capture the contents?
    – Raja
    Oct 20, 2021 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .