我使用考试类为学生制作考试,我想制作一种问题,它把总分放在前面,但给出详细的分数。我举一个例子:
\documentclass[addpoints]{exam}
\pointformat{}
\qformat{\textbf{Question \thequestion}. [Points of question \thequestion: \totalpoints]\hfill}
\begin{document}
\begin{questions}
\question
\begin{parts}
\part[3]
\part[2]
\end{parts}
\end{questions}
\end{document}
输出结果如下:
我希望获得问题的详细要点作为输出,因此具体如下:
[Points of question 1: 3+2=5 points]
我如何获得它?
答案1
关键是弄清楚它\@doitem
实际上在处理参数。虽然它是全局定义的,但我只想修改/替换它的某些部分。
s\expandafter
是扩展\else
和\fi
首先的。
\documentclass[addpoints]{exam}
\pointformat{}
\qformat{\textbf{Question \thequestion}. [Points of question \thequestion: \details\totalpoints]\hfill}
\makeatletter
\newcommand{\details}{\@ifundefined{details@\roman{question}}{}{\csname details@\roman{question}\endcsname =}}
\newcommand{\@details}{}% reserve global name
\let\normal@parts=\parts
\let\endnormal@parts=\endparts
\renewenvironment{parts}% no arguments?
{\xdef\@details{\@empty}% initialize
\normal@parts
\let\normal@part=\@doitem
\let\@doitem=\my@part
}{%
\endnormal@parts
\ifx\@empty\@details
\else
\immediate\write\@auxout{\string\gdef\string\details@\roman{question}{\@details}}
\fi
}
\newcommand{\my@part}[1][\@empty]{%
\ifx\@empty#1\relax
\expandafter\normal@part
\else
\ifx\@empty\@details
\xdef\@details{#1}%
\else
\xdef\@details{\@details +#1}%
\fi
\expandafter\normal@part\expandafter[\expandafter#1\expandafter]%
\fi
}%
\makeatother
\begin{document}
\begin{questions}
\question[5]
\question
\begin{parts}
\part[3]
\part[2]
\end{parts}
\end{questions}
\end{document}