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

Raja
  • 450
  • You can use lrbox and a minipage, or my own udbox (see https://tex.stackexchange.com/questions/610570/latex-suppressing-a-piece-of-tex-output-but-keeping-numbering-etc-throughout/610573?r=SearchResults&s=1|44.3124#610573). – John Kormylo Oct 18 '21 at 14:10
  • @JohnKormylo I tried the following link: https://tex.stackexchange.com/questions/41665/cant-i-put-a-list-inside-an-lrbox , but it completely removes both points and question number. Since all these information is displayed inside the questions environment, the filtering process is not easy as I'm novice. Can u help me in this regard? – Raja Oct 18 '21 at 18:15

1 Answers1

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}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • 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 '21 at 04: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. – John Kormylo Oct 19 '21 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. – John Kormylo Oct 19 '21 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 '21 at 05:45