%See below

\RequirePackage{amsmath,environ,xstring}
\newif\iflabel
\newif\ifdbs
\newif\ifamp
\NewEnviron{flexiblemathdisplay}{%
  \noexpandarg
  \expandafter\IfSubStr\expandafter{\BODY}{\label}{\labeltrue}{\labelfalse}%
  \expandafter\IfSubStr\expandafter{\BODY}{\\}{\dbstrue}{\dbsfalse}%
  \expandafter\IfSubStr\expandafter{\BODY}{&}{\amptrue}{\ampfalse}%
  \iflabel\def\flexiblemathdisplaystar{}\else\def\flexiblemathdisplaystar{*}\fi
  \ifdbs
    \ifamp
      \def\flexiblemathdisplayname{align}%
    \else
      \def\flexiblemathdisplayname{multline}%
    \fi
  \else
    \def\flexiblemathdisplayname{equation}
  \fi
  \begingroup\edef\x{\endgroup
    \noexpand\begin{\flexiblemathdisplayname\flexiblemathdisplaystar}%
    \noexpand\BODY
    \noexpand\end{\flexiblemathdisplayname\flexiblemathdisplaystar}%
  }\x
}

\def\[#1\]{\begin{flexiblemathdisplay}#1\end{flexiblemathdisplay}}

\endinput

Tuesday, December 6, 2011  11:08

http://tex.stackexchange.com/questions/36341/flexible-equation-align-multline-environment

Use as follows. Note flexiblemathdisplay env. can be
replaced by \[
\].

\documentclass{article}
\usepackage{../../flexiblemathdisplay}

\begin{document}
Numbered

\begin{flexiblemathdisplay}
a=b\label{1}
\end{flexiblemathdisplay}
\begin{flexiblemathdisplay}
a\\b\label{2}
\end{flexiblemathdisplay}
\begin{flexiblemathdisplay}
a&=b\label{3}\\
c&=dxxxxx
\end{flexiblemathdisplay}

Now no numbers

\begin{flexiblemathdisplay}
a=b
\end{flexiblemathdisplay}
\begin{flexiblemathdisplay}
a\\b
\end{flexiblemathdisplay}
\begin{flexiblemathdisplay}
a&=b\\
c&=dxxxxx
\end{flexiblemathdisplay}

\[ \sum \sum \sum
\sum \sum \sum \sum \sum = \sum\sum \\ \sum \sum\sum \sum = \sum\sum \sum \sum
\label{ugh!}\]

That was \ref{ugh!}

\end{document}
