1

I've just read this post linked in the xsim_manual on p.71 example 35 and i've some troubles to adapt it to my goal.

I want to add an environment resolution for each exercises of my database. This environment will contain the complete solution of an exercise. With equations, pictures, tikz schemes,... In the post linked, the goal is to write a shortsolution environment and to use the normal command for the resolution. But i prefer to keep the regular solution environment for short solutions because it allows me to define some options inside of my documents and it's this environment that i'll use more often.

Unfortunately, i'm facing an issue when i add some long stuff inside the resolution environment. In particular, double vertical line | around a vector (for a norm) create the following error : ! File ended while scanning use of \__tl_rescan:NNw.

Can you help me to fix this ? My attempts are :

  • Using double vertical lines | around my vector ;
  • Let an exercise be free of resolution without problem. I can't write a complete computer resolution for each exercises i've computed now.
  • Keep the regular solution environment as it is.

The code below is a MWE :

\documentclass{article}
\usepackage{amsmath}
\usepackage{xsim}
\usepackage{environ}

%%Adapted from https://texwelt.de/fragen/23968/xsim-ubung-losung-zusatzlich-kurzlosung
\DeclareExerciseProperty{resolution}

% we'll use a description list for the resolutions:
\newcommand\printresolutions{%
    \begin{description}
        \ForEachUsedExerciseByType{%
            \def\ExerciseType{##1}%
            \def\ExerciseID{##2}%
            \GetExercisePropertyT{resolution}
            {%
                \item[Résolution ##3]
                ####1%
            }%
        }%
    \end{description}
}

\NewEnviron{resolution}{\SetExpandedExerciseProperty{resolution}{\expandonce{\BODY}}}


\begin{document}
    \section{My section}
    \begin{exercise}
        Foo exercise with no resolution
    \end{exercise}
    \begin{solution}
        Foo solution with no resolution.
    \end{solution}

    \begin{exercise}
        Bar exercise with a resolution
    \end{exercise}
    \begin{resolution}
        This is the resolution of my \textbf{bar} exercise.

        \begin{equation*}
            ||\vec{F}|| %%here is the trouble
        \end{equation*}
    \end{resolution}
    \begin{solution}
        This is a solution for bar
    \end{solution}

    \printsolutions

    \section{Resolutions}
    \printresolutions
\end{document}
  • Your MWE compiles fine for me (up to date TeX Live). (As an aside: you don't need environ – you can also use \NewDocumentEnvironment{resolution}{+b}{\SetExerciseProperty{resolution}{#1}}{}) – cgnieder Jan 29 at 20:29
  • @cgnieder yes, it missed the second vertical line | where i wrote the comment. I've just updated. – Piroooh Jan 29 at 21:59
1

As you've discovered || makes problems. The reason is that xsim uses || as a delimiter in its property lists. If you open the .xsim file you will see lines like

\XSIM{id}{exercise-1=={1}||exercise-2=={2}}

In your case this makes problems because your resolutions are used as entries in such a list:

\XSIM{resolution}{exercise-2=={This is the resolution of my \textbf {bar} exercise. \par \begin {equation*} ||\vec {F}|| \end {equation*}}}

(you might notice that this for example will also prevent usage of verbatim material in your resolutions).

There are two possible solutions:

  1. Use a different delimiter, something that isn't likely to be used in normal text, maybe something like this:

    \xsimsetup{split-aux-lists = |&|}
    

    The xsim manual actually documents this but is outdated. It documents a single | as list delimiter (which it was in early versions).

  2. I'd prefer a different solution and avoid the problem altogether: use \lVert\vec{F}\rVert. Or – even better – load the mathtools package and do something like this:

    \usepackage{mathtools}
    \DeclarePairedDelimiter\norm{\lVert}{\rVert}
    

    You can than use the much more semantic \norm{\vec{F}}.

  • Thank you for the highlight : solution and origin of the problem ! I find ||\vec{F}|| more readable but i just compare the output and think i'll change for a macro using \norm{\vec{F}} because the spaces between || is nicer. Problem solved for me :) ! – Piroooh Jan 31 at 7:56
  • An other question but do you think it's possible to create the new resolution environment such that i can make some calls like \printresolutions[chapter=2, section=3] to print the complete resolutions in a dedicated appendix chapter with separated section ? At the moment, it prints all resolutions of used exercises and i can't separate them by some headings/\clearpage or \section{Resolutions of chapter 2 section 3}. In short, make a second environment like solution with all dedicated options for \printsolutions. – Piroooh Jan 31 at 8:00
  • @Piroooh that's currently not really possible. I plan to add something in the future but I really can't tell when I will find the time to implement it… – cgnieder Feb 8 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.