cgnieder/xsim

\GetExercideBody{solution} does not work as expected

mw88-personal opened this issue · 4 comments

I try to use \GetExerciseBody{solution} inside an exercise environment. However, it only outputs the body of the exercise. See the following MWE attached:

\documentclass[]{article}
\usepackage{xsim}
\usepackage{framed}

% XSIM Settings
\xsimsetup{
    solution/print=true
}


\SetExerciseParameters{exercise}{
    exercise-name = \XSIMtranslate{exercise},
    exercise-template = exercise,
    solution-template = solution,
    counter = section,
}



\DeclareExerciseEnvironmentTemplate{solution}{%
    \subsection{Solution}
    \begin{framed}
}{
    \end{framed}

    \subsubsection{\textbackslash GetExerciseBody\{solution\} inside solution template:}
    \begin{framed}
    \GetExerciseBody{solution}
\end{framed}
    \subsubsection{\textbackslash GetExerciseBody\{exercise\} inside solution template:}
    \begin{framed}
    \GetExerciseBody{exercise}
\end{framed}
}

\DeclareExerciseEnvironmentTemplate{exercise}{%
    \subsection{Exercise}
    \begin{framed}
}{
    \end{framed}

    \subsubsection{\textbackslash GetExerciseBody\{solution\} inside exercise template:}
    \begin{framed}
    \GetExerciseBody{solution}
\end{framed}
    \subsubsection{\textbackslash GetExerciseBody\{exercise\} inside exercise template:}
    \begin{framed}
    \GetExerciseBody{exercise}
\end{framed}
}





\begin{document}
\begin{exercise}%[points=2]
    This is exercise 1.
\end{exercise}


\begin{solution}
    This is solution 1.\\
    It is long\\
    and \\
    it needs to be\\
    to check inconsistencies.
\end{solution}

\end{document}

mwe.pdf

Instead, I expect to be able to access both, exercise and solution, from inside both templates, i.e. the box under 1.1.1 should be equal to 1.2.1.
This seems like a bug to me.

I'm using texlive, lualatex and xsim 2021/02/03 v0.20c

It seems xsim v0.20 uses a print immediately new scheme, which is not the case with v0.19b (you can test with v0.19b on overleaf.com, texlive 2020).

For a workaround, collecting then printing all the material works. The required changes are:

  • Change \xsimsetup{solution/print=true} to \xsimsetup{collect=true} and
  • Add \printcollection[print=both]{all exercises} just before \end{document}.

If your exercise/solution body ever contains verbatim material, you'll need the use-files package option.

At first glance, your proposed workaround seems to work in my MWE. I'll try and implement it in my lecture notes to see if the first impression holds. Thank you.

However, it still is (for me as a beginner with xsim) not intuitive to use your workaround, so I believe this should still be considered a bug

[...] so I believe this should still be considered a bug

I think so. Getting exercise body from \getExerciseBody{solution} used in an environment template without any warnings/errors is clearly a bug.

This is an error in \__xsim_save_environment_body:nnnn and is now fixed.