Short summary:
I would like to create a command that creates a new command each time it is called, based on a counter. Then I could use PGF's for-loops to go through the sequence of commands. The non-working example is:
\newcounter{group}
\newcommand{\defgroup}[1]{
\stepcounter{group}
\newcommand{\problem\Alph{group}}[0]{#1}
}
\defgroup{$1*1=$}
\defgroup{$1+1=$}
However, it turns out you cannot do \newcommand{\problem\Alph{group}}
. Is there a way to do this?
Longer explanation:
I am writing a jigsaw activity, which requires a sequence of related versions of a document (A,B,C,D,E), each with a different problem. This is currently done as follows (MWE)
\documentclass[12pt]{exam}
\newcounter{group}
\newcommand{\groupname}{\stepcounter{group}\textbf{\Huge \Alph{group}\\}}
\newcommand{\newgroup}[1]{
\newpage
\groupname
\setcounter{section}{0}
\section{Here is your problem!}
\begin{center}
#1
\end{center}
\section{Now copy down other groups problems!}
}
\begin{document}
\newgroup{$1+1=$}
\newgroup{$1*1=$}
\newgroup{$1^1=$}
\end{document}
What I would like to do is be able to to reference the other groups in the second section of each version. Thus, I want group A's document to look like:
A
Here is your problem: 1+1 =
Now copy down other groups problems:
B: 1*1=
C: 1^1 =
\expandafter\newcommand\csname problem\Alph{group}\endcsname{#1}%
, but you will get into troubles if you have more than 26 problems and again, if you repeat your scheme, since\problemA
etc. is tried to be redefined, leading to errors. As it stands, the first code fragment seems to be unrelated to the 2nd code\newgroup
that would define them. In fact, as of group A, you don't even know how many other groups will follow. The traditional approach would be to somehow write things out to the aux file and force a 2nd compilation pass.