0

How do I take the output from \numqinrange and use it in my own custom command?

I have created a custom grading table for the Exam Class. This allows me to add custom elements to the table that we use for grading our exam. Everything in my exam latex file is automatic (question totals, number of points per section, etc.), thereby leading to less user-error in making exams in the future. However, currently, in order to use my custom \GradingTable command, you must enter the start and end of the ranges of questions. How can I make this automatic? Since \numqinrange outputs the exact numbers I need, it would be nice to get this into the \GradingTable command.

I have attempted many solutions to this including \expandafter, but I am not familiar enough with LaTeX to make it work.

Here is a minimum working example:


\documentclass[12pt, addpoints]{exam}

% Grading Table Packages
\usepackage{makecell}
\usepackage{adjustbox}
\usepackage{forloop}
\usepackage{xfp}

\begin{document}

\begin{questions}

\section*{Section A}
\label{section-a}
\begingradingrange{seca}
\question[4] Question Text
\question[7] Question Text
\endgradingrange{seca}

\section*{Section B}
\label{section-b}
\begingradingrange{secb}
\question[2] Question Text
\question[8] Question Text
\endgradingrange{secb}

\end{questions}

\newcounter{QNum}
\newcommand{\InnerContent}[2]{
    \forloop{QNum}{#1}{\value{QNum} < \fpeval{#2+1}}
    {   \\\hline
        $\theQNum$ &
        \pointsofquestion{\value{QNum}} &
        \makecell{\vspace{-1mm} \\ ------ \\ \vspace{-1mm}} &
        \makecell{\vspace{-1mm} \\ ------ \\ \vspace{-1mm}}}
}

\newcommand{\GradingTable}[3]{
\adjustbox{valign=t}{
\begin{tabular}{|c|c|c|c|} \hline
    \multicolumn{4}{|c|}{#1} \\\hline
    Q & P & M1 & M2%
    \InnerContent{#2}{#3}
    \\\hline
\end{tabular}
}
}

% These numbers: "1,2,3,4" are hard coded. How can I use the "numinrange" to automate this?
\GradingTable{Section A}{1}{2}
\GradingTable{Section B}{3}{4}

% This does not work
% \GradingTable{Section A}{1}{\numqinrange{seca}}


\end{document}

enter image description here

Any and all help is appreciated. Thank you.

Lloyd

1 Answer 1

0

I rewrote a bit \InnerContent so now you can use \GradingTable{<title of the table>}{<range>}.

For example, \GradingTable{Section A}{seca} will generate the first table, where the question numbers within the range will be filled in automatically.

The first time it will be compiled three times to build the tables.

a

(Added a question and the starting question number for testing purposes)

\documentclass[12pt, addpoints]{exam}

% Grading Table Packages
\usepackage{makecell}
\usepackage{adjustbox}
\usepackage{forloop}

\newcounter{QNum}
%% ************************************  added
\makeatletter
\newcommand{\InnerContent}[1]{% #1 => range name
\@ifundefined{range@#1@firstq}{\\\hline &&&}{%      
    \forloop{QNum}{\csname range@#1@firstq\endcsname}{\numexpr\value{QNum}-1  <\csname range@#1@lastq\endcsname}
    { \\\hline
        \theQNum &
        \pointsofquestion{\value{QNum}} &
        \makecell{\vspace{-1mm} \\ ------ \\ \vspace{-1mm}} &
        \makecell{\vspace{-1mm} \\ ------ \\ \vspace{-1mm}}
    }}
        }   
\makeatother
%%***********************************************

\newcommand{\GradingTable}[2]{% #1 => table title, #2 => range name
\adjustbox{valign=t}{%
    \begin{tabular}{|c|c|c|c|} \hline
        \multicolumn{4}{|c|}{#1} \\\hline
        Q & P & M1 & M2%
        \InnerContent{#2}
        \\\hline
    \end{tabular}
                }
                        }

\begin{document}
    
\begin{questions}
    
    \addtocounter{question}{5} % added for testing
    \section*{Section A}
    \label{section-a}
    \begingradingrange{seca}
    \question[4] Question Text 1
    \question[7] Question Text 2
    \endgradingrange{seca}

    
    \section*{Section B}
    \label{section-b}
    \begingradingrange{secb}
    \question[2] Question Text 3
    \question[8] Question Text 4
    \question[10] Question Text 5  % added for testing
    \endgradingrange{secb}      

\end{questions}

\GradingTable{Section A}{seca}

\bigskip

\GradingTable{Section B}{secb}  
    
\end{document}
2
  • Thank you! This is perfect. I am still trying to understand the @references. Are those from the exam class?
    – Lloyd
    Commented Jul 5, 2021 at 8:03
  • @Lloyd (You wrote 90%!) Usually a macro with @ in their name is an internal macro command of a class or package. See the comments in tex.stackexchange.com/questions/239305/latex-variables-varname Commented Jul 5, 2021 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .