1

I want to create a template to standardise the question papers in my institution. I had previously asked this question but did not receive any answer. Recently, I tried the way as shown in the MWE below. There, I faced the following problems:

  1. In my attempt, the counters for different knowledge-levels for questions and its parts are working fine. However, the marks counter for individual knowledge-levels are misbehaving after some time. After compiling the MWE, I see that at Qn 16.a, the marks counter value for Analysing has not increased, and more surprisingly, the Evaluating marks counter value has decreased! The rests are all messed up Qn 17 onwards.
  2. The marks counter values are flushed outside the question environment. As a result, I cannot use the command \printRBTtable successfully at the end.
  3. In the last row of the tabular inside the \printRBTtable, the command \FPeval is not working, however, \fpeval is working fine.

Please indicate the problem here. I am also open to any alternate solution which solves the linked question.

\documentclass[a5paper, 11pt]{exam}
\usepackage{fp}
\usepackage{array, siunitx}
%
\newcounter{rem}
\newcounter{und}
\newcounter{app}
\newcounter{ana}
\newcounter{eva}
\newcounter{cre}
%
\edef\rem{0}
\edef\und{0}
\edef\app{0}
\edef\ana{0}
\edef\eva{0}
\edef\cre{0}
\edef\x{0}
%
\newcommand{\rqn}[1]{\question[#1]\emph{(Remembering)}%
    \let\x\rem%
    \FPeval{\rem}{clip(\x+#1)}%
    \refstepcounter{rem}
}
\newcommand{\rpart}[1]{\part[#1]\emph{(Remembering)}%
    \let\x\rem%
    \FPeval{\rem}{clip(\x+#1)}%
    \refstepcounter{rem}
}
\newcommand{\rsubpart}[1]{\subpart[#1]\emph{(Remembering)}%
    \let\x\rem%
    \FPeval{\rem}{clip(\x+#1)}%
    \refstepcounter{rem}
}
%
\newcommand{\uqn}[1]{\question[#1]\emph{(Understanding)}%
    \let\x\und%
    \FPeval{\und}{clip(\x+#1)}%
    \refstepcounter{und}
}
\newcommand{\upart}[1]{\part[#1]\emph{(Understanding)}%
    \let\x\und%
    \FPeval{\und}{clip(\x+#1)}%
    \refstepcounter{und}
}
\newcommand{\usubpart}[1]{\subpart[#1]\emph{(Understanding)}%
    \let\x\und%
    \FPeval{\und}{clip(\x+#1)}%
    \refstepcounter{und}
}
%
\newcommand{\aqn}[1]{\question[#1]\emph{(Applying)}%
    \let\x\app%
    \FPeval{\app}{clip(\x+#1)}%
    \refstepcounter{app}
}
\newcommand{\apart}[1]{\part[#1]\emph{(Applying)}%
    \let\x\app%
    \FPeval{\app}{clip(\x+#1)}%
    \refstepcounter{app}
}
\newcommand{\asubpart}[1]{\subpart[#1]\emph{(Applying)}%
    \let\x\app%
    \FPeval{\app}{clip(\x+#1)}%
    \refstepcounter{app}
}
%
\newcommand{\bqn}[1]{\question[#1]\emph{(Analysing)}%
    \let\x\ana%
    \FPeval{\ana}{clip(\x+#1)}%
    \refstepcounter{ana}
}
\newcommand{\bpart}[1]{\part[#1]\emph{(Analysing)}%
    \let\x\ana%
    \FPeval{\ana}{clip(\x+#1)}%
    \refstepcounter{ana}
}
\newcommand{\bsubpart}[1]{\subpart[#1]\emph{(Analysing)}%
    \let\x\ana%
    \FPeval{\ana}{clip(\x+#1)}%
    \refstepcounter{ana}
}
%
\newcommand{\evqn}[1]{\question[#1]\emph{(Evaluating)}%
    \let\x\eva%
    \FPeval{\eva}{clip(\x+#1)}%
    \refstepcounter{eva}
}
\newcommand{\evpart}[1]{\part[#1]\emph{(Evaluating)}%
    \let\x\eva%
    \FPeval{\eva}{clip(\x+#1)}%
    \refstepcounter{eva}
}
\newcommand{\evsubpart}[1]{\subpart[#1]\emph{(Evaluating)}%
    \let\x\eva%
    \FPeval{\eva}{clip(\x+#1)}%
    \refstepcounter{eva}
}
%
\newcommand{\cqn}[1]{\question[#1]\emph{(Creating)}%
    \let\x\eva%
    \FPeval\cre{clip(\x+#1)}%
    \refstepcounter{cre}
}
\newcommand{\cpart}[1]{\part[#1]\emph{(Creating)}%
    \let\x\eva%
    \FPeval\cre{clip(\x+#1)}%
    \refstepcounter{cre}
}
\newcommand{\csubpart}[1]{\subpart[#1]\emph{(Creating)}%
    \let\x\eva%
    \FPeval\cre{clip(\x+#1)}%
    \refstepcounter{cre}
}
%
\newcommand{\printRBTtable}[1]{%
    \begin{center}%
        \def\arraystretch{#1}%
        \begin{tabular}{|l|S|S|}%
            \hline%
            \multicolumn{1}{|c|}{\small\textbf{Knowledge levels}}   &   \multicolumn{1}{c}{\small\textbf{Number of questions}}  &   \multicolumn{1}{|c|}{\small\textbf{Marks}}\\%
            \hline%
            Remembering &   \therem &   \rem\\%
            \hline%
            Understanding   &   \theund &   \und\\%
            \hline%
            Applying    &   \theapp &   \app\\%
            \hline%
            Analysing   &   \theana &   \ana\\%
            \hline
            Evaluating  &   \theeva &   \eva\\%
            \hline
            Creating    &   \thecre &   \cre\\%
            \hline%
            \textbf{Total}  &   \fpeval{\therem+\theund+\theapp+\theana+\theeva+\thecre}    &   \fpeval{\rem+\und+\app+\ana+\eva+\cre} \\%
            \hline
        \end{tabular}
    \end{center}
}
%
\begin{document}
%
\subsubsection*{\centering{GROUP -- A\\ \small Answer any FIVE questions.\normalsize}}\vspace{1ex}
%
\begin{questions}
%
%Qn 1
%
\uqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 2
%
\evqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 3
%
\aqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 4
%
\rqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 5
%
\uqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 6
%
\uqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 7
%
\aqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 8
%
\rqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%
\subsubsection*{\centering{GROUP -- B\\ \small Answer any FOUR questions.\normalsize}}\vspace{1ex}
%
%
%
%Qn 9
%
\evqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 10
%
\uqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 11
%
\aqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 12
%
\bqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 13
%
\bqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 14
%
\uqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%
\subsubsection*{\centering{GROUP -- C\\ \small Answer any TWO questions.\normalsize}}\vspace{1ex}
%
%
%
%Qn 15
%
\question
\begin{parts}
%15.a
\bpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%15.b
\evpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{2ex}
%
%Qn 16
%
\question
\begin{parts}
%Qn 16.a
\bpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%16.b
\apart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{2ex}
%
% Qn 17
%
\question
\begin{parts}
%17.a
\evpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%17.b
\evpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{2ex}
%
%Qn 18
%
\question
\begin{parts}
%18.a
\apart{3}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%18.b
\bpart{7}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{5ex}
%
\printRBTtable{1.25}
%
%
\end{questions}

\printRBTtable{1.25} % % % % \begin{center} \vspace{3ex} \rule{6cm}{0.4pt} \end{center} \end{document}

EDIT:

It only occurred to me after the comment from cfr that the attached MWE is too large. To minimise the effort to comprehend my process, here is a step-by-step description of the code snippets.

  1. I declared six counters for different k-levels to count the number of questions in each level. \newcounter{rem}.
  2. I declared six variables for different k-levels to sum the total marks against each level. \edef\rem{0}.
  3. Declared a temporary variable \edef\x{0}.
  4. For each k-level, defined three macros \rqn, \rpart and \rsubpart to account for question, part and subpart respectively.
  5. Each of the above macros did the followings:
    • took the total marks of the question as an argument.

    • printed the corresponding k-level at the beginning of the question. \newcommand{\rqn}[1]{\question[#1]\emph{(Remembering)}

    • stored the previous value of corresponding k-level marks variable in the temporary variable \x, added the marks of the current question to \x and stored it into the same k-level marks variable. \let\x\rem% \FPeval{\rem}{clip(\x+#1)}

    • increased the corresponding k-level question counter. \refstepcounter{rem}

    • Snippet for entire macro:

\newcommand{\rqn}[1]{\question[#1]\emph{(Remembering)}%
    \let\x\rem%
    \FPeval{\rem}{clip(\x+#1)}%
    \refstepcounter{rem}
}
  1. I have prepared the entire QP with different combinations of the defined macros, and after each question, printed the present value of the total marks corresponding to each k-level: R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre.

  2. Finally, I have printed the \printRBTtable inside and outside of the questions environment.

  • 1
    Can you minimise your example a bit? – cfr Mar 21 '24 at 06:11
  • Unfortunately, I cannot. The problem is appearing for the first time in the 16th Qn and I do not have any idea why! However, if you want, I can definitely add a description of the code snippets in parts. Tell me if that will help. – Subhajit Paul Mar 21 '24 at 06:43
  • @cfr I have edited my question with the descriptions. – Subhajit Paul Mar 21 '24 at 07:15
  • 1
    Something like \edef\x{} is a really, really bad idea. How certain are you you're not overwriting something important? In any case, I'd recommend looking at expl3 and handle this as integers. As far as I can tell, you don't need anything else or are you dealing with fractional marks? I used to use fp. It worked, but life is so much easier now ;). – cfr Mar 21 '24 at 07:36
  • @cfr Thanks for your suggestion. I got to know about fp package from here and used \edef from its documentation. It will be very helpful for me if you please suggest any alternate idea to execute the task in an answer. There may happen to exist fractional marks, but for the time being, I am happy with integers only. – Subhajit Paul Mar 21 '24 at 08:47
  • @cfr As a matter of fact, I tried the same code replacing \edef by \def, but the same result continued. – Subhajit Paul Mar 21 '24 at 08:50
  • In 2011, fp was a good recommendation. You can still use it. It's just there are better options available these days. – cfr Mar 21 '24 at 21:55
  • \def and \edef define things locally. \begin{parts} forms a group. Hence the original definitions are restored at the end of that group. So the points for evaluation or whatever increase inside the group and then get reset to whatever they were at the start. You'd need \gdef or \xdef for global effect. But, again, be careful with these. It would be better in your preamble to use \newcommand\x{0}. Then you can say \edef\x{} relatively safely. – cfr Mar 21 '24 at 22:05

1 Answers1

2

To just make the existing code work, you only need to make the definitions of \rem etc. global. Because parts creates a local group and \FPeval only changes the values locally, the points do not accumulate when parts is used. They increase within the group but are then reset to the values they had at the beginning when the group ends.

For example,

\newcommand{\rqn}[1]{\question[#1]\emph{(Remembering)}%
  \let\x\rem
  \FPeval{\remtmp}{clip(\x+#1)}%
  \global\let\rem\remtmp
  \refstepcounter{rem}%
}

This changes \rem globally, so the added points survive \end{parts}.

This issue doesn't affect the counters because LaTeX always sets counters globally.

Complete code:

\documentclass[a5paper, 11pt]{exam}
\usepackage{fp}
\usepackage{array, siunitx}
%
\newcounter{rem}
\newcounter{und}
\newcounter{app}
\newcounter{ana}
\newcounter{eva}
\newcounter{cre}
%
\newcommand\rem{0}
\newcommand\und{0}
\newcommand\app{0}
\newcommand\ana{0}
\newcommand\eva{0}
\newcommand\cre{0}
\newcommand\x{0}
\edef\rem{0}
\edef\und{0}
\edef\app{0}
\edef\ana{0}
\edef\eva{0}
\edef\cre{0}
\edef\x{0}
%
\newcommand{\rqn}[1]{\question[#1]\emph{(Remembering)}%
  \let\x\rem
  \FPeval{\remtmp}{clip(\x+#1)}%
  \global\let\rem\remtmp
  \refstepcounter{rem}%
}
\newcommand{\rpart}[1]{\part[#1]\emph{(Remembering)}%
  \let\x\rem
  \FPeval{\remtmp}{clip(\x+#1)}%
  \global\let\rem\remtmp
  \refstepcounter{rem}%
}
\newcommand{\rsubpart}[1]{\subpart[#1]\emph{(Remembering)}%
  \let\x\rem
  \FPeval{\remtmp}{clip(\x+#1)}%
  \global\let\rem\remtmp
  \refstepcounter{rem}%
}
%
\newcommand{\uqn}[1]{\question[#1]\emph{(Understanding)}%
  \let\x\und
  \FPeval{\undtmp}{clip(\x+#1)}%
  \global\let\und\undtmp
  \refstepcounter{und}%
}
\newcommand{\upart}[1]{\part[#1]\emph{(Understanding)}%
  \let\x\und
  \FPeval{\undtmp}{clip(\x+#1)}%
  \global\let\und\undtmp
  \refstepcounter{und}%
}
\newcommand{\usubpart}[1]{\subpart[#1]\emph{(Understanding)}%
  \let\x\und
  \FPeval{\undtmp}{clip(\x+#1)}%
  \global\let\und\undtmp
  \refstepcounter{und}%
}
%
\newcommand{\aqn}[1]{\question[#1]\emph{(Applying)}%
  \let\x\app
  \FPeval{\apptmp}{clip(\x+#1)}%
  \global\let\app\apptmp
  \refstepcounter{app}%
}
\newcommand{\apart}[1]{\part[#1]\emph{(Applying)}%
  \let\x\app
  \FPeval{\apptmp}{clip(\x+#1)}%
  \global\let\app\apptmp
  \refstepcounter{app}%
}
\newcommand{\asubpart}[1]{\subpart[#1]\emph{(Applying)}%
  \let\x\app
  \FPeval{\apptmp}{clip(\x+#1)}%
  \global\let\app\apptmp
  \refstepcounter{app}%
}
%
\newcommand{\bqn}[1]{\question[#1]\emph{(Analysing)}%
  \let\x\ana
  \FPeval{\anatmp}{clip(\x+#1)}%
  \global\let\ana\anatmp
  \refstepcounter{ana}%
}
\newcommand{\bpart}[1]{\part[#1]\emph{(Analysing)}%
  \let\x\ana
  \FPeval{\anatmp}{clip(\x+#1)}%
  \global\let\ana\anatmp
  \refstepcounter{ana}%
}
\newcommand{\bsubpart}[1]{\subpart[#1]\emph{(Analysing)}%
  \let\x\ana
  \FPeval{\anatmp}{clip(\x+#1)}%
  \global\let\ana\anatmp
  \refstepcounter{ana}%
}
%
\newcommand{\evqn}[1]{\question[#1]\emph{(Evaluating)}%
  \let\x\eva
  \FPeval{\evatmp}{clip(\x+#1)}%
  \global\let\eva\evatmp
  \refstepcounter{eva}%
}
\newcommand{\evpart}[1]{\part[#1]\emph{(Evaluating)}%
  \let\x\eva
  \FPeval{\evatmp}{clip(\x+#1)}%
  \global\let\eva\evatmp
  \refstepcounter{eva}%
}
\newcommand{\evsubpart}[1]{\subpart[#1]\emph{(Evaluating)}%
  \let\x\eva
  \FPeval{\evatmp}{clip(\x+#1)}%
  \global\let\eva\evatmp
  \refstepcounter{eva}%
}
%
\newcommand{\cqn}[1]{\question[#1]\emph{(Creating)}%
  \let\x\cre
  \FPeval\cretmp{clip(\x+#1)}%
  \global\let\cre\cretmp
  \refstepcounter{cre}%
}
\newcommand{\cpart}[1]{\part[#1]\emph{(Creating)}%
  \let\x\cre
  \FPeval\cretmp{clip(\x+#1)}%
  \global\let\cre\cretmp
  \refstepcounter{cre}%
}
\newcommand{\csubpart}[1]{\subpart[#1]\emph{(Creating)}%
  \let\x\cre
  \FPeval\cretmp{clip(\x+#1)}%
  \global\let\cre\cretmp
  \refstepcounter{cre}%
}
%
\newcommand{\printRBTtable}[1]{%
  \begin{center}%
    \def\arraystretch{#1}%
    \begin{tabular}{|l|S|S|}%
      \hline%
      \multicolumn{1}{|c|}{\small\textbf{Knowledge levels}}   &   \multicolumn{1}{c}{\small\textbf{Number of questions}}  &   \multicolumn{1}{|c|}{\small\textbf{Marks}}\\%
      \hline%
      Remembering &   \therem &   \rem\\%
      \hline%
      Understanding   &   \theund &   \und\\%
      \hline%
      Applying    &   \theapp &   \app\\%
      \hline%
      Analysing   &   \theana &   \ana\\%
      \hline
      Evaluating  &   \theeva &   \eva\\%
      \hline
      Creating    &   \thecre &   \cre\\%
      \hline%
      \textbf{Total}  &   \fpeval{\therem+\theund+\theapp+\theana+\theeva+\thecre}    &   \fpeval{\rem+\und+\app+\ana+\eva+\cre} \\%
      \hline
    \end{tabular}
  \end{center}
}
%
\begin{document}
%
\subsubsection*{\centering{GROUP -- A\\ \small Answer any FIVE questions.\normalsize}}\vspace{1ex}
%
\begin{questions}
%
%Qn 1
%
\uqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 2
%
\evqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 3
%
\aqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 4
%
\rqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 5
%
\uqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 6
%
\uqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 7
%
\aqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 8
%
\rqn{2}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%
\subsubsection*{\centering{GROUP -- B\\ \small Answer any FOUR questions.\normalsize}}\vspace{1ex}
%
%
%
%Qn 9
%
\evqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 10
%
\uqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 11
%
\aqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 12
%
\bqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 13
%
\bqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%Qn 14
%
\uqn{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%
%
\subsubsection*{\centering{GROUP -- C\\ \small Answer any TWO questions.\normalsize}}\vspace{1ex}
%
%
%
%Qn 15
%
\question
\begin{parts}
%15.a
\bpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%15.b
\evpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{2ex}
%
%Qn 16
%
\question
\begin{parts}
%Qn 16.a
\bpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%16.b
\apart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{2ex}
%
% Qn 17
%
\question
\begin{parts}
%17.a
\evpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%17.b
\evpart{5}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{2ex}
%
%Qn 18
%
\question
\begin{parts}
%18.a
\apart{3}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
%18.b
\bpart{7}\droppoints
R:\rem, U:\und, A1:\app, A2: \ana, E: \eva, C: \cre
\end{parts}\vspace{5ex}
%
\printRBTtable{1.25}
%
%
\end{questions}

Note, however, that it is not good practice to put formatting into the argument of sectioning commands. It would be better to make \subsubsection or whatever do what you want.

The use of non-stretching vertical spacing will also give you poorer page breaks. You seem to want to suppress all paragraph breaks. I'm not sure why, but there is probably an easier and more effective approach. (It is not entirely effective here and it isn't especially easy, from a coding and legibility point of view.

However, I would probably do something using the stuff in LaTeX 3 and, especially if this is for other people to use (but even if it isn't), I would avoid using cryptic abbreviations for commands. Even where you establish these are safe, they make code harder to read etc. Anyway, I don't know what you're doing exactly, but here's something by way of an example.

\documentclass[a5paper, 11pt]{exam}
\usepackage{array, siunitx}
\usepackage{booktabs}
\usepackage[T1]{fontenc}
\ExplSyntaxOn
\prop_new:N \l__subhajitpaul_qntypes_prop
\seq_new:N \l__subhajitpaul_qntypes_seq
\prop_set_from_keyval:Nn \l__subhajitpaul_qntypes_prop
{
  ana = Analysing,
  app = Applying,
  cre = Creating,
  eva = Evaluating,
  rem = Remembering,
  und = Understanding,
}
\prop_map_inline:Nn \l__subhajitpaul_qntypes_prop
{
  \int_gzero_new:c { g__subhajitpaul_#1_int }
  \int_gzero_new:c { g__subhajitpaul_#1pts_int }
  \tl_set:cn { l__subhajitpaul_#1_tl } { #2 }
  \cs_new_protected:cpn { #1 } { \int_to_arabic:v { g__subhajitpaul_#1pts_int } }
  \seq_put_right:Nn \l__subhajitpaul_qntypes_seq { #1 }
}

\NewDocumentCommand \typequestion { mm } { \question[#1]\emph{ \tl_use:c { l__subhajitpaul_#2_tl } } \int_gincr:c { g__subhajitpaul_#2_int } \int_gadd:cn { g__subhajitpaul_#2pts_int } { #1 } } \NewDocumentCommand \typepart { mm } { \part[#1]\emph{\tl_use:c { l__subhajitpaul_#2_tl }} \int_gincr:c { g__subhajitpaul_#2_int } \int_gadd:cn { g__subhajitpaul_#2pts_int } { #1 } } \NewDocumentCommand \typesubpart { mm } { \subpart[#1]\emph{ \tl_use:c { l__subhajitpaul_#2_tl } } \int_gincr:c { g__subhajitpaul_#2_int } \int_gadd:cn { g__subhajitpaul_#2pts_int } { #1 } }

\NewDocumentCommand \printRBTtable { O {1} } { \begin{center}% \def\arraystretch{#1}% \begin{tabular}{lSS} \toprule \multicolumn{1}{c}{\small\textbf{Knowledge ~ levels}} & \multicolumn{1}{c}{\small\textbf{Number ~ of ~ questions}} & \multicolumn{1}{c}{\small\textbf{Marks}}\ \midrule \l__subhajitpaul_rem_tl & \int_to_arabic:n { \g__subhajitpaul_rem_int } & \int_to_arabic:n { \g__subhajitpaul_rempts_int } \ \l__subhajitpaul_und_tl & \int_to_arabic:n { \g__subhajitpaul_und_int } & \int_to_arabic:n { \g__subhajitpaul_undpts_int } \ \l__subhajitpaul_app_tl & \int_to_arabic:n { \g__subhajitpaul_app_int } & \int_to_arabic:n { \g__subhajitpaul_apppts_int } \ \l__subhajitpaul_ana_tl & \int_to_arabic:n { \g__subhajitpaul_ana_int } & \int_to_arabic:n { \g__subhajitpaul_anapts_int } \ \l__subhajitpaul_eva_tl & \int_to_arabic:n { \g__subhajitpaul_eva_int } & \int_to_arabic:n { \g__subhajitpaul_evapts_int } \ \l__subhajitpaul_cre_tl & \int_to_arabic:n { \g__subhajitpaul_cre_int } & \int_to_arabic:n { \g__subhajitpaul_crepts_int } \ \cmidrule(lr){1-3} \textbf{Total} & \int_to_arabic:n { \g__subhajitpaul_rem_int + \g__subhajitpaul_und_int + \g__subhajitpaul_app_int + \g__subhajitpaul_ana_int + \g__subhajitpaul_eva_int + \g__subhajitpaul_cre_int } & \int_to_arabic:n{ \g__subhajitpaul_rempts_int + \g__subhajitpaul_undpts_int + \g__subhajitpaul_apppts_int + \g__subhajitpaul_anapts_int + \g__subhajitpaul_evapts_int + \g__subhajitpaul_crepts_int } \ \bottomrule \end{tabular} \end{center} } \NewDocumentCommand \printQnData {} { \seq_clear:N \l_tmpa_seq \seq_map_inline:Nn \l__subhajitpaul_qntypes_seq { \seq_put_right:Ne \l_tmpa_seq { \text_titlecase_first:n { ##1 } : ~ \int_to_arabic:v { g__subhajitpaul_##1pts_int } \textbar \int_to_arabic:v { g__subhajitpaul_##1_int } } } {\scriptsize \seq_use:Nn \l_tmpa_seq { , ~ } } } \ExplSyntaxOff \begin{document}

\subsubsection*{\centering{GROUP -- A\ \small Answer any FIVE questions.\normalsize}}\vspace{1ex}

\begin{questions} %Qn 1 \typequestion{2}{und}\droppoints \printQnData

%Qn 2 \typequestion{2}{eva}\droppoints \printQnData

%Qn 3 \typequestion{2}{app}\droppoints \printQnData

%Qn 4 \typequestion{2}{rem}\droppoints \printQnData

%Qn 5 \typequestion{2}{und}\droppoints \printQnData

%Qn 6 \typequestion{2}{und}\droppoints \printQnData

%Qn 7 \typequestion{2}{app}\droppoints \printQnData

%Qn 8 \typequestion{2}{rem}\droppoints \printQnData

\subsubsection*{\centering{GROUP -- B\ \small Answer any FOUR questions.\normalsize}}\vspace{1ex}

%Qn 9 \typequestion{5}{eva}\droppoints \printQnData

%Qn 10 \typequestion{5}{und}\droppoints \printQnData

%Qn 11 \typequestion{5}{app}\droppoints \printQnData

%Qn 12 \typequestion{5}{ana}\droppoints \printQnData

%Qn 13 \typequestion{5}{ana}\droppoints \printQnData

%Qn 14 \typequestion{5}{und}\droppoints \printQnData

\subsubsection*{\centering{GROUP -- C\ \small Answer any TWO questions.\normalsize}}\vspace{1ex}

%Qn 15 \question \begin{parts} %15.a \typepart{5}{ana}\droppoints \printQnData %15.b \typepart{5}{eva}\droppoints \printQnData \end{parts}

%Qn 16 \question \begin{parts} %Qn 16.a \typepart{5}{ana}\droppoints \printQnData %16.b \typepart{5}{app}\droppoints \printQnData \end{parts}

% Qn 17 \question \begin{parts} %17.a \typepart{5}{eva}\droppoints \printQnData %17.b \typepart{5}{eva}\droppoints \printQnData \end{parts}

%Qn 18 \question \begin{parts} %18.a \typepart{3}{app}\droppoints \printQnData %18.b \typepart{7}{ana}\droppoints \printQnData \end{parts}

\printRBTtable[1.25]

\end{questions}

\printRBTtable \end{document}

I won't post the output because my images suck right now due to an Okular bug and, really, the result isn't that interesting in this case.

cfr
  • 198,882
  • Thank you so much for taking the time and pain to repair the entire code. Simultaneously, my apologies for replying late. I was out of station for a couple of days without the access to my system. I have 4 comments/follow-up questions. – Subhajit Paul Mar 24 '24 at 20:02
  • 1. The first code is working fine. Sincerely grateful for that. – Subhajit Paul Mar 24 '24 at 20:03
  • 2. I do not usually put any formatting into the argument of sectioning commands. I designed this template (without RBT) a long ago, and the error has propagated since then. Thanks for pointing that out. – Subhajit Paul Mar 24 '24 at 20:03
  • 3. The LaTeX3 solution is not working. Showing 'Undefined control sequence' error for the \printQnData. Could it be because I am using 2023 version TeXLive? – Subhajit Paul Mar 24 '24 at 20:03
  • 4. Please suggest some resources to learn more about \ExplSyntax. – Subhajit Paul Mar 24 '24 at 20:03
  • Update to comment 3: I suspected the correct reason. It is working fine with the latest distribution. Thanks again. – Subhajit Paul Mar 24 '24 at 20:18
  • 1
    @SubhajitPaul There have been a lot of changes to LaTeX3 and it is sometimes hard to keep track of what's new, so sorry I didn't realise to warn about that. You could probably also change e.g. \seq_put_right:Ne to \seq_put_right:Nx and have it work with older versions. They are deprecating x in favour of e, but they were probably still using x in non-updates TL 2023. – cfr Mar 24 '24 at 20:53
  • 1
    @SubhajitPaul (4) is trickier. The main reference for expl3 syntax is in interface3.pdf. However, it is not easy to start there. I think I started with stuff on TeX SE, but https://www.alanshawn.com/latex3-tutorial/ has been recommended. However, it has not been updated with some of the recent changes e.g. it doesn't mention the e versus x thing as far as I can tell. I hoped that the new LaTeX Companion would include something both digestible and more-or-less current, but it seems to restrict itself to higher-level stuff and has quite limited coverage even of that. :( – cfr Mar 24 '24 at 21:05