試験における簡単な算数

試験における簡単な算数

LaTeX で簡単な計算を行うにはどうすればよいでしょうか?

\numpoints具体的には、 (パッケージの一部) を 1.10 で割りますexam。つまり、次のような操作を行います。

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は浮動小数点演算を実行しますが、上記の例では小数点1桁に丸められます。\numpoints出力は参照のようなので(??存在しない場合は 1 になり、そうでない場合は 0 になる\exam@numpoints代替定義を作成しました。これにより、期待どおりに計算に使用できます。\calcnumpoints\exam@numpoints

関連情報