在考试类中自定义 \pointpoints,使其不仅包括单数和复数形式

在考试类中自定义 \pointpoints,使其不仅包括单数和复数形式

我重新发送了一个问题,与其他人一起发布在这里 为考试类别重新定义 \pointname

我有一个问题,与 Exam 类中命令 ''\thepoints'' 的自定义有关。如果已为问题指定了点数,则 Exam.cls 中的命令 ''\thepoints'' 始终被“@points @pointname”替换。(@points 是点条目,@pointname 是点名称。

此点名由命令 ''\pointpoints{point}{points}'' 定义,其中当 @points=1 or=1/2 (单数)时 ''\pointname' 由 ''point'' 替换,而当 @points > 1 (复数)时 ''points'' 由 ''points'' 替换。

我想为其他语言(特别是阿拉伯语)定制命令“\thepoints”,其中可以有两种以上的情况,例如四种:情况“@points=1 or=1/2”、“@points=2”、“3<=@points<=10”和“@points>10”)。

然后,“@pointname”将有 4 个不同的值名称,比如 {WORD_1、WORD_2、WORD_3、WORD_4}。

所以我想编写一个宏来用以下代码替换“\thepoints”:

  • 如果“@points=1 or=1/2”则为“WORD_1”(请注意,这里没有写@points...)
  • 如果'@points=2',则为“WORD_2”(请注意,这里也没有写@points......)
  • "@points WORD_3" if '3<= @points <=10' (这里我们写入@points 的值……)
  • "@points WORD_4" if '@points >10' (这里也必须写上@points...)

更准确地说,我想要以下命令:

\question[1] 给出: 问题 (WORD_1)

\question[2] 给出: 问题 (WORD_2)

\question[8] 给出: 问题 (8 WORD_3)

\question[14] 给出: 问题 (14 WORD_4)

答案1

\pointsexam.cls中宏的定义是:

\newcommand\points{%
  \begingroup
    \let\half=\relax
    \edef\pt@string{\@points}%
    \ifthenelse{\equal{\pt@string}{1} \or \equal{\pt@string}{\half}}
          {\point@sing}{\point@plur}%
  \endgroup
}

您可以在条件中创建更多案例(四个),ifthenelse如下所示

\renewcommand\points{%
  \begingroup
    \let\half=\relax
    \edef\pt@string{\@points}%
    \ifthenelse{\equal{\pt@string}{1} \OR \equal{\pt@string}{\half}}
    {\point@labelone}{%
    \ifthenelse{\equal{\pt@string}{2}}{\point@labeltwo}{%
    \ifthenelse{\equal{\pt@string}{3} \OR \equal{\pt@string}{3\half}%
    \OR \equal{\pt@string}{4} \OR \equal{\pt@string}{4\half}%
    \OR \equal{\pt@string}{5} \OR \equal{\pt@string}{5\half}%
    \OR \equal{\pt@string}{6} \OR \equal{\pt@string}{6\half}%
    \OR \equal{\pt@string}{7} \OR \equal{\pt@string}{7\half}%
    \OR \equal{\pt@string}{8} \OR \equal{\pt@string}{8\half}%
    \OR \equal{\pt@string}{9} \OR \equal{\pt@string}{9\half}%
    \OR \equal{\pt@string}{10}\OR \equal{\pt@string}{10\half}}
     {\point@labelthree}{\point@labelfour}}}
          %
  \endgroup
}

在这里您可以获得您需要的东西。也许有一种更短的方法来做到这一点。

你可以用这个 MWE 来测试它:

\documentclass[11pt]{exam}

\def\sample{What is the Pythagorean theorem}


\makeatletter
\newcommand\point@labelone{word-1}
\newcommand\point@labeltwo{word-2}
\newcommand\point@labelthree{word-3}
\newcommand\point@labelfour{word-4}


\renewcommand\points{%
  \begingroup
    \let\half=\relax
    \edef\pt@string{\@points}%
    \ifthenelse{\equal{\pt@string}{1} \OR \equal{\pt@string}{\half}}
    {\point@labelone}{%
    \ifthenelse{\equal{\pt@string}{2}}{\point@labeltwo}{%
    \ifthenelse{\equal{\pt@string}{3} \OR \equal{\pt@string}{3\half}%
    \OR \equal{\pt@string}{4} \OR \equal{\pt@string}{4\half}%
    \OR \equal{\pt@string}{5} \OR \equal{\pt@string}{5\half}%
    \OR \equal{\pt@string}{6} \OR \equal{\pt@string}{6\half}%
    \OR \equal{\pt@string}{7} \OR \equal{\pt@string}{7\half}%
    \OR \equal{\pt@string}{8} \OR \equal{\pt@string}{8\half}%
    \OR \equal{\pt@string}{9} \OR \equal{\pt@string}{9\half}%
    \OR \equal{\pt@string}{10}\OR \equal{\pt@string}{10\half}}
     {\point@labelthree}{\point@labelfour}}}
          %
  \endgroup
}

\makeatother

\pointformat{(\thepoints)}

\begin{document}

\begin{questions}

\question[\half] \sample

\question[1] \sample

\question[2] \sample

\question[4] \sample

\question[12] \sample

\end{questions}

\end{document}

\@points要从宏中删除\thepoints单词 1 和单词 2,我在 exam.cls 中找不到原始定义\thepoints,解决方法是,您可以借助以下方法更改其定义\pointformat

\documentclass[11pt]{exam}

\def\sample{What is the Pythagorean theorem}


\makeatletter
\newcommand\point@labelone{word-1}
\newcommand\point@labeltwo{word-2}
\newcommand\point@labelthree{word-3}
\newcommand\point@labelfour{word-4}


\renewcommand\points{%
  \begingroup
    \let\half=\relax
    \edef\pt@string{\@points}%
    \ifthenelse{\equal{\pt@string}{1} \OR \equal{\pt@string}{\half}}
    {\point@labelone}{%
    \ifthenelse{\equal{\pt@string}{2}}{\point@labeltwo}{%
    \ifthenelse{\equal{\pt@string}{3} \OR \equal{\pt@string}{3\half}%
    \OR \equal{\pt@string}{4} \OR \equal{\pt@string}{4\half}%
    \OR \equal{\pt@string}{5} \OR \equal{\pt@string}{5\half}%
    \OR \equal{\pt@string}{6} \OR \equal{\pt@string}{6\half}%
    \OR \equal{\pt@string}{7} \OR \equal{\pt@string}{7\half}%
    \OR \equal{\pt@string}{8} \OR \equal{\pt@string}{8\half}%
    \OR \equal{\pt@string}{9} \OR \equal{\pt@string}{9\half}%
    \OR \equal{\pt@string}{10}\OR \equal{\pt@string}{10\half}}
     {\point@labelthree}{\point@labelfour}}}
          %
  \endgroup
}

\renewcommand\thepoints{%
  \if@placepoints
    \if@bonus
      \@points \@bonuspointname 
    \else
    \let\half=\relax
    \edef\pt@string{\@points}%
    \ifthenelse{\equal{\pt@string}{1} \OR \equal{\pt@string}{\half}%
                                      \OR \equal{\pt@string}{2}}
    {\@pointname}{\@points \@pointname}
     \fi
  \fi
}% thepoints

\makeatother

\pointformat{(\thepoints)}

\begin{document}

\begin{questions}

\question[\half] \sample

\question[1] \sample

\question[2] \sample

\question[4] \sample

\question[12] \sample

\end{questions}

\end{document}

我们获得:

在此处输入图片描述

相关内容