[Tex/LaTex] Manual exercise question numbering

countersexercisesnumbering

I am using exercise package to list exercises/questions.
I am defining exercise list like this:

\begin{ExerciseList}
  \Exercise{Exercise title}

  \ExeText
  Some exercise introduction
  \Question{First question}
  \Question{Second question}
  \Question{Third question}
\end{ExerciseList}

In the output questions are numbered like this:

1. First question

However my desire is to have following output:

(a) First question

Actually it would be best if I could manually define list letter for question as I anticipate some gaps in numbering later. For example \Question{e}{Some question}.
From the package source I see that questions are translated to list items:

\def\@QuestionHeader{\item[{\makebox[0cm][r]{\begingroup\@getQuestionInfo%
\QuestionHeaderDifficulty\QuestionNB\endgroup}}]%
\begingroup\@getQuestionInfo\QuestionHeaderTitle\endgroup\ignorespaces}

However I am unsure on how to redefine the macro in order to accomplish my goal.. Any ideas or hints?

Best Answer

Good on you to look in the source code. Good on the package author to use good macro names that describe the intent. I guessed from your posted snippet that \QuestionNB might be the macro that typeset the question number. Searching the source file for that string found me:

% Presentation of Questions
%    \begin{macrocode}
\newcommand{\QuestionNB}{\arabic{Question}.\ }

Excellent! We know \QuestionNB sets the arabic representation of the value the Question counter, with period and space. So all you have to do is insert

\renewcommand{\QuestionNB}{(\alph{Question})\ }

into the preamble after \usepackage{exercise} and you'll get what you want.

\documentclass{article}
\usepackage{exercise}
\renewcommand{\QuestionNB}{(\alph{Question})\ }
\renewcommand{\theQuestion}{(\alph{Question})}
\begin{document}
\begin{ExerciseList}
  \Exercise{Exercise title}

  \ExeText
  Some exercise introduction
  \Question{First question}
  \Question{Second question}\label{q2}
  \Question{Third question (\textit{Hint}: use your answer to question~\ref{q2})}
\end{ExerciseList}
\end{document}

(View this in CoCalc)

sample code output

The command \theQuestion is for setting the counter value in \references. So the line renewing it will take care of the situation described by Peutsch in the comments.

Related Question