我的目标是使用这个 MWE 按主题对必修练习进行排序,然后按主题对可选练习进行排序:
\documentclass{report}
\usepackage{xsim}
\DeclareExerciseTagging{subject}
\DeclareExerciseTagging{submission}
\xsimsetup{collect}
\DeclareExerciseCollection[subject=philosophy, submission=mandatory]{philosophy-mandatory}
\DeclareExerciseCollection[subject=philosophy, submission=optional]{philosophy-optional}
\begin{filecontents}{exercises.tex}
\begin{exercise}[solution=true, subject=philosophy, submission=mandatory]
phil 1, mandatory
\IfInsideSolutionT{phil 1 solution}
\end{exercise}
\begin{exercise}[subject=biology, submission=mandatory]
bio 1, mandatory
\end{exercise}
\begin{exercise}[subject=philosophy, submission=optional]
phil 2, optional
\end{exercise}
\end{filecontents}
\begin{document}
\input{exercises.tex}
\section{Mandatory}
\subsection{philosophy}
\printcollection{philosophy-mandatory}
\section{Optional}
\subsection{philosophy}
\printcollection{philosophy-optional}
\end{document}
但是,我真的不明白,为什么所有练习都是必修的,而两个哲学练习却是选修的。我期望
1 Mandatory
1.1 philosopy
phil 1, mandatory
2 Optional
2.1 philosopy
phil 2, optional
答案1
答案2
试试我的新包dbshow
(v1.5),它对排序、过滤和显示数据非常强大。因为现在没有group-by
选项,项目按提交和主题进行多级排序,然后显示在单级列表中。group-by
选项可能会在下一个版本中出现。请参阅文档了解dbshow
更多选项和示例。
\documentclass{article}
\usepackage{dbshow}
\dbNewDatabase{ques-db}{
ques = tl,
ans = tl,
subject = str,
submission = str,
}
\dbNewStyle{ques-style}{ques-db}{
sort = {submission, subject},
item-code = \par\dbarabic.~\dbuse{ques},
after-code = \medskip,
}
\begin{document}
\begin{dbitem}{ques-db}
\dbsave{ques}{phil 1, mandatory}
\dbsave{subject}{philosophy}
\dbsave{submission}{mandatory}
\end{dbitem}
\begin{dbitem}{ques-db}
\dbsave{ques}{bio 1, mandatory}
\dbsave{subject}{biology}
\dbsave{submission}{mandatory}
\end{dbitem}
\begin{dbitem}{ques-db}
\dbsave{ques}{phil 2, optional}
\dbsave{subject}{philosophy}
\dbsave{submission}{optional}
\end{dbitem}
\begin{dbitem}{ques-db}
\dbsave{ques}{bio 2, optional}
\dbsave{subject}{biology}
\dbsave{submission}{optional}
\end{dbitem}
\dbshow{ques-style}{ques-db}
\end{document}