Count total marks and questions

countersexammacros

I'm trying to calculate the total number of questions and total marks based on an exam paper I'm currently writing.

My MEW:

\documentclass[10pt]{exam}

\begin{document}

\section*{Section 1}
This section has 3 questions from Question 1-3 with a total marks of 3.

\begin{questions}

\question[1] Q1

\question[1] Q2

\question[1] Q3

\section*{Section 2}
\uplevel{This section has 3 questions from Question 4-6 with a total marks of 5}

\question[]
\begin{parts}
    \part[1] Q4 Part a. 
    \part[1] Q4 Part b.
\end{parts}

\question[]
\begin{parts}
    \begin{subparts}
        \subpart[1]
        \subpart[1]
    \end{subparts}
\end{parts}

\question[1]
Q6

\end{questions}
\end{document}

I'm trying to make the following lines dyanmic.

This section has 3 questions from Question 1-3 with a total marks of 3. %Section 1

This section has 3 questions from Question 4-6 with a total marks of 5 % Section 2

So that as my paper changes in terms of questions and marks, the above lines will change reflecting the paper.

I've tried to use counters,and changed each question to aquestion and bquestion but they don't give me the desired results I want.

\newtotcounter{a} 
\setcounter{a}{0}
\newcommand{\aquestion}[0]{\stepcounter{a}\question}

\newtotcounter{b} 
\setcounter{b}{0}
\newcommand{\bquestion}[0]{\stepcounter{b}\question}

Further note*

I've also used \begingradinginrange{} \numqinrange but it doesn't give me the desired results of:

a) How many questions there are?
b) What are the question numbers i.e 1-3 or 4-6 etc
c) Total marks for those sections.

Best Answer

I found the answer I need.

This section has \numqinrange{myrange} questions from Question \firstqinrange{myrange}-\lastqinrange{myrange} with a total marks of \pointsinrange{myrange}

As long as I place the \begingradinginrange{myrange} and \endgradinginrange{myrange} I was able to make it dynamic.

Here is the full code:

\documentclass[10pt,addpoints]{exam}

\begin{document}

\section*{Section 1}
This section has \numqinrange{myrange} questions from Question \firstqinrange{myrange}-\lastqinrange{myrange} with a total marks of \pointsinrange{myrange}

\begin{questions}
    
\begingradingrange{myrange}

\question[1] Q1

\question[1] Q2

\question[1] Q3
\endgradingrange{myrange}

\section*{Section 2}
\uplevel{This section has \numqinrange{myrange1} questions from Question \firstqinrange{myrange1}-\lastqinrange{myrange1} with a total marks of \pointsinrange{myrange1}}

\begingradingrange{myrange1}
\question[]
\begin{parts}
    \part[1] Q4 Part a. 
    \part[1] Q4 Part b.
\end{parts}

\question[]
\begin{parts}
    \begin{subparts}
        \subpart[1]
        \subpart[1]
    \end{subparts}
\end{parts}

\endgradingrange{myrange1}

\end{questions}
\end{document}
Related Question