在考试课中,我们可以使用命令 生成评分表\gradetable
。对于第一次编译,此命令生成消息Run \LaTeX{} again to produce the table
,并在第二次编译中生成成绩表。我想将第一次编译的此消息个性化,例如“成绩表将在第二次编译中生成”。我在文件中发现exam.cls
该消息是由以下宏生成的:
\def\check@secondrun#1{%
% The function \ii@gtable already made sure that this isn't the
% first run of latex. To do a table indexed by pages, though, we
% have to also make sure it's not the second run of latex.
% We get here from \find@prange; the argument is either ``v'' or
% ``h''.
% Check that there's enough info from the .aux file to do a page
% indexed grade table. If so, call \tbl@v@or@h{#1}:
\@ifundefined{pointsonpage@\romannumeral
\csname lastpage@withpoints\endcsname}%
{\@ifundefined{bonuspointsonpage@\romannumeral
\csname lastpage@withbonuspoints\endcsname}%
{\ClassWarning{exam}{%
You must run LaTeX again to produce the table.\MessageBreak}%
\fbox{Run \LaTeX{} again to produce the table}%
}%
{\tbl@v@or@h{#1}%
}%
}%
{\tbl@v@or@h{#1}%
}%
}% check@secondrun
那么我怎样才能改变其中的信息呢?
我给出的宏是错误的
产生该消息的宏如下:
\def\ii@gtable#1[#2]{%
% We get here from \i@gtable.
% We make sure the user said \addpoints, and then make sure
% that this isn't the first run of LaTeX (by checking that
% \exam@numpoints is defined). If both of those are OK,
% we go to \find@p@or@q@range to see whether we're doing a table
% indexed by questions or by pages.
\if@addpoints
\@ifundefined{exam@numpoints}%
{\ClassWarning{exam}%
{%
You must run LaTeX again to produce the
table.\MessageBreak
}%
\fbox{Run \LaTeX{} again to produce the table}%
}%
{\find@p@or@q@range{#1}{#2}}%
\else
\ClassError{exam}{%
You must give the command \protect\addpoints\MessageBreak
\space\space in order to create a grade table.\MessageBreak
}{%
If you don't give the command \protect\addpoints\MessageBreak
\space\space then we're not keeping track of point values.
\MessageBreak
}%
\fi
}% ii@gtable
根据给出的答案,我给出了解决方案的 MWE:
\documentclass[12pt,addpoints]{exam}
\usepackage{etoolbox}
\makeatletter
\patchcmd\ii@gtable
{Run \LaTeX{} again to produce the table}
{The Grades' table will be produced in the second compilation}
{}{}
\makeatother
\begin{document}
\pagestyle{empty}
\gradetable
\begin{questions}
\question A question
\end{questions}
\end{document}
及其编译,其中可以看到适当的消息:
答案1
实际上,你错了。你看到的消息是由\ii@gtable
宏生成的。要更改消息,你可以重新定义\ii@gtable
宏:
\makeatletter
\def\ii@gtable#1[#2]{%
\if@addpoints
\@ifundefined{exam@numpoints}%
{\ClassWarning{exam}%
{%
You must run LaTeX again to produce the
table.\MessageBreak
}%
\fbox{The Grades' table will be produced in the second compilation}%
}%
{\do@table{#1}{#2}}%
\else
\ClassError{exam}{%
You must give the command \protect\addpoints\MessageBreak
\space\space in order to create a grade table.\MessageBreak
}{%
If you don't give the command \protect\addpoints\MessageBreak
\space\space then we're not keeping track of point values.
\MessageBreak
}%
\fi
}% ii@gtable
\makeatother
或者,为了减少代码混乱,你可以对其进行修补:
\usepackage{etoolbox}
\makeatletter
\patchcmd\ii@gtable
{Run \LaTeX{} again to produce the table}
{The Grades' table will be produced in the second compilation}
{}{}
\makeatother