3

The mcexam package has a 'fixlast' option for mcanswerslist, allowing the last option (e.g. 'none of the above') to be fixed while the others are randomised.

I would like a 'fixlasttwo' option so that I can specify 'all of the above' followed by 'none of the above'.

Here is an MWE showing the fixlasttwo option I'd like, and the existing fixlast option:

\documentclass{article}

\usepackage[output=exam
  ,numberofversions=1
  ,version=1
  ,seed=1
  ,randomizequestions=true
  ,randomizeanswers=true
  ,writeRfile=false
]{mcexam}

\begin{document}

\begin{mcquestions}

\question Is this going to be on the exam?
\begin{mcanswerslist}[fixlasttwo] % desired option
  \answer Russell's antinomy
  \answer Gödel's numbering
  \answer Borges' library
  \answer[correct] none of the above
  \answer all of the above
\end{mcanswerslist}

\begin{mcanswerslist}[fixlast] % existing option
  \answer Russell's antinomy
  \answer Gödel's numbering
  \answer Borges' library
  \answer[correct] none of the above
  \answer all of the above
\end{mcanswerslist}

\end{mcquestions}

\end{document}
  • 1
    Could you please make a small but complete example document using mcexam with randomization, with one question in it for which you want the last two options fixed? That would make it easier to start working on a solution for your question without spending time on such preparatory tasks. You can add code to your question by clicking the edit button below your post. – Marijn Nov 01 '19 at 16:27

1 Answers1

3

In the source of mcexam the fixlast option is implemented by defining the number of permutable answers as the total number of answers minus one, and then selecting permutation pairs randomly between 1 and the number of permutable answers. Therefore a quick solution is to define the number of permutable answers as the total number of answers minus two.

To add a bit of flexibility a macro \fixn can be defined to store the number of answers that need to be fixed and inserting that macro instead of the literal number 1 in the source code of the fixlast option. Modifying the source code can be done on the fly using the etoolbox package (which is already loaded by mcexam) which provides the macro \patchcmd, that has five arguments: the command to be patched, the specific code within that command that needs to be modified, the replacement code, and two arguments that are executed when the patch is successful or not, respectively.

MWE:

\documentclass{article}

\usepackage[output=exam
  ,numberofversions=1
  ,version=1
  ,randomizequestions=false
  ,randomizeanswers=true
  ,seed=10
  ,writeRfile=false
]{mcexam}
\makeatletter
\patchcmd{\mc@randomizeAnswers@fixlast}%
{\numdef\@numberofpermuteanswers{\csuse{mc@totalNumberOfAnswersQ\q}-1}}%
{\numdef\@numberofpermuteanswers{\csuse{mc@totalNumberOfAnswersQ\q}-\fixn}}%
{\typeout{patch ok}}{\typeout{patch failed}}
\makeatother
\begin{document}

\begin{mcquestions}

\question Is this going to be on the exam?
\gdef\fixn{2}
\begin{mcanswerslist}[fixlast] % existing option
  \answer Russell's antinomy
  \answer G\"odel's numbering
  \answer Borges' library
  \answer[correct] none of the above
  \answer all of the above
\end{mcanswerslist}

\end{mcquestions}

\end{document}

Result:

enter image description here

The \fixn definition can be changed later, if for example for the next question you want only the last answer fixed then you should put \gdef\fixn{1} before the answers and use fixlast as before.

Alternatively a new option fixlasttwo can be implemented (as asked by the OP) or a more general fixlastn option, but that includes patching or adding a lot more code so this might be an acceptable solution.

Marijn
  • 37,699