Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.