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
  • 1
    \begin{tabular}[rcl] should be \begin{tabular}{rcl} Commented Jun 16, 2016 at 17:21

1 Answer 1

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}
2
  • I took the liberty to edit (reverently) your answer to remove the references to the now unnecessary switch.
    – GuM
    Commented Jun 16, 2016 at 22:04
  • Wonderful. This made the trick. Many thanks. Commented Jun 17, 2016 at 8:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .