![xsim 访问练习文本](https://linux22.com/image/358521/xsim%20%E8%AE%BF%E9%97%AE%E7%BB%83%E4%B9%A0%E6%96%87%E6%9C%AC.png)
在尝试时,xsim
我发现缺少一个对我来说基本的功能:打印重复练习文本的解决方案(顺便说一句:使用 tcolorbox 样式)。我可以模拟一个看起来不太理想的类似行为:
这里的问题是:(a) 问题在写着“解决方案”的框中重复出现,并且计数器错误;(b) 我无法将练习的框拿走(试过\let\tcolorbox\relax
,但失败了)。
我想要实现的目标如下:
所以问题是:我怎样才能访问不带格式化的练习文本(注意:我的真实情况中有一些逐字材料)或删除练习周围的 tcolorbox?
% arara: lualatex
\documentclass{scrbook}
\PreventPackageFromLoading{inputenc} % stop tcb from loading this
\usepackage[most]{tcolorbox}
\usepackage[clear-aux]{xsim}
\DeclareExerciseEnvironmentTemplate{tcb}
{%
\tcolorbox[breakable,drop shadow,beforeafter skip = .5\baselineskip,title =
\textbf{\GetExerciseName~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{\PropertyValue}}%
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{ % notice the space
(%
\PropertyValue
\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
)%
}%
}%
]%
\IfInsideSolutionT{%
\GetExercisePropertyT{id}{\printexercise{ltxexercise}{\PropertyValue}}%
}%
}{\endtcolorbox}
\DeclareExerciseType{ltxexercise}{
exercise-env=ltxexercise,
solution-env=ltxsolution,
exercise-name=\XSIMtranslate{exercise},
solution-name=\XSIMtranslate{solution},
exercise-template=tcb,
solution-template=tcb,
within=chapter,
}
\begin{document}
\chapter{Exercises}
\begin{ltxexercise}
Blub?
\end{ltxexercise}
\begin{ltxsolution}
Under water
\end{ltxsolution}
\begin{ltxexercise}
Quack?
\end{ltxexercise}
\begin{ltxsolution}
At the surface
\end{ltxsolution}
\section{Solutions}
\printsolutions[headings=false]
\section{Intended result}
\begin{tcolorbox}[title=Solution for exercise 1]
\tcbsubtitle{Exercise}
Blub
\tcbsubtitle{Solution}
Under water
\end{tcolorbox}
\end{document}
答案1
这应该有效:
% arara: lualatex
\documentclass{scrbook}
\PreventPackageFromLoading{inputenc} % stop tcb from loading this
\usepackage[most]{tcolorbox}
\usepackage[clear-aux]{xsim}
\DeclareExerciseEnvironmentTemplate{tcb}
{%
\tcolorbox[breakable,drop shadow,beforeafter skip = .5\baselineskip,title =
\textbf{\IfInsideSolutionT{Solution for }%
Exercise~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{\PropertyValue}}%
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{ % notice the space
(%
\PropertyValue
\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
)%
}%
}%
]%
\IfInsideSolutionT{%
\tcbsubtitle{Exercise}
\input{\jobname-\ExerciseType-\ExerciseID-exercise-body.tex}
\tcbsubtitle{Solution}
}
}{\endtcolorbox}
\DeclareExerciseType{ltxexercise}{
exercise-env=ltxexercise,
solution-env=ltxsolution,
exercise-name=\XSIMtranslate{exercise},
solution-name=\XSIMtranslate{solution},
exercise-template=tcb,
solution-template=tcb,
within=chapter,
}
\begin{document}
\chapter{Exercises}
\begin{ltxexercise}
Blub?
\end{ltxexercise}
\begin{ltxsolution}
Under water
\end{ltxsolution}
\begin{ltxexercise}
Quack?
\end{ltxexercise}
\begin{ltxsolution}
At the surface
\end{ltxsolution}
\section{Solutions}
\printsolutions[headings=false]
\end{document}
从
xsim
0.10 版(2017 年 9 月)开始,此功能已集成到包中。不再需要以下声明,您可以直接使用\GetExerciseBody{exercise}
。
我将在的下一个版本中添加类似以下内容xsim
:
% #1: type
% #2: id
% #3: exercise|solution
\cs_new_protected:Npn \xsim_input:nnn #1#2#3
{
\group_begin:
\__xsim_set_file_signature:nnn {#1} {#2} {#3}
\file_input:n { \l__xsim_file_path_and_name_tl }
\group_end:
}
\cs_generate_variant:Nn \xsim_input:nnn {oo}
% #1: exercise|solution
\NewDocumentCommand \GetExerciseBody {m}
{ \xsim_input:oon { \ExerciseType } { \ExerciseID } {#1} }
然后在模板定义中
\input{\jobname-\ExerciseType-\ExerciseID-exercise-body.tex}
可以替换为
\GetExerciseBody{exercise}