2

I have a question (code given below) which has subparts. Part (a) is further divided into 3 parts: i, ii and iii, whereas Part (b) does not contain any subparts. The total points awarded to this question is 15 of which Part (a) carries 11 marks and Part (b) 4 marks.

There exists the macro \totalpoints in the exam class package that gives me the 11 + 4 = 15 points for the whole question. However there is no macro to compute the number of points (marks) for Part (a) only. I would like a macro that also sums the marks for Part (a) i.e. 2 + 6 + 3 for the subparts to give 11. As the code is today, I have to manually write \part[11] i.e. I myself must manually do the addition of 2 + 6 + 3. I would like a macro that I can just use as \part[\mymacro] that will be equivalent to \part[11].

\totalpoints should also recognise the macro so that I still get 11 + 4 = 15 as the total points for the question. The macro should perhaps just be visible to one subquestion of a whole question so that it can be used in other subquestions of other questions to count the respective sums overthere.

\documentclass[addpoints,12pt]{exam}

\begin{document}

\pointpoints{mark}{marks}


\begin{questions}

\qformat{Question: \thequestion \dotfill {\bfseries \totalpoints\ marks}}
\question


\begin{parts}

\addpoints
\boxedpoints
\part[11]
\noboxedpoints

\noaddpoints

Some background words about the first question.\\[-6.5mm]

\begin{subparts}

  \subpart[2] Show that John is a boy.

  \subpart[6] Show that Jane is a girl.

  \subpart[3] Show that Janice is a monkey.

\end{subparts}

\vspace{5mm}


\addpoints
\boxedpoints
\part[4]
\noboxedpoints


My second question is here and it is worth 4 points. There are no subparts.

\end{parts}


\end{questions}

\end{document}

Based on the answer proposed by @John Kormylo in order for the macro to cater for half points as well, the correct output is not obtained. See output below: enter image description here

We do get 9 1/2 marks as the required sum for the subpart total subtotal. However there are three extras 1/2 inserted between Part (ii) and Part (iii). Moreover now \totalpoints is ignoring the 1/2 marks. The aux file is shown below:

\relax

\gdef\subtotal@i@i{9\half}

\gdef\pointsofq@i{13}

\gdef\bonuspointsofq@i{0}

\PgInfo{question@1}{1}

\PgInfo{question1@object1}{1}

\newlabel{question@1}{{1}{1}}

\PgInfo{part@1@1}{1}

\PgInfo{question1@object2}{1}

\newlabel{part@1@1}{{a}{1}}

\PgInfo{subpart@1@1@1}{1}

\PgInfo{question1@object3}{1}

\newlabel{subpart@1@1@1}{{i}{1}}

\newlabel{firstpoints@onpage@1}{{i}{1}}

\PgInfo{subpart@1@1@2}{1}

\PgInfo{question1@object4}{1}

\newlabel{subpart@1@1@2}{{ii}{1}}

\PgInfo{subpart@1@1@3}{1}

\PgInfo{question1@object5}{1}

\newlabel{subpart@1@1@3}{{iii}{1}}

\PgInfo{part@1@2}{1}

\PgInfo{question1@object6}{1}

\newlabel{part@1@2}{{b}{1}}

\gdef\exam@lastpage{1}

\gdef\exam@lastcoverpage{0}

\gdef\exam@totalpages{1}

\gdef\exam@numpoints{13}

\gdef\exam@numbonuspoints{0}

\gdef\exam@numquestions{1}

\gdef\exam@numparts{2}

\gdef\exam@numsubparts{3}

\gdef\exam@numsubsubparts{0}

\gdef\pointsonpage@i{13}

\gdef\lastpage@withpoints{1}

\gdef\lastpage@withbonuspoints{0}

Compilation is done with TeXLive 2014 using the dvi > ps > pdf workflow.

user11206
  • 319
  • Possibly related: https://tex.stackexchange.com/questions/402863/exam-class-write-details-of-points-with-totalpoints – John Kormylo Apr 05 '18 at 13:17
  • @John Kormylo I looked at the link you've provided but it seems that my question is not related. – user11206 Apr 05 '18 at 16:08
  • @user11206, were you able to find a solution to your problem? I noticed that if you use the \subtotal command twice within the same question, it increases the totalpoints value. Im not sure why it does this? – Alan Jones Apr 22 '22 at 11:03

1 Answers1

3

I added a \subtotal macro which is question and part dependent. It works by storing a number on the aux file, same as \totalpoints (more of less).

Interestingly, this number is ignored by \addpoints.

\documentclass[addpoints,12pt]{exam}

\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

\begin{document}

\pointpoints{mark}{marks}


\begin{questions}

\qformat{Question: \thequestion \dotfill {\bfseries \totalpoints\ marks}}
\question


\begin{parts}

\addpoints
\boxedpoints
\part[\subtotal]

Some background words about the first question.\\[-6.5mm]

\begin{subparts}
  \noboxedpoints
  \subpart[2] Show that John is a boy.

  \subpart[6] Show that Jane is a girl.

  \subpart[3 \half] Show that Janice is a monkey.

\end{subparts}

\vspace{5mm}

\boxedpoints
\part[4]
\noboxedpoints


My second question is here and it is worth 4 points. There are no subparts.

\end{parts}


\end{questions}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Your code works fine. However if the marks in \subpart is not an integer such as 3 but something as 3\half or 3.5:then the macro fails in giving the correct sum. The Exam class recognises the format 3\half for points with fractional parts. – user11206 Apr 06 '18 at 05:15
  • I was hoping to avoid the hlfcntr protocol. – John Kormylo Apr 06 '18 at 14:53
  • Is there any fix? At times I need to have half marks as well. Thank you. – user11206 Apr 06 '18 at 16:34
  • I already editted the solution so use hlfcntr. – John Kormylo Apr 06 '18 at 17:11
  • I see some changes in the code but I don't understand how to use hlfcntr. Do I still have to use \subtotal? – user11206 Apr 06 '18 at 17:26
  • Yup. The text is formatted and written to the aux file using whatever setttings exam class uses for half points. – John Kormylo Apr 07 '18 at 03:51
  • There are still some issues. I've updated the post with the new output that I get to clarify things. Thank you. – user11206 Apr 07 '18 at 07:13
  • Exam class uses \half instead of 1/2 for half points. Also, it takes two runs to update \subtotal (aux file). – John Kormylo Apr 07 '18 at 16:26
  • Great! I've found why I was not getting the correct result. WinEdt will compile the required number of times. The problem was that I was writing \subpart[3\half] instead of \subpart[3 \half] as you now has put in the MWE. This difference was causing havoc! – user11206 Apr 07 '18 at 16:44
  • I think my question is very close to what you did here. I would be grateful if you could consider it. – Diaa Sep 02 '18 at 17:34