# use string variable as format string in \begin{tabu}

I have the following problem. I'm using the tabu package to create tables but instead of a format string like this: \begin{tabu}{ccc} I want to use a format string like this (as string variable): \begin{tabu}{\reptemp}.

Here is my code:

\documentclass{article}
\usepackage{forloop,tabu}

\begin{document}

\def\reptemp{}

\newcounter{ct}

\forloop{ct}{1}{\value{ct} < 5}%
{%
}

\begin{tabu}{\reptemp}
\end{tabu}

\end{document}


And get the following compiling error:

! Package array Error: Illegal pream-token (\reptemp): 'c' used.

I hope you have a tip for my how I can solve this problem.

• Welcome to TeX.SX. Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Claudio Fiandrino Apr 11 '13 at 8:40

The tabu environment doesn't do expansion on the preamble argument.

\documentclass{article}
\usepackage{forloop,tabu}

\def\reptemp{}
\makeatletter
\newcounter{ct}

\forloop{ct}{1}{\value{ct} < 5}%
{%
}
\makeatother

\newenvironment{xtabu}[1]
{\begingroup\edef\x{\endgroup
\unexpanded{\begin{tabu}}{\unexpanded\expandafter{#1}}}\x}
{\end{tabu}}

\begin{document}
\begin{xtabu}{\reptemp}
1&2&3&4
\end{xtabu}
\end{document}


You need to expand the macro before passing it to the environment:

\def\starttabu#1{\begin{tabu}{#1}}

\expandafter\starttabu\expandafter{\reptemp}