2

Consider the following example:

\documentclass{article}
\usepackage{amsmath}

\usepackage{tabstackengine}


\stackMath
\setstacktabbedgap{0.5em}
\setstackTAB{ }

\makeatletter
\robustify{\@normalcr} %globally robust
%avoids error but wrong output:
%\def\@parboxrestore{\@arrayparboxrestore\def\\{\protect\@normalcr}}
\makeatother
\usepackage{environ}

\begin{document}

\NewEnviron{LGS}{
  \begin{equation*}
    \tabbedCenterstack[r]{
      \BODY
    }
  \end{equation*}
}


\begin{LGS}
  -2x +  y + 3z = 10 + x \\
  x +  y +  z =  6 + 2z\\
  3 + 3y + 2z = y - 3z
\end{LGS}

\end{document}

It's output is one line, i.e. the \\ symbols are ignored:

enter image description here

How can I make this work?

student
  • 29,003
  • You should use one of the multiline environments provided by amsmath for this. Why aren't you doing it that way? – cfr Aug 31 '16 at 23:56
  • @cfr: This way was an answer to the question: http://tex.stackexchange.com/questions/35174/best-way-to-create-an-system-of-equations-environment/126112#126112 and I am just playing with it to see if it is really the best way to do it. – student Sep 01 '16 at 08:58
  • Thanks for explaining - the example just looked strange in isolation. – cfr Sep 01 '16 at 11:05

1 Answers1

4

First problem: \tabstackengine must see \\ in its argument, so you have to expand \BODY before passing it to the macro.

Second problem: \tabstackengine knows to ignore spaces after \\ when absorbing its argument, but once it has been absorbed by the environ-based LGS, they cannot be removed, so you get a spurious alignment point.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabstackengine}
\usepackage{environ}

\stackMath
\setstacktabbedgap{0.5em}
\setstackTAB{ }
\makeatletter
\robustify{\@normalcr} %globally robust
\makeatother
\NewEnviron{LGSo}{%
  \begin{equation*}
  \def\temp{\tabbedCenterstack[r]}
  \expandafter\temp\expandafter{\BODY}
  \end{equation*}
}
\newenvironment{LGS}{\endlinechar=-1 \LGSo}{\endLGSo}

\begin{document}

\begin{LGS}
-2x +  y + 3z = 10 + x \\
x +  y +  z =  6 + 2z\\
3 + 3y + 2z = y - 3z
\end{LGS}

\end{document}

enter image description here

egreg
  • 1,121,712