我想要一个包含练习的文件,并且在文件末尾,我想要打印按级别排序的练习(我用 xsim 创建的标签)。
由于显而易见的原因,下面不起作用的\printcollection
是使用集合而不是标签,但我无法弄清楚如何处理集合,而无需为每个练习都写它)。
相关问题:是否可以用数字(例如 、1
或2
)定义级别,并在 中3
打印相应数字?$\star$
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
两种情况都有可能。
您可以定义一个命令来仅打印特定级别的练习,如下所示:
\NewDocumentCommand\printlevel{m}{%
\ForEachUsedExerciseByType{%
\def\ExerciseType{##1}%
\def\ExerciseID{##2}%
\IfExercisePropertySetT{level}{%
\ifnum\GetExerciseProperty{level}=#1
\printexercise{exo}{##2}%
\fi
}%
}%
}
并且使用\prg_replicate:nn { integer } { code }
将integer
时间放置code
在输入流中的 expl3,您可以轻松输出 s 的数量\star
:
\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}