I need to construct a table that looks like:
\begin{tabular}{ccc}
a(1,1) & a(1,2) & a(1,3)\\ % <---
a(2,1) & a(2,2) & a(2,3)\\ % <--- I need this
a(3,1) & a(3,2) & a(3,3)\\ % <---
\end{tabular}
for any given number of colums or rows. In fact I only need the part that has arrow next to it, because I would like to be able to put it in different kinds of environments.
I need it to come like some sort of macro, so I can do
\begin{tabular}{ccc}
\generate{a}{3}{3}
\end{tabular}
to get the above table. I've tried:
\newcommand\makerow[3]{
\foreach \n [count=\ni] in {1,...,#3}{%
\ifnum\ni=1
#1(#2,\n)
\else
& #1(#2,\n)
\fi
}%
}%
\newcommand\makematrix[3]{
\foreach \m [count=\mi] in {1,...,#2}{%
\ifnum\mi=#2
\makerow{#1}{\m}{#3}
\else
\makerow{#1}{\m}{#3}\\
\fi
}%
}%
\begin{tabular}{ccc}
\makematrix{a}{3}{3}
\end{tabular}
Yet I get this error:
Incomplete \ifnum; All text was ignored after line 81.
Missing \endgoup inserted.
....
What I need
I need a macro to quickly build tabular environments that have a variable number of colums and rows, yet I want to be able to use the tabular as I would do every day:
\begin{tabular}{cc|cc}
\hline
header 1 & header 2 & header 3\\
\hline
foo & bar & baz \\
\makematrix{a}{4}{3} % <-- makes the rest of the table as described below
\hline
bar & baz &baz\\
\end{tabular}
etc. So The macro must be just inputted into the tabular environment, and behave as if
a(1,1) & a(1,2) & a(1,3)\\
a(2,1) & a(2,2) & a(2,3)\\
...
were inputted at that spot. Similarly, I would like to be able to define the colums of the tabular environment myself because I'd like to be able tu use > {...} on the columns.

pgfforpackage and nest twoforeachloops to run over all rows and columns. – percusse Jan 06 '12 at 12:34&'s to be inserted without pgf giving an error – romeovs Jan 06 '12 at 12:40