
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
출력은 참조와 다소 유사 하므로 (??존재하지 않는 경우, 그렇지 않은 경우) 아직 정의되지 않은 경우 기본값이 0인 \exam@numpoints
대체 정의를 만들었습니다 . 이렇게 하면 예상대로 계산에 사용할 수 있습니다.\calcnumpoints
\exam@numpoints