当我尝试在包中的环境中使用列表环境( itemize
、enumerate
等)时遇到编译错误。shortsolution
xsim
这是一个 MWE。
\documentclass{scrartcl}
\usepackage{xsim}
\usepackage{enumitem}
\xsimsetup{
exercise/template = default,
exercise/name = Aufgabe,
solution/name = Lösung,
}
\DeclareExerciseProperty{shortsolution}
\newcommand*\printshortsolutions{%
\begin{description}[leftmargin=3cm, style=sameline]
\ForEachUsedExerciseByType{%
\def\ExerciseType{##1}%
\def\ExerciseID{##2}%
\GetExercisePropertyT{shortsolution}%
{%
\item[Kurzlösung ##3] ####1%
}%
}%
\end{description}
}
\NewDocumentEnvironment{shortsolution}{b}
{\SetExpandedExerciseProperty{shortsolution}{#1}}
{}
\begin{document}
\begin{exercise}
This is the exercise
\begin{shortsolution}
Some text.
\begin{enumerate}
\item
Some more text.
\end{enumerate}
\end{shortsolution}
\end{exercise}
\begin{solution}
The Solution
\end{solution}
\printshortsolutions
\printallsolutions
\end{document}
我收到的错误是在 TeXLive-2020 下。
! Use of \\enumerate doesn't match its definition.
\kernel@ifnextchar ...d@d =#1\def \reserved@a {#2}
\def \reserved@b {#3}\futu...
l.17 \end
{shortsolution}
If you say, e.g., `\def\a1{...}', then you must always
put `1' after `\a', since control sequence names are
made up of letters only. The macro here has not been
followed by the required stuff, so I'm ignoring it.
! Illegal parameter number in definition of \l__exp_internal_tl.
<to be read again>
1
l.17 \end
{shortsolution}
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
答案1
你没有说出你期望的输出,但是
\NewDocumentEnvironment{shortsolution}{b}
{\SetExpandedExerciseProperty{shortsolution}{#1}}
{}
记录为将#1
(此处的整个环境主体)放入\edef
。您不能将带有可选参数的脆弱命令放入 edef 中,否则会出现所示的奇怪内部错误。
如果你使用
\NewDocumentEnvironment{shortsolution}{b}
{\SetExerciseProperty{shortsolution}{#1}}
{}
然后它运行没有错误,但我不知道这是否是您需要的输出。