您发布了一个非常好的解决方案来获取包含解决方案的单独文件这里。我花了几个小时尝试修改您的解决方案。是否可以将问题的编号添加到解决方案中?
这是我通过您的解决方案得到的结果:
a) 解决方案是...
b) 解决方案是...
c) 解决方案是...
a) 解决方案是...
b) 解决方案是...
a) 解决方案是...
这就是我想要的:
练习 1
a) 解决方案是......
b) 解决方案是......
c) 解决方案是......
练习 2
a) 解决方案是......
b) 解决方案是......
练习 3
a) 解决方案是......
我希望你能帮忙。非常感谢!
马蒂亚斯
答案1
新解决方案基于我自己的答案到考试文件末尾的答案,当问题有部分、子部分和子子部分时,这可以正确处理,这与我之前的回答(如下)不同。
标签和答案内容都存储在单独的seq
变量中,然后同时通过两个序列进行迭代,一起重新打印。计数器只会打印出来,并且只有在计数器设置为零时才会被抑制,为了更优雅地格式化解决方案编号,需要根据它们是否为零进行条件判断。
\documentclass[a4paper]{exam}
\usepackage{xparse}
\printanswers
\ExplSyntaxOn
% Counters are not reset on \end{parts} so I add code to reset them
\tl_put_right:Nn \endparts { \setcounter{partno}{0} }
\tl_put_right:Nn \endsubparts { \setcounter{subpart}{0} }
\tl_put_right:Nn \endsubsubparts { \setcounter{subsubpart}{0} }
\seq_new:N \l_exam_endprint_seq
\seq_new:N \l_exam_endprint_labels_seq
\tl_new:N \l__exam_endprint_temp_tl
\NewDocumentCommand \WriteAnswer { +m } {
\seq_gput_right:Nx \l_exam_endprint_labels_seq {\arabic{question}\alph{partno}\roman{subpart}\greeknum{subsubpart}} \seq_gput_right:Nn \l_exam_endprint_seq { #1 }
}
\NewDocumentCommand \EndPrintAnswers { } {
\seq_map_inline:Nn \l_exam_endprint_seq {
\seq_pop_left:NN \l_exam_endprint_labels_seq \l__exam_endprint_temp_tl
\renewcommand{\solutiontitle}{\noindent\textbf{Solution~\l__exam_endprint_temp_tl}:\enspace}
\begin{solution} ##1 \end{solution}
}
}
\ExplSyntaxOff
\begin{document}
\begin{questions}
\addpoints \question
\begin{parts}
\part This is the first part of question one.
\WriteAnswer{This is the solution to part one of question one.}
\part This is the second part of question one.
\begin{subparts}
\subpart This is the first subpart of the second part of question one.
\WriteAnswer{This is the solution to the first subpart of part two of question one.}
\subpart
\begin{subsubparts}
\subsubpart This is the first subsubpart of the second subpart of the second part of question one.
\WriteAnswer{This is the solution to the first subsubpart of the second subpart of the second part of question one.}
\end{subsubparts}
\end{subparts}
\part This is the third part of question one
\WriteAnswer{This is the solution to part three of question one.}
\end{parts}
\addpoints \question This is the second question.
\WriteAnswer{This is the solution to question two.}
\end{questions}
\EndPrintAnswers
\end{document}
这是我最初的答案,它只是通过计数器对每个解决方案进行编号,每次打印解决方案时计数器都会递增。如果使用零件,那么这将破坏编号(即解决方案 1 可以用于问题 1a,解决方案 2 可以用于问题 1b,解决方案 3 可以用于问题 2)。
使用解决方案中的 MWE考试文件末尾的答案
\solutiontitle
为每个解决方案添加一个新的计数器,并使用类中的宏对其进行步进exam
,如下所示
\newcounter{solution}
\stepcounter{solution}
\renewcommand{\solutiontitle}{\noindent\textbf{Solution \arabic{solution}:}\enspace\stepcounter{solution}}
产量
来自完整代码
\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\printanswers
\newcounter{solution}
\stepcounter{solution}
\renewcommand{\solutiontitle}{\noindent\textbf{Solution \arabic{solution}:}\enspace\stepcounter{solution}}
\usepackage{url}
\usepackage{endnotes}
\def\enotesize{\normalsize}
\def\makeenmark{\relax}
\def\notesname{Answers}
\def\answer#1{\endnotetext{\vspace*{-3.5ex}\begin{solution}#1\end{solution}\unskip}}
\def\theanswers{\theendnotes \medskip}
\begin{document}
\begin{questions}
\addpoints \question This is the first question
\answer{This is the solution to question one.}
\addpoints \question This the second question
\answer{This is the solution to question two.}
\end{questions}
\theanswers
\end{document}