1

I want to have a file with exercises and at the end of the file, I want to print the exercises sorted by level (a tag i created with xsim).

Below what do not work, for obvious reason, \printcollection works with a collection, not with a tag, but I cannot figure out how to handle collections, without writing it for every exercise).

Connected question: is it possible to define the level by a number (eg. 1, 2 or 3) and print a the corresponding number of $\star$ in the exercise-header?

\documentclass{article}
\usepackage[no-files]{xsim}

\DeclareExerciseTagging{level}
\DeclareExerciseTagging{nom}

\DeclareExerciseEnvironmentTemplate{custom}
  {
    \par\bigskip
    \noindent\sffamily\textbf
      {%
        \XSIMmixedcase {\GetExerciseName}\nobreakspace
        \GetExerciseProperty{counter}%
        \IfExercisePropertySetT{level}
          { (\GetExerciseProperty{level}) }%
        \IfExercisePropertySetT{nom}
          { {\itshape\GetExerciseProperty{nom}} }%
      }\par\noindent%
  }
  {\par\medskip}

\DeclareExerciseType{exo}{
  exercise-env= exo ,
  solution-env = soln ,
  exercise-name = \XSIMtranslate{exercise} ,
  exercises-name = \XSIMtranslate{exercises} ,
  solution-name = \XSIMtranslate{solution} ,
  solutions-name = \XSIMtranslate{solutions} ,
  exercise-template = custom ,
  solution-template = custom , 
  exercise-heading = \subsection* ,
  solution-heading = \subsection*
}

\xsimsetup{
  level ={$\star$,$\star\star$, $\star\star\star$} ,
  solution/print=true,
  soln/print=true,
}

\begin{document}

Le cours...

\begin{exo}[nom=Suite de Syracuse]
  Exercice 1 - pas de niveau 
\end{exo}

Le cours...

\begin{exo}[level=$\star$, nom = Suite de Fibonacci]
  Exercice 2 - niveau 1
\end{exo}

Une remarque ....

\begin{exo}[level=$\star\star$]
  Exercice 3 - niveau 2
\end{exo}

\begin{exo}[level=$\star$]
  Exercice 4 - niveau 1
\end{exo}

Et on termine par quelque chose de plus difficile

\begin{exo}[level=$\star\star\star$]
  Exercice 5 - très dur - niveau 3
\end{exo}

Fin du cours.

\newpage
Feuille exercice

%\FeuilleExercices

Exercices simples
\printcollection{level=$\star$}

Exercices medians
\printcollection{level=$\star\star$}

Exercices complexes
\printcollection{level=$\star\star\star$}

\end{document}
1

Both is possible.

enter image description here

You can define a command to only print the exercises for a certain level like this:

\NewDocumentCommand\printlevel{m}{%
  \ForEachUsedExerciseByType{%
    \def\ExerciseType{##1}%
    \def\ExerciseID{##2}%
      \IfExercisePropertySetT{level}{%
        \ifnum\GetExerciseProperty{level}=#1
          \printexercise{exo}{##2}%
        \fi
      }%
  }%
}

And with expl3's \prg_replicate:nn { integer } { code } which places integer times code in the input stream you can easily output the number of \stars:

\documentclass{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[no-files]{xsim}

\ExplSyntaxOn
\newcommand*\replicate{\prg_replicate:nn}
\ExplSyntaxOff

\DeclareExerciseTagging{level}
\DeclareExerciseTagging{nom}

\DeclareExerciseEnvironmentTemplate{custom}
  {%
    \par\bigskip
    \noindent\sffamily\textbf
      {%
        \XSIMmixedcase{\GetExerciseName}\nobreakspace
        \GetExerciseProperty{counter}%
        \IfExercisePropertySetT{level}
          { ($\replicate{\GetExerciseProperty{level}}{\star}$) }%
        \IfExercisePropertySetT{nom}
          { {\itshape\GetExerciseProperty{nom}} }%
      }\par\noindent
  }
  {\par\medskip}

\DeclareExerciseType{exo}{
  exercise-env= exo ,
  solution-env = soln ,
  exercise-name = \XSIMtranslate{exercise} ,
  exercises-name = \XSIMtranslate{exercises} ,
  solution-name = \XSIMtranslate{solution} ,
  solutions-name = \XSIMtranslate{solutions} ,
  exercise-template = custom ,
  solution-template = custom , 
  exercise-heading = \subsection* ,
  solution-heading = \subsection*
}

\NewDocumentCommand\printlevel{m}{%
  \ForEachUsedExerciseByType{%
    \def\ExerciseType{##1}%
    \def\ExerciseID{##2}%
      \IfExercisePropertySetT{level}{%
        \ifnum\GetExerciseProperty{level}=#1
          \printexercise{exo}{##2}%
        \fi
      }%
  }%
}

\xsimsetup{
  level ={1,2,3} ,
  % level/ignore-untagged = false,
  % soln/print=true,
}

\begin{document}

Le cours...

\begin{exo}[nom=Suite de Syracuse]
  Exercice 1 - pas de niveau 
\end{exo}

Le cours...

\begin{exo}[level=1, nom = Suite de Fibonacci]
  Exercice 2 - niveau 1
\end{exo}

Une remarque ....

\begin{exo}[level=2]
  Exercice 3 - niveau 2
\end{exo}

\begin{exo}[level=1]
  Exercice 4 - niveau 1
\end{exo}

Et on termine par quelque chose de plus difficile

\begin{exo}[level=3]
  Exercice 5 - très dur - niveau 3
\end{exo}

Fin du cours.

\newpage
Feuille exercice

%\FeuilleExercices

Exercices simples
\printlevel{1}

Exercices medians
\printlevel{2}

Exercices complexes
\printlevel{3}

\end{document}

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.