[Tex/LaTex] Making a new environment combining equation and split

environmentsequationserrors

I'm trying to define a new environment that consists of a split environment inside an equation environment. But I'm getting an error. Here's what I'm doing:

\documentclass[a4paper,12pt]{article}
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\newenvironment{example}{\begin{equation}\begin{split}}{\end{split}\end{equation}}

\begin{document}
\begin{example}oi\end{example}
\end{document}

And the error message I'm getting is:

ERROR: LaTeX Error: \begin{split} on input line 8 ended by \end{example}.

I then tried a few other cases. If I remove the splits and define example to be just equation, it runs fine. If I remove the equations and define example to be just split, I get the exact same error message.

In other words: I only get this error when split is involved. Is there a way to make this work?

EDIT: The reason I'm doing this, is because I want a convenient way to create split-equations. I know it's similar to align. I prefer split-equations because the entire line of equations gets a single number for referencing (it's even placed in the middle line). align, however, will force me to \notag each line, otherwise I get a number for each line in the equation (which tends to get messy when equations are long and numerous). It's not the end of the world, but the splitequation combination is just quicker and easier (if I can manage to define a command for it).

Alternatively, the multline environment is not appropriate either, because it doesn't let you manually align each line (like aligning the equal signs). Instead it only lets you push everything left or right.

EDIT2: I just tried this:

\newenvironment{example}{ \begin{equation}\split}{\endsplit \end{equation}}

and got this error

ERROR: LaTeX Error: \begin{equation} on input line 8 ended by \end{example}.

Which is weird, because removing \split and \endsplit entirely doesn't return any errors (so it's not equation's fault).

Best Answer

I wouldn't have expected this, but there's an easy answer; thanks to Stefan Kottwitz! (And thanks to Will Robertson for writing the package environ that I had never heard of before. He should have given this answer; with his package it works like a charm.)

\documentclass{article}
\usepackage{amsmath,environ}
\NewEnviron{example}{%
\begin{equation}\begin{split}
  \BODY
\end{split}\end{equation}
}
\begin{document}
\begin{example}
a &= b + c \\
  &= d + e
\end{example}
\end{document}

Some explanations can be found in Stefan's post behind the above link.

Related Question