Skip to content

Pre-hook is not applicable to exercise environment #121

Description

@m-haug

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.

Activity

  1. changed the title [-]Pre-hook is not applicable to exercises[/-] [+]Pre-hook is not applicable to exercise environment[/+] on Nov 16, 2023
  2. muzimuzhi commented on Nov 16, 2023

    @muzimuzhi

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions