2

I am trying to write a template for writing tests and homework for math classes in the familar format:
1) Given . . .
a) question . . .
b) question . . .
Here is what I have tried:

\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}  

This compiles, but gives
1) Given . . .
1) question . . .
Any attempt I have made to get the subquestion in alphabetic form throws errors.

Error 1 is:

! 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?}

Error 2 is:

! 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?}

Trying the code called "tests" suggests that the counter is working properly if not called within \testquestionpart.

I tried

\newcommand\testquestionpart[2]{\begin{minipage}[t]{\textwidth}\stepcounter{partnum}\alph{partnum)}\quad(#1 pts.)\quad#2\end{minipage}}

and got

! 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

The proper syntax is \alph{partnum}, not \alph{\thepartnum}. I also show (in commented text) the use of \roman{partnum} or, in the style originally tried by the OP, \romannumeral\value{partnum}. This latter syntax is TeX, whereas the former two are LaTeX.

EDIT to implement solution into \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} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.