我正在尝试使用 xsim 为学生设计一本练习册,并为导师提供第二版。其中将包含练习/问题/家庭作业(无论你想如何称呼它)及其各自的解决方案。
从我目前的评论来看,模拟,似乎是实现此目的的最合适的软件包。但是,有一条信息我在文档中找不到:如何在空的答案空间/空白/框和打印的解决方案之间切换?
理想情况下,我希望答案空间能够精确占据排版解决方案的幻像空间。
附件中您可以找到我希望它如何工作的 MWE,但我希望该过程能够自动化。
以下 MWE 产生(注意solution/print = true
)
\documentclass{article}
\usepackage{mwe}
\usepackage{amssymb, amsmath}
\usepackage{xsim}
\usepackage{tcolorbox}
\DeclareExerciseEnvironmentTemplate{tcolorbox}
{%
\tcolorbox[
beforeafter skip = .5\baselineskip ,
title =
\textbf{\GetExerciseName~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{\PropertyValue}}%
]%
}
{\endtcolorbox}
\DeclareExerciseType{problem}{
exercise-env = problem ,
solution-env = answer ,
exercise-name = Problem ,
solution-name = Answer ,
exercise-template = tcolorbox ,
solution-template = tcolorbox
}
\xsimsetup{
answer/print=true
}
\begin{document}
\begin{problem}
Show that $(\mathbb{R}, +, \cdot)$ is a field.
\end{problem}
\begin{answer}
Let $a, b, c \in \mathbb{R}$ arbitrary. Then, we show the following properties:
\begin{description}
\item[Commutativity of addition] $a + b = b+ a$.
\item[Associativity of addition] $a +(b + c) = (a+b) +c$.
\item[Additive identity] $0 \in \mathbb{R}$, and $a +0 = a $.
\item[Additive inverse] for each $a \in \mathbb{R}$, there exists $-a \in \mathbb{R}$, sch that $a + (-a) = 0$.
\item[Commutativity of multiplication] $a \cdot b = b \cdot a$.
\item[Associativity of multiplications] $a \cdot (b \dot c) = (a \cdot b) \cdot c$.
\item[Multiplicative identity] $1 \in \mathbb{R}$, such that $1 \cdot a = a$.
\item[Multiplicative inverse] for each $a \in \mathbb{R}$, there exists $a^{-1}\in \mathbb{R}$, such that $a \cdot a^{-1} = 1$.
\item[Distributivity] $a\cdot (b + c) = (a \cdot b) + (a \cdot c)$.
\end{description}
These are the necessary and sufficient properties of a field, hence $(\mathbb{R}, +, \cdot)$ is a field.
\end{answer}
\end{document}
但我想要当答案被禁用时,尺寸相同的空框。
更新
最终,我放弃了xsim
,选择了一条不同的道路,并提出了自己的替代解决方案,具体如下在另一个问题和答案中。但是,这仍然不是这个问题的答案。
更新
再过一步,我又重新开始使用xsim
。请参阅下面的解决方案。
答案1
与此同时,我已经想到了一个答案,但是这个答案取决于xsim
正在使用的版本。
xsim < v0.19b
例如,请参阅更新后的 MWE:
\documentclass{article}
\usepackage{mwe}
\usepackage{amssymb, amsmath}
\usepackage[]{xsim}
\usepackage{tcolorbox}
\xsimsetup{
solution/print = true,
}
\SetExerciseParameters{exercise}{
exercise-name = \XSIMtranslate{exercise},
solution-name = \XSIMtranslate{solution},
exercise-template = exercise,
solution-template = solution,
counter=section,
}
\DeclareExerciseEnvironmentTemplate{exercise}
{%
\tcolorbox[
beforeafter skip = .5\baselineskip ,
title =
\textbf{\GetExerciseName~\GetExerciseProperty{counter}}%
]%
}%
{%
\endtcolorbox
% at this point, add invisible solution
\IfSolutionPrintTF{}{%
\tcolorbox[%
upperbox=invisible,%
beforeafter skip = .5\baselineskip ,%
title =
\textbf{\GetExerciseParameter{solution-name}~\GetExerciseProperty{counter}}%
]%
\GetExerciseBody{solution}%
\endtcolorbox%
}%
}%
\DeclareExerciseEnvironmentTemplate{solution}%
{%
\tcolorbox[
beforeafter skip = .5\baselineskip ,
title =
\textbf{SOL: \GetExerciseName~\GetExerciseProperty{counter}}%
]%
}%
{\endtcolorbox}%
\begin{document}
\section{A section title}
\begin{exercise}
Show that $(\mathbb{R}, +, \cdot)$ is a field.
\end{exercise}
\begin{solution}
Let $a, b, c \in \mathbb{R}$ arbitrary. Then, we show the following properties:
\begin{description}
\item[Commutativity of addition] $a + b = b+ a$.
\item[Associativity of addition] $a +(b + c) = (a+b) +c$.
\item[Additive identity] $0 \in \mathbb{R}$, and $a +0 = a $.
\item[Additive inverse] for each $a \in \mathbb{R}$, there exists $-a \in \mathbb{R}$, sch that $a + (-a) = 0$.
\item[Commutativity of multiplication] $a \cdot b = b \cdot a$.
\item[Associativity of multiplications] $a \cdot (b \dot c) = (a \cdot b) \cdot c$.
\item[Multiplicative identity] $1 \in \mathbb{R}$, such that $1 \cdot a = a$.
\item[Multiplicative inverse] for each $a \in \mathbb{R}$, there exists $a^{-1}\in \mathbb{R}$, such that $a \cdot a^{-1} = 1$.
\item[Distributivity] $a\cdot (b + c) = (a \cdot b) + (a \cdot c)$.
\end{description}
These are the necessary and sufficient properties of a field, hence $(\mathbb{R}, +, \cdot)$ is a field.
\end{solution}
\end{document}
xsim v0.20
理想情况下,相同的代码应该可以工作。然而,直到这个错误已解决。问题评论中的解决方法是使用
\xsimsetup{collect=true}
然后在文档主体中使用
\printcollection[print=both]{all exercises}
solutions/print=false
不幸的是,如果设置了该选项,则会附加解决方案的填充副本。
因此,目前针对此答案的解决方法是:将解决方案主体移到练习中进行打印:
\documentclass{article}
\usepackage{mwe}
\usepackage{amssymb, amsmath}
\usepackage[]{xsim}
\usepackage{tcolorbox}
\xsimsetup{
solution/print = true, % toggle this line
collect=true,
}
\SetExerciseParameters{exercise}{
exercise-name = \XSIMtranslate{exercise},
solution-name = \XSIMtranslate{solution},
exercise-template = exercise,
solution-template = solution,
counter=section,
}
\DeclareExerciseEnvironmentTemplate{exercise}
{%
\tcolorbox[
beforeafter skip = .5\baselineskip ,
title =
\textbf{\GetExerciseName~\GetExerciseProperty{counter}}%
]%
}%
{%
\endtcolorbox
% at this point, add invisible solution
\IfSolutionPrintTF{%
\tcolorbox[%
beforeafter skip = .5\baselineskip ,%
title =
\textbf{\GetExerciseParameter{solution-name}~\GetExerciseProperty{counter}}%
]%
\GetExerciseBody{solution}%
\endtcolorbox%
}{%
\tcolorbox[%
upperbox=invisible,%
beforeafter skip = .5\baselineskip ,%
title =
\textbf{\GetExerciseParameter{solution-name}~\GetExerciseProperty{counter}}%
]%
\GetExerciseBody{solution}%
\endtcolorbox%
}%
}%
\DeclareExerciseEnvironmentTemplate{solution}%
{%
\tcolorbox[
beforeafter skip = .5\baselineskip ,
title =
\textbf{\GetExerciseName~\GetExerciseProperty{counter}}%
]%
}%
{\endtcolorbox}%
\begin{document}
\section{A section title}
\begin{exercise}
Show that $(\mathbb{R}, +, \cdot)$ is a field.
\end{exercise}
\begin{solution}
Let $a, b, c \in \mathbb{R}$ arbitrary. Then, we show the following properties:
\begin{description}
\item[Commutativity of addition] $a + b = b+ a$.
\item[Associativity of addition] $a +(b + c) = (a+b) +c$.
\item[Additive identity] $0 \in \mathbb{R}$, and $a +0 = a $.
\item[Additive inverse] for each $a \in \mathbb{R}$, there exists $-a \in \mathbb{R}$, sch that $a + (-a) = 0$.
\item[Commutativity of multiplication] $a \cdot b = b \cdot a$.
\item[Associativity of multiplications] $a \cdot (b \dot c) = (a \cdot b) \cdot c$.
\item[Multiplicative identity] $1 \in \mathbb{R}$, such that $1 \cdot a = a$.
\item[Multiplicative inverse] for each $a \in \mathbb{R}$, there exists $a^{-1}\in \mathbb{R}$, such that $a \cdot a^{-1} = 1$.
\item[Distributivity] $a\cdot (b + c) = (a \cdot b) + (a \cdot c)$.
\end{description}
These are the necessary and sufficient properties of a field, hence $(\mathbb{R}, +, \cdot)$ is a field.
\end{solution}
\printcollection[print=exercises]{all exercises}
\end{document}
这会产生以下所需的输出(与以前的版本相同,但代码不太简单并且可能存在额外的未观察到的缺点):