cgnieder/xsim

exercise property "solution" does not work as expected

mschneiderwng opened this issue · 5 comments

In the following MWE, I would expect to see the solutions to both exercises, however, only the second is shown.
This uses xsim v0.21.

\documentclass[a4paper]{article}
\usepackage[use-aux]{xsim}
\xsimsetup{solution/print=true,exercise/print=false}
\begin{document}
\begin{exercise}[solution]
	algebra question 1
	\IfInsideSolutionT{Solution to algebra question 1}
\end{exercise}
\begin{exercise}[]
	calculus question 2
\end{exercise}
\begin{solution}[]
	Solution to calculus question 2
\end{solution}
\end{document}

Also \printsolutions does not show exercises with the property solution. This worked before upgrading to xsim v0.21.

Oh bugger. I don't know how this could happen :(

This is a bug in

\prg_new_conditional:Npnn \xsim_if_exchange:nnn #1#2#3 {T,F,TF}
  {
    \str_if_eq:nnTF {#3} {solution} % <<< this should be `exercise'
      {
        \xsim_if_boolean_property:nnnTF {#1} {#2} {solution}
          { \prg_return_true: }
          { \prg_return_false: }
      }
      { \prg_return_false: }
  }

Adding

\ExplSyntaxOn
\prg_set_conditional:Npnn \xsim_if_exchange:nnn #1#2#3 {T,F,TF}
  {
    \str_if_eq:nnTF {#3} {exercise}
      {
        \xsim_if_boolean_property:nnnTF {#1} {#2} {solution}
          { \prg_return_true: }
          { \prg_return_false: }
      }
      { \prg_return_false: }
  }
\ExplSyntaxOff

to your preamble should restore the behaviour till the next update is released.

Unrelated to the bug I'm not sure

\begin{exercise}[solution]
	algebra question 1
	\IfInsideSolutionT{Solution to algebra question 1}
\end{exercise}

should print anything with exercise/print=false.
I'd rather use

\begin{exercise}[solution=true,ID=one]
  algebra question 1
  \IfInsideSolutionT{Solution to algebra question 1}
\end{exercise}
\printsolution{exercise}{one}

Yes, I just tested commit 99d8b80 and it fixed the issue. Thanks a lot!

Is there a place for discussions? I understood, that (conceptually) the solution property creates a solution environment by "copying" the exercise. Hence, I expected that exercise/print=false does not print the exercise, but the copied solution.

I am using the solution property a lot and would like to print a sheet with solutions only. Using IDs and then iterate over them for \printsolution is okay, but I am not very happy with this.

We can discuss here.

I can imagine an option that enables the behaviour you want – maybe even as a default setting.

Maybe

\begin{exercise}[solution]
   xxx
\end{exercise}

should be the same as

\begin{exercise}
  xxx
\end{exercise}
\begin{solution}
  xxx
\end{solution}

at least in regard to global options...

Great! That is exactly the behavior I expected.