Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-hook is not applicable to exercise environment #121

Open
m-haug opened this issue Nov 16, 2023 · 1 comment
Open

Pre-hook is not applicable to exercise environment #121

m-haug opened this issue Nov 16, 2023 · 1 comment

Comments

@m-haug
Copy link

m-haug commented Nov 16, 2023

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.

@m-haug m-haug changed the title Pre-hook is not applicable to exercises Pre-hook is not applicable to exercise environment Nov 16, 2023
@muzimuzhi
Copy link

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 (99d8b80, 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants