我会对 进行处理xsim
,它的后继exsheets
,我对它所做的同样的事情:在任务环境中列出问题。
那可能吗?
像这样:
\documentclass{article}
\usepackage{exsheets, tasks}
\makeatletter
\def\sol{\relax}
\newcommand*{\@exoSol}[1]{%
\ES@Line #1 \sol\sol%
}
\ExplSyntaxOn
\cs_set_eq:NN \exsheets_par: \scan_stop:
\ExplSyntaxOff
\SetupExSheets{
headings=inline-nr,
counter-format=$\cdot$qu$\cdot$,
question/no-skip-below = true,
question/post-hook={},
solution/post-hook={\hspace{1em}},
solution/pre-hook={}
}
\long\def\ES@Line#1\sol#2\sol{%
\begin{question}#1\end{question}%
\long\def\@test{#2}\ifx\@test\empty\else\begin{solution}#2
\end{solution}\fi%
}
\NewTasks[
label={\relax},
label-width=0em,
item-indent=0em,
label-offset=0em,
item-format={\@exoSol},
before-skip = 0pt]{series}[?]
\makeatother
\begin{document}
Solve with natural numbers, when possible:
\begin{series}(3)
? $1+5$ \sol $6$
? $4-2$ \sol $2$
? $3-4$ \sol impossible
? $8+2$ \sol $10$
? $0+0$
? $6\times 0$ \sol $0$
\end{series}
Solutions:\par
\printsolutions
\end{document}
答案1
这是使用最新版本tasks
(2020/01/11 v1.1a) 和xsim
(2020/02/21 v0.17) 的解决方案。需要xsim
使用该选项加载no-files
才能使用其他宏内的环境。为了方便起见,它还利用了\ifblank
包etoolbox
(无论如何都已加载)。
首先,我稍微改变一下您的自定义宏(主要是为了满足您的喜好):
\newcommand*\sol{}
\newcommand*\exsol[1]{\ESLine#1\sol\sol}
\long\def\ESLine#1\sol#2\sol{%
\begin{exercise}#1\end{exercise}%
\ifblank{#2}{}{\begin{solution}#2\end{solution}}%
}
现在我定义一个适合练习和解决方案的模板(请注意空格,它们很重要):
\DeclareExerciseEnvironmentTemplate{dotted}
{\textbf{$\cdot$\GetExerciseProperty{counter}$\cdot$} }
{ }
然后我告诉xsim
使用新模板并省略标题\printsolutions
:
\xsimsetup{
exercise/template = dotted ,
solution/template = dotted ,
print-solutions/headings = false
}
最后我tasks
用一个空标签定义环境,编号来自xsim
:
\NewTasksEnvironment[
label = ,
label-width = 0em ,
item-indent = 0em ,
label-offset = 0em ,
item-format = \exsol
]{series}[?]
就是这样。文档主体与 OP 中的相同。
完整代码:
\documentclass{article}
\usepackage[no-files]{xsim}[2020/02/21]
\usepackage{tasks}
\newcommand*\sol{}
\newcommand*\exsol[1]{\ESLine#1\sol\sol}
\long\def\ESLine#1\sol#2\sol{%
\begin{exercise}#1\end{exercise}%
\ifblank{#2}{}{\begin{solution}#2\end{solution}}%
}
\DeclareExerciseEnvironmentTemplate{dotted}
{\textbf{$\cdot$\GetExerciseProperty{counter}$\cdot$} }
{ }
\xsimsetup{
exercise/template = dotted ,
solution/template = dotted ,
print-solutions/headings = false
}
\NewTasksEnvironment[
label = ,
label-width = 0em ,
item-indent = 0em ,
label-offset = 0em ,
item-format = \exsol
]{series}[?]
\begin{document}
Solve with natural numbers, when possible:
\begin{series}(3)
? $1+5$ \sol $6$
? $4-2$ \sol $2$
? $3-4$ \sol impossible
? $8+2$ \sol $10$
? $0+0$
? $6\times 0$ \sol $0$
\end{series}
Solutions:\par
\printsolutions
\end{document}