![命令 \alph{counter} 编译错误](https://linux22.com/image/321799/%E5%91%BD%E4%BB%A4%20%5Calph%7Bcounter%7D%20%E7%BC%96%E8%AF%91%E9%94%99%E8%AF%AF.png)
我正在尝试编写一个模板,用于以熟悉的格式编写数学课的测试和家庭作业:
1)给定......
a)问题......
b)问题......
这是我尝试过的:
\documentclass[12pt]{amsart}%
\setcounter{errorcontextlines}{1000}
%
\begin{document}
%
\newcounter{probnum}
\newcounter{partnum}[probnum]
\newcommand\testquestion[2]{\begin{minipage}[t]{\textwidth}\stepcounter{probnum}\theprobnum)\quad(#1 pts.)\quad#2\end{minipage}}
\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\thepartnum)\quad(#1 pts.)\quad#2\end{minipage}}% compiles
%\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\alph{\thepartnum)}\quad(#1 pts.)\quad#2\end{minipage}}% error 1
%\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\alph{\value{\thepartnum}})\quad(#1 pts.)\quad#2\end{minipage}}% error 2
%
\testquestion{2}{An investment of \$10,000 is made in a stock portfolio, which doubles in value after 7 years.
Using the equation for continuous compounding $ A = P e^{rt} $:}
\par\vspace*{10mm}
%
% Tests
\stepcounter{partnum}
\thepartnum
\stepcounter{partnum}
\thepartnum
\stepcounter{partnum}
\thepartnum\\
%\alph{\thepartnum}% error 1
%\alph{\value{\thepartnum}}% error 2
% End Tests
%
\testquestionpart{2}{At what rate is the investment growing?}
%
\end{document}
这可以编译,但会给出
1) 给定...
1) 问题...
我所做的任何以字母形式获取子问题的尝试都会引发错误。
错误 1 是:
! Missing number, treated as zero. <to be read again> \c@4) \@alph #1->\ifcase #1 \or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k... \testquestionpart ...partnum}\alph {\thepartnum )} \quad (#1 pts.)\quad #2\en... l.30 ...}{At what rate is the investment growing?}
错误2是:
! Missing \endcsname inserted. <to be read again> \c@4 \alph #1->\expandafter \@alph \csname c@#1 \endcsname \testquestionpart ...\alph {\value {\thepartnum }} )\quad (#1 pts.)\quad #2\e... l.30 ...}{At what rate is the investment growing?}
尝试名为“测试”的代码表明,如果未在内调用,计数器则正常工作\testquestionpart
。
我试过
\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\alph{partnum)}\quad(#1 pts.)\quad#2\end{minipage}}
并得到
! Missing number, treated as zero.
<to be read again>
\c@partnum)
\@alph #1->\ifcase #1
\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k...
\testquestionpart ...ter {partnum}\alph {partnum)}
\quad (#1 pts.)\quad #2\en...
l.30 ...}{At what rate is the investment growing?}
答案1
正确的语法是\alph{partnum}
,而不是\alph{\thepartnum}
。我还展示了(在注释文本中) 或 的用法\roman{partnum}
,这是 OP 最初尝试的样式,\romannumeral\value{partnum}
。后一种语法是 TeX,而前两种是 LaTeX。
编辑以实施解决方案\testquestionpart
。
\documentclass[12pt]{amsart}%
\setcounter{errorcontextlines}{1000}
%
\begin{document}
%
\newcounter{probnum}
\newcounter{partnum}[probnum]
\newcommand\testquestion[2]{\begin{minipage}[t]{\textwidth}%
\stepcounter{probnum}\theprobnum)\quad(#1 pts.)\quad#2\end{minipage}}
\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}%
\stepcounter{partnum}\alph{partnum})\quad%
(#1 pts.)\quad#2\end{minipage}}% compiles
%\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\alph{\thepartnum)}\quad(#1 pts.)\quad#2\end{minipage}}% error 1
%\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\alph{\value{\thepartnum}})\quad(#1 pts.)\quad#2\end{minipage}}% error 2
%
\testquestion{2}{An investment of \$10,000 is made in a stock
portfolio, which doubles in value after 7 years.
Using the equation for continuous compounding $ A = P e^{rt} $:}
\par\vspace*{10mm}
%
% Tests
%\alph{partnum}% WORKS
%\romannumeral\value{partnum}% WORKS
%\roman{partnum}% WORKS
%\alph{\thepartnum}% error 1
%\alph{\value{\thepartnum}}% error 2
% End Tests
%
\testquestionpart{2}{At what rate is the investment growing?}
\testquestionpart{3}{Is this working?}
%
\end{document}