0

The following template worked with xsim v.0.19, but no longer works with v.0.20. The problem seems to be that \GetExerciseProperty{counter} is unable to retrieve the counter.

Package info:

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

Broken Template:

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

enter image description here

4
  • I just compiled the document online with "overleaf" and it compiled fine. However, overleaf uses xsim 2020/04/04 v0.19b eXercise Sheets IMproved with Version 3.14159265-2.6-1.40.21 (TeX Live 2020) whereas I'm using xsim 2021/02/03 v0.20c eXercise Sheets IMproved with Version 3.141592653-2.6-1.40.23 (TeX Live 2022/dev) (preloaded format=pdflatex 2021.9.28). Is it a bug/feature with the latest version of xsim?
    – PatrickT
    Sep 29, 2021 at 11:31
  • I have now raised an issue on the github repo. I'm not sure if I should delete my question here. It does look like the problem comes after a recent update of xsim. I'm hoping to find a workaround within a week or so, so I'm leaving the question open here just in case someone can suggest a workaround. Thanks! github.com/cgnieder/xsim/issues/91
    – PatrickT
    Sep 30, 2021 at 5:18
  • 1
    In my opinion it is OK to leave the question here to signal to other users that a problem exists and that you have filed an issue with the maintainer of the package. Would be good that when you see that the problem is fixed to make an appropriate comment / answer here as well.
    – albert
    Oct 1, 2021 at 11:35
  • Good point albert. I'm monitoring this space closely as I need to fix the problem soon. If an xsim solution is not forthcoming, I will create my own counter, which should not be too hard. :-)
    – PatrickT
    Oct 1, 2021 at 12:42

1 Answer 1

1

Put \collectexercisesstop{myCollection} at the end, after the last question/solution.

a

Using 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}
1
  • Thank you Simon! Lifesaver. How were you able to figure it out? Was there something in the log file that gave it away?
    – PatrickT
    Oct 2, 2021 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .