作为 randomizechoices 参数传递的宏不起作用

作为 randomizechoices 参数传递的宏不起作用

这是一部大型作品的高度简化版本。

请参阅最后给出的 MWE。在第一种情况下,当宏直接作为内部选项提供时,randomizechoices它可以正常工作。但是,当定义另一个宏时,其中randomizechoices环境位于定义内部,并且宏参数作为选项传递,它会产生错误消息,

Package exam-randomizechoices Warning: You need exactly one \CorrectChoice, I f
ound 0 in question 1 on input line 40.

! Undefined control sequence.
\erc@answer ->\@empty \CorrectChoice 
                                     \A  
l.38 \mcq{\A}{\B}{\C}{\D}

这是 MWE。

\documentclass{exam}

\usepackage{exam-randomizechoices}
\setrandomizerseed{2021}

\def\A{a}
\def\B{b}
\def\C{c}
\def\D{d}

% Define a macro for MCQ questions
\def\mcq#1#2#3#4{%
  Which one in this case?
  
  \begin{randomizechoices}
    \CorrectChoice#1
    \choice#2
    \choice#3
    \choice#4
  \end{randomizechoices}
}

\begin{document}

% Direct use of macro as choices
\begin{questions}
  \question Which one?

  \begin{randomizechoices}
    \CorrectChoice \A
    \choice \B
    \choice \C
    \choice \D
  \end{randomizechoices}
\end{questions}

% Choices are passed as macro arguments. This does not work.
\mcq{\A}{\B}{\C}{\D}

\end{document}

答案1

不管你信不信,这都是一个%最终的问题。

我还添加了\question的定义\mcq

\documentclass{exam}

\usepackage{exam-randomizechoices}
\setrandomizerseed{2021}

\def\A{a}
\def\B{b}
\def\C{c}
\def\D{d}

% Define a macro for MCQ questions
\newcommand{\mcq}[4]{%
  \question Which one in this case?
  
  \begin{randomizechoices}
    \CorrectChoice#1% <---
    \choice#2% <---
    \choice#3% <---
    \choice#4% <---
  \end{randomizechoices}
}

\begin{document}

% Direct use of macro as choices
\begin{questions}
  \question Which one?

  \begin{randomizechoices}
    \CorrectChoice \A
    \choice \B
    \choice \C
    \choice \D
  \end{randomizechoices}

\mcq{\A}{\B}{\C}{\D}
\end{questions}

\end{document}

在此处输入图片描述

相关内容