1

I've been trying to modify the following code which I have obtained from Macro for computing subtotal Tex Question.

My MWE with my not so great solution.


\documentclass[addpoints]{exam}

%%%%%%%%%%%%%%% Finds subtotal of all subparts %%%%%%%%%%%%%% %%%%%%%%%%%%%%% Solution by John, K %%%%%%%%%%%%%% \makeatletter \newcommand{\subtotal}{@ifundefined{subtotal@\roman{question}@\roman{partno}}% {}% {\csname subtotal@\roman{question}@\roman{partno}\endcsname}}

\new@hlfcntr{part@subtotal}

\let\normal@subparts=\subparts \let\endnormal@subparts=\endsubparts \renewenvironment{subparts}% no arguments? {\set@hlfcntr{part@subtotal}{0}% \normal@subparts \let\normal@subpart=@doitem \let@doitem=\my@subpart }{% \endnormal@subparts \ifnum\c@part@subtotal>0 \immediate\write@auxout{\string\gdef\string\subtotal@\roman{question}@\roman{partno}% {\prtaux@hlfcntr{part@subtotal}}}%

\fi }

\newcommand{\my@subpart}[1][@empty]{%

\ifx@empty#1\relax \expandafter\normal@subpart \else \ifx@empty@details \else \addto@hlfcntr{part@subtotal}{#1}% \fi \expandafter\normal@subpart\expandafter[\expandafter#1\expandafter]% \fi }% \makeatother

\newcommand{\hidepoints}{\pointformat{}} % Hides my points

\newcommand{\showpoints}{\pointformat{\textbf{\thepoints}}} % Shows my points

\begin{document} \begin{questions}

%%%%%%%%%%% The problem below %%%%%%%%%%%%%%5

\question This is my problem \begin{parts} \part[\subtotal] I don't want to see the subtotal of 5. % I don't want to see the \subtotal on my paper, but I need it to tell LaTeX as this parts total points is the sum of the subparts below. \begin{subparts} \subpart[2] This subpart has 2 points. \subpart[3] This subpart has 3 points. \end{subparts}

This is another problem

\part[\subtotal] I don't want to see the subtotal of 2. % I don't want to see the \subtotal on my paper, but I need it to tell LaTeX as this parts total points is the sum of the subparts below. \begin{subparts} \subpart[1] This subpart has 1 points. \subpart[1] This subpart has 1 points. \end{subparts}

\end{parts}

\droptotalpoints % Another problem as a result is Why the total points for Question 1 = 12 when it should be 7 (5+2)?

%%%%%%%%%% My current work around for the above problem below %%%%%%%%%

\question This is my not so great solution. \hidepoints % I have hidden by \subtotal result. \begin{parts} \part[\subtotal] % I don't want to see the \subtotal on my paper, but I need to tell latex that this part is the sum of the subparts below. \showpoints % Now i have to show points or else the \subparts won't be dispalyed.

\begin{subparts}
    \subpart[2] 
    \subpart[3] 
\end{subparts}

\end{parts}

\end{questions} \end{document}

*The Problem

I can work around showing and hiding the subtotal of all my subparts manually by adding \hidepoints and \showpoints between my \parts[\subtotal] commands, but I noticed that if I have 2 subparts within a question, the total points for that question is calculated incorrectly.

Ideally I would like to come up with a solution that:

a) auto hides the \subtotal command. b) calculates the correct points for the question.

0 Answers0