2

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}
\title{Your Paper}
\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.

1 Answers1

5

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}
\title{Your Paper}
\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}
GuM
  • 21,558
David Carlisle
  • 757,742