I was trying to build a tabular environment that is auto-generated through the use of pgffor's \foreach macro. But I can't seem to get it right.
Here's a MWE for generating a multiplication table:
\documentclass{article}
\usepackage[margin=0.5in,showframe]{geometry}
\usepackage{pgfkeys,pgffor}
%% keys for control the dimensions of the table
\pgfkeys
{/ae/multiplication/table/.cd,
xmax/.initial = 9,
ymax/.initial = 9,
}
\def\aeget#1{\pgfkeysvalueof{/ae/multiplication/table/#1}}
%% commands to facilitate controlling when expansion occurs.
\def\aemulttable{\tabular[t]}
\def\aecolcnt{{ c | *{\number\numexpr\xmax\relax}{c}}}
\def\mytablecontents{%%'
\foreach \y in {0,1,...,\ymax} {%%'
\foreach \x in {0,1,...,\xmax} {%%'
\ifnum\y=0\relax
\ifnum\x=0\relax
$\times$ & %%'
\else
$\x$ & %%'
\fi
\else
\ifnum\x=0\relax
$\y$ & %%'
\else
$\number\numexpr\x*\y\relax$ & %%'
\fi
\fi
\ifnum\x=\xmax\relax\\\fi
}}}
\newcommand{\createtable}[1][]
{\pgfkeys{/ae/multiplication/table/.cd,#1}%%'
\def\xmax{\aeget{xmax}}%%'
\def\ymax{\aeget{ymax}}%%'
\noindent
\expandafter\expandafter\expandafter\aemulttable\expandafter\aecolcnt
\mytablecontents
\endtabular
}
\pagestyle{empty}
\begin{document}
\createtable[xmax=4,ymax=25]
\end{document}
I thought Pgffor and the alignment character (&) would be helpful. But the only answer provided does not use pgffor. I have already written my own expl3 solution, but I'd really like to know how to implement this with pgffor.
