0

As described in Multiple split equations I want to create an equation environment that inserts aligned and lets me split equations with \n. The solution I found there is a bit hackish I guess, but works in the general case.

Now curiously, if I only put a single line (i.e. one aligned, split by \n or not) into the environment, like this:

\documentclass{article}
\usepackage[fleqn]{amsmath}

\usepackage{environ}
\makeatletter
\NewEnviron{multeq}{%
    \let\n\math@cr
    \begin{gather}
        \def\math@cr{\end{aligned}\n\begin{aligned}}
        \begin{aligned}
            \BODY
        \end{aligned}
    \end{gather}
}
\makeatother

\begin{document}
    \begin{multeq}
        1-1=9
    \end{multeq}
\end{document}

compilation will fail with an error like

! Missing $$ inserted.
<to be read again> 
                   \egroup 
l.20    \end{multeq}

So the question, I can't figure out is: What is the difference when there is only one aligned? Also there seem to be issues with using \intertext and \shortintertext inside of multeq now. If somebody has a suggestion for improvement, that would be great!

1 Answer 1

2

Here's an idea: we don't mess with redefinitions of anything (this is bound to cause trouble somewhere), but rather do a search&replace in advance.

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{xstring}
\usepackage{environ}

\NewEnviron{multeq}{%
  \def\n{\\}\noexpandarg
  \expandafter\StrSubstitute\expandafter{\BODY}{\\}{\end{aligned}\\\begin{aligned}}[\newBODY]
  \begin{gather}
    \begin{aligned}
      \newBODY
    \end{aligned}
  \end{gather}
}

\begin{document}

\begin{multeq}
    0 + 0 = 0\n
    0 * 0 = 0\\
    1 + 1 = 2\n
    1 * 1 = 1
\end{multeq}

\begin{multeq}
    0 + 0 = 0
\end{multeq}

\end{document}

You must log in to answer this question.

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