0

I want to use both \question and \titledquestion of the exam documentclass without messing up the gradetable. From this question we know how to patch the questions environment in order to preserve the grade table with the numbers of the questions. But the solution to that question works for \titledquestion only, it breaks down if some of the questions are typeset using the \question command without a title.

For example having question 2 input with the \question command (see the MWE below) will result in a line "Question 2: 2...". We see that exam treats the number of the question as its title and thus prints it twice. In this case I want it reduced to "Question 2...", but at the same time I want to keep the behaviour for titled questions.


I have tried to compare the macros with an if statement:

\if\thequestiontitle\thequestion ...

but this approach seems too simple and I couldn't get it to work anyway. My MWE attached:

\documentclass[addpoints]{exam}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\questions}
  {\def\@currentlabel{\thequestiontitle}}
  {\def\@currentlabel{\thequestion}}
  {}
  {}
\makeatother
\qformat{Question~\thequestion:~\thequestiontitle\dotfill (\thepoints)}

\begin{document}
\begin{questions}
\titledquestion{Wood}[15]
How much wood would a woodchuck chuck if a woodchuck could chuck
wood?
\question[10] Here the problem turns up!
\end{questions}
\gradetable[v][questions]
\end{document}
1
  • 1
    The easy soultion is to always use \titledquestion, but with an empty title. It seems to me that the only problem is that both \question and \titledquestion use the same \qformat. Nov 19, 2023 at 14:36

1 Answer 1

1

Assuming your objection is to the extra "2" in the question title...

\documentclass[addpoints]{exam}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\questions}
  {\def\@currentlabel{\thequestiontitle}}
  {\def\@currentlabel{\thequestion}}
  {}
  {}
\patchcmd{\questions}
  {\def\question{%
    \@bonusfalse
    \def\thequestiontitle{\csname p@question\endcsname
                          \csname thequestion\endcsname}%
    \process@question
  }}%
  {\def\question{%
    \@bonusfalse
    \def\thequestiontitle{\csname p@question\endcsname}%
    \process@question
  }}%
  {}
  {FAILED}
\makeatother
\qformat{Question~\thequestion:~\thequestiontitle\dotfill (\thepoints)}

\begin{document}
\begin{questions}
\titledquestion{Wood}[15]
How much wood would a woodchuck chuck if a woodchuck could chuck
wood?
\question[10] Here the problem turns up!
\end{questions}
\gradetable[v][questions]
\end{document}
2
  • Would it be easy to remove to colon as well? The \qformat contains a colon that makes sense for titled questions, but not for \question.
    – fborchers
    Nov 20, 2023 at 0:29
  • You would need two separate \qformats for that. Doable, but not trivial. Nov 20, 2023 at 3:48

You must log in to answer this question.

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