考試中的簡單算術

考試中的簡單算術

如何在 LaTeX 中進行一些簡單的計算?

具體來說,我想將\numpoints(包包的一部分exam)除以 1.10。也就是說,我想做這樣的事情:

Grade: \underline{\hspace{2cm}} out of \numpoints<DIVIDED BY 1.1> (points available \numpoints).

答案1

使用expl3這真的很簡單:

在此輸入影像描述

\documentclass[addpoints]{exam}
\usepackage{expl3}
\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
\makeatletter
\newcommand{\calcnumpoints}{\@ifundefined{exam@numpoints}{0}{\exam@numpoints}}
\makeatother
\begin{document}

\begin{questions}
  \titledquestion{First Question}[5]
  \titledquestion{Second Question}[5]
  \titledquestion{Third Question}[2]
  \titledquestion{Fourth Question}[2]
\end{questions}

\numpoints

\calc{round(\calcnumpoints/1.1,1)}

\end{document}

\calc執行任何浮點計算,在上述情況下四捨五入到一位小數。由於\numpoints輸出有點像參考(??如果它不存在,\exam@numpoints否則),我做了一個替代定義,如果尚未定義,則\calcnumpoints預設為 0 。\exam@numpoints這樣您就可以按預期在計算中使用它。

相關內容