cgnieder / xsim

eXercise Sheets IMproved
65 stars 20 forks source link

Pre-hook is not applicable to exercise environment #121

Open m-haug opened 8 months ago

m-haug commented 8 months ago

I'm trying to do something similar to https://texwelt.de/fragen/22255/xsim-printcollection-jede-aufgabe-mit-losung-auf-einer-neuen-seite. I'm trying to start some exercises on a new page. However, when I set the exercise hook on the exercise environment itself, it seems that the hook is not applied. Setting the hook globally does work. Setting the hook on the solution environment also works.

Is this expected behaviour that I missed in the docs? Or what am I doing wrong?

I greatly appreciate any help.

muzimuzhi commented 8 months ago

It seems the support for hook options pre-hook, begin-hook, end-hook, and post-hook are incomplete.

For exercise environment, it currently treats all env options as properties. But hook options are not properties, thus they are either ignored (in v0.21 2022/02/12) or throw errors

! Package xsim Error: You tried to set the property `pre-hook' on line <n>.
(xsim)                This property does not exist. Check for a typo or 
(xsim)                define the property yourself.

using the current dev (99d8b8034e0a6bf69c28ea11af662d2f00edec03, the change in \__xsim_set_property:nnnn).

For solution environment, it currently process env options through normal key-value functions. This may seem to work if solution envs are printed immediately, but if they're printed by \printsolutions, per env hook settings are still lost.

\documentclass{article}
\usepackage{xsim}

\xsimsetup{
%  solution/print=true
}

\xsimsetup{
  exercise/pre-hook   = {\noindent (pre-exer)},
  exercise/begin-hook = {(begin-exer)},
  exercise/end-hook   = {(end-exer)},
  exercise/post-hook  = {\noindent (post-exer)},
  solution/pre-hook   = {\noindent (pre-solu)},
  solution/begin-hook = {(begin-solu)},
  solution/end-hook   = {(end-solu)},
  solution/post-hook  = {\noindent (post-solu)}
}

\begin{document}

\begin{exercise}[
  pre-hook={\noindent (\textbf{special-pre-exer})},
  begin-hook=(\textbf{special-begin-exer})%
]
  exercise 1
\end{exercise}

\begin{solution}[
  pre-hook={\noindent (\textbf{special-pre-solu})},
  begin-hook=(\textbf{special-begin-solu})
]
  solution 1
\end{solution}

\begin{exercise}
  exercise 1
\end{exercise}

\begin{solution}
  solution 2
\end{solution}

\printsolutions

\end{document}

Using xsim v0.21,

solution/print=true solution/print=false
image image