1

I'm using xsim package to manage exercises in my lessons but I can't find a good way to select exercises by using tags.

In particular, when i write the following code (example1), each exercise produces three exercises body file. And for a year, I call the exercises.tex files several times, producing more and more files and guess, increasing the compiling time exponentially. (record with 15min for a 50 pages document... So I'm turning crazy when I've to compile a second time for cross-referencing.)

To avoid those multiple files, I've used collection but it's not as flexible as tag system. I've to manage many collection declarations for each tag and mixed calling is impossible. See example 2.

To achieve what i'm looking for :

  1. Do not produce multiple files each time I call part of my exercises.tex.
  2. Able to use flexibility of tags to choose which exercise to print.

I thought to declare the same amount of collection than in example 2 but use the tag to open collecting exercises when exercise environment appears. So that i don't have to open/close exercises manually for each exercise and i can call it by using keyvalues with \printcollection to reproduce tag system. (example 3)

However, the main.xsim file is clear, no exercise is added in the collection...

So I've two (almost related questions) :

  1. Is there a way to use tags to filter exercises other than \include{exercises.tex} each time and reproduce whole exercices ?
  2. How can i open the collecting exercises at the very begin exercise environment so it can be usefull to select exercises by collection ?

I read and re-read again the manual and I have tried to parse the xsim.collection.tex and xsim.exercises.tex to find a solution but I still have some trouble to understand expl3 syntax and I can't find a good way. Thank you for any help !

Example 1

\documentclass{report}
\usepackage{xsim}

%%Declare collection
%\DeclareExerciseCollection{Collection1}    
%\DeclareExerciseCollection{Collection2}

%%Declare tags
\DeclareExerciseTagging{Subject}
\DeclareExerciseTagging{Difficulty}


\begin{filecontents*}{exercises.tex}
%   \collectexercises{Collection1}
    \begin{exercise}[Subject=Philosophy, Difficulty=1]
        My first exercise, part of collection 1
    \end{exercise}
%   \collectexercisesstop{Collection1}

%   \collectexercises{Collection2}
    \begin{exercise}[Subject=Biology, Difficulty=2]
        My second exercise, part of collection 2
    \end{exercise}
%   \collectexercisesstop{Collection2}

%   \collectexercises{Collection1}
    \begin{exercise}[Subject=Philosophy, Difficulty=1]
        My third exercise, also part of collection 1
    \end{exercise}
%   \collectexercisesstop{Collection1}
\end{filecontents*}

\begin{document}
    Here for three exercises, nine files are created.
    \input{exercises}
    \hrule
    \section{Philosophy}
    \xsimsetup{Subject=Philosophy}
    \input{exercises}

    \section{Biology}
    \xsimsetup{Subject=Biology}
    \input{exercises}
\end{document}

Example 2

\documentclass{report}
\usepackage{xsim}

%%Declare collection
\DeclareExerciseCollection{Collection1} 
\DeclareExerciseCollection{Collection2}
%%Required Collection to use certain filters :
\DeclareExerciseCollection{Philosophy}
\DeclareExerciseCollection{Philosophy_Difficulty1}
\DeclareExerciseCollection{Philosophy_Difficulty2}

\DeclareExerciseCollection{Biology}
\DeclareExerciseCollection{Biology_Difficulty1}
\DeclareExerciseCollection{Biology_Difficulty2}

%%Declare tags
\DeclareExerciseTagging{Subject}
\DeclareExerciseTagging{Difficulty}


