Good day,
I'm making a customized grading table for the exam class. In particular, I want to delete the first column and append a new one to the end. It seemed that creating a new table altogether would be the way to go.
After searching stackexchange I have found this question, which modifies \part
environment and writes every question part and its amount of points to an auxiliary file from which they are placed into a table.
I was able to change it to my liking, except for the way scores are displayed.
Proposed solution uses question parts by default, while I would like to see only the totals for every question.
Hence the question about counting totals for every \question
.
My current code (mostly a hackjob of what @Andrew proposed) is as follows:
% redefine \question command to be \myquest
\appto\questions{\let\examquestion\question\let\question\myquestion}
% redefine \part command to be \mypart
\appto\parts{\let\exampart\part\let\part\mypart}
\makeatletter
\ExplSyntaxOn
% this will become a sequence of the part numbers and scores
% like: 1a,10,1b,8,1c,9,2a,6,2b,8,3,12,4,14, ...
\clist_new:N \g_grades_clist
\clist_new:N \g_grades_aux_clist
\int_new:N \g_questions_row_int
\int_new:N \g_scores_row_int
\int_new:N \g_spaces_row_int
\int_new:N \g_grade_total_int
\int_new:N \g_number_of_scores_int
\int_new:N \g_total_questions
% add a question/part number and score to \g_grades_clist
\cs_new:Nn \__add_to_grades_list:nn {
\clist_gput_right:Nx \g_grades_clist { #1 }
\clist_gput_right:Nx \g_grades_clist { #2 }
}
\NewDocumentCommand\myquestion{o}{
\IfNoValueTF{#1}{\examquestion}{
% don't do anything special inside solutions
\if@insolution\examquestion[#1]
\else\examquestion[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { Auf.~\arabic{question} } { #1 }
\fi
}
}
\NewDocumentCommand\mypart{o}{
\IfNoValueTF{#1}{\exampart}{
% don't do anything special inside solutions
\if@insolution\exampnrt[#1]
\else\exampart[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { Auf.~\arabic{question}\alph{partno} } { #1 }
\fi
}
}
\AtEndDocument{
\iow_now:cx { @auxout } {
\token_to_str:N \SetGradeList { \g_grades_clist } ^^J
}
}
% set grade list from the aux file
\NewDocumentCommand\SetGradeList{m}{\clist_gset:Nn \g_grades_aux_clist {#1}}
% Draw quesions
\cs_new:Nn \__add_questions_to_grade_table: {
\int_gincr:N \g_questions_row_int
\clist_item:Nn \g_grades_aux_clist {2*\g_questions_row_int-1} \int_compare:nT {\g_questions_row_int < (\g_number_of_scores_int)} { & \__add_questions_to_grade_table: }
}
% Draw scores
\cs_new:Nn \__add_scores_to_grade_table: {
\int_gincr:N \g_scores_row_int
\clist_item:Nn \g_grades_aux_clist {2*\g_scores_row_int} \int_compare:nT {\g_scores_row_int < \g_number_of_scores_int} { & \__add_scores_to_grade_table: }
}
% Draw empty spaces
\cs_new:Nn \__add_spaces_to_grade_table: {
\int_gincr:N \g_spaces_row_int
\int_compare:nT {\g_spaces_row_int < \g_number_of_scores_int} { & \__add_spaces_to_grade_table: }
}
\NewDocumentCommand\PrintGradeTable{}{% the new grade table
\int_set:Nn \g_number_of_scores_int {(\clist_count:N \g_grades_aux_clist)/2}
\int_gzero:N \g_questions_row_int % a counter to step through the rows
\int_gzero:N \g_scores_row_int % a counter to step through the rows
\int_gzero:N \g_spaces_row_int % a counter to step through the rows
% create the grade table
\renewcommand{\arraystretch}{2}
\begin{tabular}{|c|*{\int_eval:n {(\clist_count:N \g_grades_aux_clist)/2-1}}{c|}c}
\hline
\int_compare:nT {\g_number_of_scores_int>0} { \__add_questions_to_grade_table: } & \multicolumn{1}{l|}{\hphantom{A}~\large\textbf{Note}~\hphantom{A}} \\
\hline
\int_compare:nT {\g_number_of_scores_int>0} { \__add_scores_to_grade_table: } & \\
\hline
\int_compare:nT {\g_number_of_scores_int>0} { \__add_spaces_to_grade_table: } & \multicolumn{1}{l|}{} \\
\hline
\end{tabular}
}
\ExplSyntaxOff
Here is a visual representation of what the code produces:
Every exercise in the exam is of the following format:
\question
\begin{parts}
\part
\end{parts}
So every question always has parts.
What would be the easiest way to do sum up the totals for the parts?