我希望能够在问题中调用 \CurrentQuestionID,特别是在 \IfQuestionPropertyTF 语句中,但似乎 \CurrentQuestionID 在命令中调用时不会扩展。请参阅 mwe:
\documentclass{article}
\usepackage{exsheets}
\DeclareQuestionProperty{notes}
\DebugExSheets{true}
\usepackage{parskip}
\begin{document}
\begin{question}
\SetQuestionProperties{notes={blah}}
\textbackslash\texttt{CurrentQuestionID} is \CurrentQuestionID.
Calling \textbackslash\texttt{QuestionNumber} with input ``1'' works:
Question number is \QuestionNumber{1}
Calling \textbackslash\texttt{QuestionNumber} with input \textbackslash\texttt{CurrentQuestionID} doesn't work:
Question number is \QuestionNumber{\CurrentQuestionID}
Calling \textbackslash\texttt{IfQuestionPropertyTF} with input ``1'' works:
\IfQuestionPropertyTF{notes}{1}{true}{false}
Calling \textbackslash\texttt{IfQuestionPropertyTF} with input \textbackslash\texttt{CurrentQuestionID} doesn't work:
\IfQuestionPropertyTF{notes}{\CurrentQuestionID}{true}{false}
\end{question}
\end{document}
答案1
您可以重新定义宏以接受类似的控制序列\CurrentQuestionID
并在开始工作之前对其进行扩展。
\documentclass{article}
\usepackage{exsheets}
\DeclareQuestionProperty{notes}
\DebugExSheets{true}
\ExplSyntaxOn
\RenewDocumentCommand{\QuestionNumber}{sm}
{
\IfBooleanTF{#1}
{ \exsheets_question_number:o {#2} }
{ \exsheets_question_number:n {#2} }
}
\cs_generate_variant:Nn \exsheets_question_number:n { o }
\RenewDocumentCommand{\IfQuestionPropertyTF}{smmmm}
{
\IfBooleanTF{#1}
{ \exsheets_if_question_property:noTF { #2 } { #3 } { #4 } { #5 } }
{ \exsheets_if_question_property:nnTF { #2 } { #3 } { #4 } { #5 } }
}
\cs_generate_variant:Nn \exsheets_if_question_property:nnTF { no }
\ExplSyntaxOff
\begin{document}
\begin{question}
\SetQuestionProperties{notes={blah}}
\texttt{\string\CurrentQuestionID} is \CurrentQuestionID.
Calling \texttt{\string\QuestionNumber} with input ``1'' works:
Question number is \QuestionNumber{1}
Calling \texttt{\string\QuestionNumber*} with input \texttt{\string\CurrentQuestionID} works as well:
Question number is \QuestionNumber*{\CurrentQuestionID}
Calling \texttt{\string\IfQuestionPropertyTF} with input ``1'' works:
\IfQuestionPropertyTF{notes}{1}{true}{false}
Calling \texttt{\string\IfQuestionPropertyTF*} with input \texttt{\string\CurrentQuestionID} works as well:
\IfQuestionPropertyTF*{notes}{\CurrentQuestionID}{true}{false}
\end{question}
\end{document}