2

I would like to be able to call \CurrentQuestionID within a question, specifically in a \IfQuestionPropertyTF statement, but it seems that \CurrentQuestionID is not expanding when called within a command. See 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}

output

2

You can redefine the macros to accept also a control sequence like \CurrentQuestionID and expand it before starting their work.

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.