Following the question Tab not as extra alignment tab I managed to use the tab character as column divider '&' and the newline character as line break '\\' in an array (or tabular) environment, which works as expected.
Now I'd like to wrap this environment in a command, but it seems that all tab and newline characters are stripped from the table body. Is there a way to preserve those control characters?
MWE:
\documentclass{article}
\makeatletter%
\begingroup%
\gdef\activateCtrlChars{%
\catcode`\^^I=\active%
\catcode`\^^M=\active%
}%
\activateCtrlChars%
\gdef^^I{\@ifnextchar^^I{}{&}}%
\gdef^^M{\@ifnextchar\end {}{\\}}%
\gdef\gobbleLineBreak{\@ifnextchar^^M {\@gobble}{}}%
\endgroup%
\makeatother%
\newenvironment{myArray}
{% before
\activateCtrlChars%
\array[t]{ccc}%
\gobbleLineBreak%
}
{% after
\endarray%
\par%
}
\newcommand{\myArrayAsCmd}[1]{\begin{myArray}#1\end{myArray}}
\begin{document}
Environment:
\begin{myArray}
a b c
aa bb cc
\end{myArray}
Command:
\myArrayAsCmd{
a b c
aa bb cc
}
\end{document}
Output: