考试:有条件地打印分数/问题/页面的单数/复数形式

考试:有条件地打印分数/问题/页面的单数/复数形式

后续行动这个答案,我想知道在多道题考试的情况下如何打印单词,在单道题考试的情况下如何\NAMEquestions打印单词?"questions""question"

例如,在两道题的考试中,\NAMEquestions打印TWO questions,而在单题考试中,它会打印ONE question\NAMEpages。和 也同样如此\NAMEpoints

因此,在下面的 MWE 中,所需的输出是:

此考试包含一个问题一页(包括封面)共计十分

\documentclass[addpoints]{exam}

\usepackage{fmtcount,etoolbox}

\makeatletter
\let\NAMEquestions\numquestions
\patchcmd{\NAMEquestions}{\exam@numquestions}{{\NUMBERstringnum\exam@numquestions}}{}{}
\let\NAMEpages\numpages
\patchcmd{\NAMEpages}{\exam@lastpage}{{\NUMBERstringnum\exam@lastpage}}{}{}
\let\NAMEpoints\numpoints
\patchcmd{\NAMEpoints}{\exam@numpoints}{{\NUMBERstringnum\exam@numpoints}}{}{}
\makeatother

\begin{document}

This exam contains \textbf{\NAMEquestions} in \textbf{\NAMEpages} (including the cover) for a total of \textbf{\NAMEpoints}.

\begin{questions}
  \question[10] single question
\end{questions}

\end{document}

答案1

您可以根据用于打印命名数字的各个宏的值进行条件设置:

在此处输入图片描述

\documentclass[addpoints]{exam}

\usepackage{fmtcount,etoolbox}

\makeatletter
\let\NAMEquestions\numquestions
\patchcmd{\NAMEquestions}{\exam@numquestions}{{\NUMBERstringnum\exam@numquestions} question\ifnum\exam@numquestions>1 s\fi}{}{}
\let\NAMEpages\numpages
\patchcmd{\NAMEpages}{\exam@lastpage}{{\NUMBERstringnum\exam@lastpage} page\ifnum\exam@lastpage>1 s\fi}{}{}
\let\NAMEpoints\numpoints
\patchcmd{\NAMEpoints}{\exam@numpoints}{{\NUMBERstringnum\exam@numpoints} mark\ifnum\exam@numpoints>1 s\fi}{}{}
\makeatother

\begin{document}

This exam contains \textbf{\NAMEquestions} in \textbf{\NAMEpages} (including the cover) for a total of \textbf{\NAMEpoints}.

\begin{questions}
  \question[10] single question
\end{questions}

\end{document}

相关内容