cgnieder/xsim

global option print-solutions

MichaelHuck opened this issue · 1 comments

I work with global options. My setup:

xsimsetup{
print-solutions/headings=false,
print-solutions/chapter=true
}

print-solutions/headings=false works fine
print-solutions/chapter=true does not work
I use
\printsolutions[chapter=true]
localy to print only the current chapter solutions.
My understanding of the manual is that you can set all options globally (xsimsetup) or locally.
Can you clarify why there is a difference between using these settings?
I can't see any difference in the manual.

Thanks.

You're right, the setup with \xsimsetup{ print-solutions/chapter = true } does not work. The reason is that it sets \l_xsim_printsolutions_chapter_int to the current value of the chapter counter. In the preamble this is 0

I agree that this is not obvious from the manual.

A possible solution is to add this to the \@chapter command:

\documentclass{report}
\usepackage{xsim}
\xsimsetup{print-solutions/chapter=true}

\ExplSyntaxOn

\AddToHook {cmd/@chapter/after} {
  \int_set:Nn \l_xsim_printsolutions_chapter_int { \value{chapter} }
}

\ExplSyntaxOff

\begin{document}

\chapter{A}
\begin{exercise}
  a
\end{exercise}
\begin{solution}
  a
\end{solution}

\printsolutions

\chapter{B}
\begin{exercise}
  b
\end{exercise}
\begin{solution}
  b
\end{solution}

\printsolutions

\end{document}