XSIM:问题计数器不打印

XSIM:问题计数器不打印

以下模板可以与 一起使用xsim v.0.19,但不再与 一起使用v.0.20。问题似乎是\GetExerciseProperty{counter}无法检索计数器。

包装信息:

Package: xsim 2021/02/03 v0.20c eXercise Sheets IMproved
pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2022/dev)

模板损坏:

\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{filecontents} % for self-contained example
\begin{filecontents}{QuestionBank.tex}
\begin{mc}[ID=Q001]
First Question: Select one of the following solutions:
\begin{enumerate}
\item A
\item B
\end{enumerate}
\end{mc}
\begin{hint}
Solution to First Question
\end{hint}
\begin{mc}[ID=Q002]
Second Question: Select one of the following solutions:
\begin{enumerate}
\item C
\item D
\end{enumerate}
\end{mc}
\begin{hint}
Solution to Second Question
\end{hint}
\end{filecontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[verbose,clear-aux]{xsim}
\usepackage[most]{tcolorbox}

\newcommand*\includeQuestion[1]{%
\XSIMexpandcode{\printexercise{mc}{\GetExerciseIdForProperty{ID}{#1}}}%
}

\newcommand*\includeSolution[1]{%
\XSIMexpandcode{\printsolution{mc}{\GetExerciseIdForProperty{ID}{#1}}}%
}

\DeclareExerciseEnvironmentTemplate{mctemplate}
{%
    \tcolorbox[breakable,
        drop shadow,
        beforeafter skip=1\baselineskip,
        fonttitle=\bfseries,
        fontupper=\normalsize,
        valign=top,
        colframe=\IfInsideSolutionF{green!20!white}%
                 \IfInsideSolutionT{blue!20!white},
        colback=\IfInsideSolutionF{green!3!white}%
                \IfInsideSolutionT{blue!3!white},
        coltext=black,
        coltitle=black,
        boxrule=1pt,
        width=\linewidth,
        left=2mm,
        title=\IfInsideSolutionT{%
          \XSIMmixedcase{\XSIMtranslate{solution}}~to~}%
          \XSIMmixedcase{\XSIMtranslate{question}}~\GetExerciseProperty{counter}%
    ]%
}{\endtcolorbox}

\DeclareExerciseType{mc}{
    exercise-env = mc,
    solution-env = hint,
    exercise-name = question,% used with headings=true
    solution-name = answer,% used with headings=true
    exercise-template = mctemplate,
    solution-template = mctemplate,
    counter = mc
}

\DeclareExerciseCollection{myCollection}


\begin{document}

\collectexercises{myCollection}
\input{QuestionBank.tex}
\collectexercisesstop{myCollection}

\section*{Multiple Choice Questions with XSIM}
Total number of questions: \numberofmcs 

\noindent
The counter above should be 2, not 0.

\noindent
The following should print \textbf{Question 1} and \textbf{Solution to Question 1}. And likewise \textbf{Question 2} and \textbf{Solution to Question 2}.

\includeQuestion{Q001}
\includeSolution{Q001}

\includeQuestion{Q002}
\includeSolution{Q002}

\end{document}

在此处输入图片描述

答案1

放在\collectexercisesstop{myCollection}最后,在最后一个问题/解决方案之后。

A

使用 v0.20c 2021/02/03

    \documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage{filecontents} %  not needed anymore
\begin{filecontents}{QuestionBank.tex}
    \begin{mc}[ID=Q001]
        First Question: Select one of the following solutions:
        \begin{enumerate}
            \item A
            \item B
        \end{enumerate}
    \end{mc}
    \begin{hint}
        Solution to First Question
    \end{hint}
    \begin{mc}[ID=Q002]
        Second Question: Select one of the following solutions:
        \begin{enumerate}
            \item C
            \item D
        \end{enumerate}
    \end{mc}
    \begin{hint}
        Solution to Second Question
    \end{hint}
\end{filecontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    

\usepackage[verbose,clear-aux]{xsim}

\usepackage[most]{tcolorbox}

\newcommand*\includeQuestion[1]{%
    \XSIMexpandcode{\printexercise{mc}{\GetExerciseIdForProperty{ID}{#1}}}%
}

\newcommand*\includeSolution[1]{%
    \XSIMexpandcode{\printsolution{mc}{\GetExerciseIdForProperty{ID}{#1}}}%
}

\DeclareExerciseEnvironmentTemplate{mctemplate}
{%
    \tcolorbox[breakable,
    drop shadow,
    beforeafter skip=1\baselineskip,
    fonttitle=\bfseries,
    fontupper=\normalsize,
    valign=top,
    colframe=\IfInsideSolutionF{green!20!white}%
    \IfInsideSolutionT{blue!20!white},
    colback=\IfInsideSolutionF{green!3!white}%
    \IfInsideSolutionT{blue!3!white},
    coltext=black,
    coltitle=black,
    boxrule=1pt,
    width=\linewidth,
    left=2mm,
    title=\IfInsideSolutionT{%
    \XSIMmixedcase{\XSIMtranslate{solution}}~to~}%
    \XSIMmixedcase{\XSIMtranslate{question}}~\GetExerciseProperty{counter}%
    ]%
}{\endtcolorbox}

\DeclareExerciseType{mc}{
    exercise-env = mc,
    solution-env = hint,
    exercise-name = question,% used with headings=true
    solution-name = answer,% used with headings=true
    exercise-template = mctemplate,
    solution-template = mctemplate,
    counter = mc
}

\DeclareExerciseCollection{myCollection}    

\begin{document}
    \collectexercises{myCollection} % here <<<<<<<<<<<<<<<<<<<<<<<<
    \input{QuestionBank.tex}        
    
    \section*{Multiple Choice Questions with XSIM}
    Total number of questions: \numberofmcs 
    
    \noindent
    The counter above should be 2, not 0.
    
    \noindent
    The following should print \textbf{Question 1} and \textbf{Solution to Question 1}. And likewise \textbf{Question 2} and \textbf{Solution to Question 2}.
    
    \includeQuestion{Q001}
    \includeSolution{Q001}
    
    \includeQuestion{Q002}
    \includeSolution{Q002}
    \collectexercisesstop{myCollection} % added <<<<<<<<<<<<<<<<<<<<<<<
    
\end{document}

相关内容