\begin{filecontents*}{exercises.tex}
    \collectexercises{Collection1}
        \collectexercises{Philosophy}
            \collectexercises{Philosophy_Difficulty1}
                \begin{exercise}[Subject=Philosophy, Difficulty=1]
                    My first exercise, part of collection 1
                \end{exercise}
            \collectexercisesstop{Philosophy_Difficulty1}
        \collectexercisesstop{Philosophy}
    \collectexercisesstop{Collection1}

    \collectexercises{Collection2}
        \collectexercises{Biology}
            \collectexercises{Biology_Difficulty2}
                \begin{exercise}[Subject=Biology, Difficulty=2]
                    My second exercise, part of collection 2
                \end{exercise}
            \collectexercisesstop{Biology_Difficulty2}
        \collectexercisesstop{Biology}
    \collectexercisesstop{Collection2}

    \collectexercises{Collection1}
        \collectexercises{Philosophy}
            \collectexercises{Philosophy_Difficulty2}
                \begin{exercise}[Subject=Philosophy, Difficulty=2]
                    My third exercise, also part of collection 1
                \end{exercise}
            \collectexercisesstop{Philosophy_Difficulty2}
        \collectexercisesstop{Philosophy}
    \collectexercisesstop{Collection1}
\end{filecontents*}

\begin{document}
    Here only three files are created but i've to manage and declare many collections (open/close) to trigger all combinations of tags.
    \input{exercises}
    \hrule
    \section{Philosophy}
    \printcollection{Philosophy}

    \section{Biology}
    \printcollection{Biology}
\end{document}

Example 3 :

\documentclass{report}
\usepackage{xsim}

%%Declare collection
\DeclareExerciseCollection{Collection1} %%Here it has to contain all exercises with pre-hook    
\DeclareExerciseCollection{Collection2}

%%Declare tags
\DeclareExerciseTagging{Subject}
\DeclareExerciseTagging{Difficulty}

%% I want automatically add \collectexercises command (with corresponding tag, next goal) 
\xsimsetup{exercise/pre-hook=\collectexercises{Collection1},
            exercise/post-hook=\collectexercisesstop{Collection1}}
\begin{filecontents*}{exercises.tex}
%   \collectexercises{Collection1}
    \begin{exercise}[Subject=Philosophy, Difficulty=1]
        My first exercise, part of collection 1
    \end{exercise}
%   \collectexercisesstop{Collection1}

%   \collectexercises{Collection2}
    \begin{exercise}[Subject=Biology, Difficulty=2]
        My second exercise, part of collection 2
    \end{exercise}
%   \collectexercisesstop{Collection2}

%   \collectexercises{Collection1}
    \begin{exercise}[Subject=Philosophy, Difficulty=1]
        My third exercise, also part of collection 1
    \end{exercise}
%   \collectexercisesstop{Collection1}
\end{filecontents*}

\begin{document}
    Only exercises from the input appear.
    \input{exercises}
    \hrule
    \printcollection{Collection1}
\end{document}
Piroooh
  • 1,197
  • @cgnieder Thank you for your comment. You are right, it is related. Can I interact directly on this post ? (so this one could be closed) In fact, i'm already using the path=folder but it doesn't solve all the points. Files, hidden or not, are created. I've tested with no-files option but the situation is not better... You're talking about a next draft version to solve it. There is no other way ? Ifso, i'll stay tuned ! Does this next version be part of TexLive 2020 ? Thank you for your work anyway ! – Piroooh Mar 29 '20 at 10:44
  • 1
    What do you mean by “not better”? Do you mean with no-files the files are created nonetheless? That would be weird. If you mean it doesn't reduce compilation time then you're right of course, because that's not what the option is supposed to do. For a faster xsim you need version 0.19 (which was published to CTAN after the tex live 2019 freeze – it will only be in tex live 2020) – cgnieder Mar 29 '20 at 10:55
  • @cgnieder i mean, it doesn't reduce compilation time which is the most problem i want to tackle. In fact, the number of files is a problem because of multiplication call who forces to recompile each of them instead of by pass. I'll have a look to the version 0.19 with tex live 2020. Thanks for you help. – Piroooh Mar 30 '20 at 09:32
  • Please have a look here: https://github.com/cgnieder/xsim/issues/68 – cgnieder Apr 01 '20 at 17:26

0 Answers0