# \centering breaks fragile command (is there a fix?)

Many on this site know (and perhaps find slightly annoying) that I will try to solve any LaTeX problem with the use of my stackengine package. My motto is like one of the overnight delivery services: "if it stacks, we ship it".

I found an odd problem in one of my parsing routines from that package, and I know it very much relates to the topic or robustness (which I kind of understand in theory, but certainly don't know enough to overcome). What I found surprising is that this particular problem only arises after an invocation of \centering which I found quite odd and unexpected.

I've boiled the problem down to this MWE. Here, \@readMANYrows will take an argument consisting of multi-row data, each row separated by a "end-of-line" (EOL) character, and parse it into individual row data. The stackengine package, for historical reasons, defaults this EOL character to a space, but has a package option to make the EOL a \\ to be more in line with what LaTeX users might expect (I realize \\ is a macro, not a character, and that perhaps is the root of this problem).

When the EOL is set to \\, everything works fine. If \centering is invoked, however, the routine will only work if the EOL is something other than \\. Finally, if I make \protect\\ the EOL, everything works again even when centering, but that last syntax is really a nuisance and for academic interest only.

So my question is two-fold: I am curious how it is that \centering undermines the parsing routine (it is not as if \centering is an argument to my routine... it is not)?; AND, is there an easy way to make the parsing routine robust without, for example, rewriting it in LaTeX3, as egreg did at Parsing rows (\\) and tab characters (&)?

I would only add, as a postscript, that \usepackage{fixltx2e} does not resolve this problem.

\documentclass{article}
\usepackage{ifthen}
\newcounter{ROWcellindex@}
\makeatletter
\newcommand\setstackEOL[1]{%
\ifthenelse{\equal{#1}{}}{\def\SEP@char{ }}{\def\SEP@char{#1}}%
\expandafter\define@processROW\expandafter{\SEP@char}%
}

\newcommand\define@processROW[1]{%
\def\@processROW##1#1##2||{%
\protected@edef\@preSEP{##1}%
\protected@edef\@postSEP{##2}%
}%
}

% FOR PROCESSING A GROUP OF STACK ROWS SEPARATED BY \SEP@char
\def\@postSEP{#1\SEP@char}%
\setcounter{ROWcellindex@}{0}%
\stepcounter{ROWcellindex@}%
\expandafter\@processROW\@postSEP||%
\ifthenelse{\equal{\@postSEP}{}}{%
}{}%
\ifthenelse{\equal{\SEP@char}{ }}%
{\def\@preSEPtemp{\@preSEP}}%
{\def\@preSEPtemp{\ignorespaces\@preSEP\unskip}}%
\expandafter\protected@edef\csname arg\roman{ROWcellindex@}\endcsname{%
\@preSEPtemp}%
}%
% \narg GIVES HOW MANY ROWS WERE PROCESSED
\xdef\narg{\arabic{ROWcellindex@}}%
}
\begin{document}

% OK IF NO CENTERING
\setstackEOL{\\}
\argi, \argii, \argiii\\

% OK IF DIFFERENT EOL CHARACTER
\centering
\@readMANYrows{d $e$ f}
\argi, \argii, \argiii\\

% BREAKS! \\ NOT ROBUST
\centering
\setstackEOL{\\}

• Your ability to digest bad code and fix it on the fly is much appreciated. And I can readily understand this syntax (unlike LaTeX3), and will use this example to enrich my learning. Not only did you fix the issue of fragile EOL separators, but as a by-product you fixed the issue of fragile arguments in \Shortstack, \Shortundertack, \Longstack and \Longunderstack. I am very grateful. This will without doubt go into the next package release. – Steven B. Segletes Oct 10 '13 at 20:11
• @StevenB.Segletes You're welcome. Once you master etoolbox` facilities, going to LaTeX3 shouldn't be difficult. ;-) – egreg Oct 10 '13 at 20:15