# How to correctly create a macro for a table?

I am trying to apply the following answer: https://tex.stackexchange.com/a/72916/25124

What is wrong with this code? I am trying to define a macro to be able to specify a table of 3 columns but whose central column are always arrows. It looks like the error comes from \begin{tabular} but I'm not sure.

\documentclass[a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{array}
\author{You}
\begin{document}
\newif\ifrulesetSep
\newcommand*{\ruleset}[1]{%
\begin{center}\begin{tabular}[rcl]
\rulesetSepfalse
\ruleScan#1\relax\relax
}
\newcommand{\ruleScan}[2]{%
\ifx\relax#1
\end{tabular}\end{center}
\else
\ifrulesetSep
\\
\else
\rulesetSeptrue
\fi
#1 & $\rightarrow$ & #2
\expandafter\ruleScan
\fi
}
\ruleset{
{A}{B C}
{B}{b}
{C}{c A B}
}
\end{document}

I get the error

Package array Error: Illegal pream-token (\rulesetSepfalse): `c' used.

• \begin{tabular}[rcl] should be \begin{tabular}{rcl} Jun 16 '16 at 17:21

The column specification of tabular is mandatory not optional so {} not [] and your true/false switch would not work as written as each tavle cell is a group so the setting was lost at each & or \\

\documentclass[a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{array}
\author{You}

\begin{document}
\newcommand*{\ruleset}[1]{%
\begin{center}\begin{tabular}{rcl}%%
\ruleScan#1\relax\relax
}
\newcommand{\ruleScan}[2]{%
\ifx\relax#1%%
\end{tabular}\end{center}%
\else
#1 & $\rightarrow$ & #2\\%%
\expandafter\ruleScan
\fi
}
\ruleset{
{A}{B C}
{B}{b}
{C}{c A B}
}
\end{document}
• I took the liberty to edit (reverently) your answer to remove the references to the now unnecessary switch.
– GuM
Jun 16 '16 at 22:04
• Wonderful. This made the trick. Many thanks. Jun 17 '16 at 8:41