# Disable fleqn option for multline environments?

Getting into the same trouble as in amsmath's multline and fleqn, I wonder if it is possible to enable amsmath's fleqn option (globally, no other choice) but disable it for multline environment (okay, that's not ideal but, anyway)?

Internally, the fleqn option sets a flag \if@fleqn so all that you need to do is turn this off. The simplest way to do this is using the \preto command from the etoolbox package:

\documentclass[fleqn]{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\makeatletter
\preto\multline{\@fleqnfalse}% disable fleqn inside multline environments
\makeatother

\begin{document}

\begin{multline}
1+2+3+4+5+6+7+8+9+10+11+12 \\
+13+14+15+16+17+18+19+20+21+22 \\
+23+24+25+26+27+28+29+30+31
\end{multline}

\end{document}


This produces:

A second option would be to define a general environment, called nofleqn below, that allows you to turn off fleqn whenever you wanted. The way this environment works is that it takes one argument, which is the name of the environment that you really want to use (such as multine, align, align*, etc) and then you add the contents of the environment as usual. Using the code, which uses the environ package, the MWE below produces:

For reference, an undoctored multline environment is also given. Here is the code:

\documentclass[fleqn]{article}
\usepackage{amsmath}
\usepackage{environ}
\makeatletter
\NewEnviron{nofleqn}[1]{\@fleqnfalse\begin{#1}\BODY\end{#1}}
\makeatother

\begin{document}

Without fleqn:
\begin{nofleqn}{multline}
1+2+3+4+5+6+7+8+9+10+11+12 \\
+13+14+15+16+17+18+19+20+21+22 \\
+23+24+25+26+27+28+29+30+31
\end{nofleqn}

With fleqn:
\begin{multline}
1+2+3+4+5+6+7+8+9+10+11+12 \\
+13+14+15+16+17+18+19+20+21+22 \\
+23+24+25+26+27+28+29+30+31
\end{multline}

\end{document}


Of course, you could define a fleqn-less version of the multline environment in exactly the same way. In fact, if you know the name of the environment that you are using then you don't need environ:

\newenvironment{Multline}{\@fleqnfalse\multline}{\endmultline}


In all cases it is necessary to enclose the defining code in \makeatletter....\makeatother because otherwise LaTeX will complain about ythe @ in \if@fleqn. I think that this should work without issues but I have not tested it thoroughly so there may be unintended side-effects.

Here's a redefinition of the multline and multline* environments where lines after the first are indented twice the \mathindent (you can easily spot where to act if you prefer a different spacing).

\documentclass[fleqn]{article}
\usepackage{amsmath}
\usepackage{xparse,environ}
\usepackage{lipsum}

\ExplSyntaxOn

% save the original environments
\cs_set_eq:NN \db_multline_start: \multline
\cs_set_eq:NN \db_multline_end: \endmultline
\cs_set_eq:Nc \db_multline_star_start: {multline*}
\NewDocumentEnvironment{amsmathmultline}{}
{\db_multline_start:}
{\db_multline_end:}
\NewDocumentEnvironment{amsmathmultline*}{}
{\db_multline_star_start:}
{\db_multline_end:}

% redefine them
\RenewEnviron{multline}
{
\db_multline:nV {multline} \BODY
}
\RenewEnviron{multline*}
{
\db_multline:nV {multline*} \BODY
}
\seq_new:N \l_db_multline_seq
\cs_new_protected:Nn \db_multline:nn
{
\seq_set_split:Nnn \l_db_multline_seq { \\ } { #2 }
\begin{amsmath#1}
\seq_use:Nn \l_db_multline_seq { \multlineaddspace } \hfill
\end{amsmath#1}
}
\cs_generate_variant:Nn \db_multline:nn { nV }
\ExplSyntaxOff

\IfValueTF{#1}{\\[#1]}{\\}\hspace{\mathindent}%
}

\begin{document}

\lipsum*[3]
\begin{multline}
1+2+3+4+5+6+7+8+9+10+11+12 \\[2ex]
+13+14+15+16+17+18+19+20+21+22 \\[2ex]
+23+24+25+26+27+28+29+30+31
\end{multline}
\lipsum*[4]
\begin{multline*}
1+2+3+4+5+6+7+8+9+10+11+12 \\
+13+14+15+16+17+18+19+20+21+22 \\
+23+24+25+26+27+28+29+30+31
\end{multline*}
\lipsum[5]

\end{document}


• Very nice indeed: the indentation of the first line is then the same as in the other display math environments. The only drawback is, the last line has the same indentation as the other ones (but the 1st one) and, in order to mimic the default multline environment, it could be nice to make it have a bigger indentation (say triple \mathindent). – Denis Bitouzé Oct 28 '17 at 10:44
• Okay, just a matter of \seq_use:Nnnn \l_db_multline_seq { \\ \hspace{\mathindent} } { \\ \hspace{\mathindent} } { \\ \hspace{2\mathindent} } \hfill instead of \seq_use:Nn \l_db_multline_seq { \\ \hspace{\mathindent} } \hfill. – Denis Bitouzé Oct 28 '17 at 13:03
• @DenisBitouzé Yes, it's possible! ;-) Updated version is online. – egreg Oct 29 '17 at 9:47
• @DenisBitouzé It should have an optional argument, whereas expl3 level commands haven't one. – egreg Oct 29 '17 at 11:25
• @DenisBitouzé They're at different levels and, no, it won't happen. – egreg Oct 29 '17 at 18:53