%%
%% This is file `breqn.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% breqn.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 1997-2003 by Michael J. Downes
%% Copyright (C) 2007-2008 by Morten Hoegholm
%% Copyright (C) 2007-2014 by Lars Madsen
%% Copyright (C) 2007-2014 by Will Robertson
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Will Robertson.
%% 
%% This work consists of the main source file breqn.dtx
%% and the derived files
%%    breqn.sty, breqn.pdf, breqn.ins.
%% 
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}[2009/08/05]
\ProvidesExplPackage{breqn}{2012/05/10}{0.98b}{Breaking equations}
\ExplSyntaxOff
\edef\breqnpopcats{%
  \catcode\number`\"=\number\catcode`\"
  \relax}
\AtEndOfPackage{\breqnpopcats}%
\catcode`\^=7 \catcode`\_=8 \catcode`\"=12 \relax
\DeclareOption{mathstyleoff}{%
  \PassOptionsToPackage{mathstyleoff}{flexisym}%
}
\ProcessOptions\relax
\@ifpackageloaded{flexisym}{}{%
  \RequirePackage{flexisym}[2009/08/07]
    \edef\breqnpopcats{\breqnpopcats
    \catcode\number`\^=\number\catcode`\^
    \catcode\number`\_=\number\catcode`\_
  }%
  \catcode`\^=7 \catcode`\_=8 \catcode`\"=12 \relax
}
\RequirePackage{keyval,calc}\relax
\@ifundefined{options}{%
\newcommand{\options}[2]{%
  \expandafter\options@a\csname opt@#1.sty\endcsname{#2}%
  \setkeys{#1}{#2}%
}
\def\options@a#1#2{%
  \edef\@tempa{\options@b#2,\@empty\@nil}%
  \ifx#1\relax \let#1\@empty\fi
  \xdef#1{#1\ifx#1\@empty\@xp\@gobble\@tempa\@empty\else\@tempa \fi}%
}
\def\options@b#1,#2#3\@nil{%
  \options@c#1 \@nil
  \ifx#2\@empty \else\options@b#2#3\@nil\fi
}
\def\options@c#1 #2\@nil{\options@d#1=\@nil}
\def\options@d#1=#2\@nil{\ifx\@empty #1\@empty\else,\fi#1}
}{}% end @ifundefined test
\let\@nx\noexpand
\let\@xp\expandafter
\@ifundefined{@emptytoks}{\newtoks\@emptytoks}{}
\chardef\f@ur=4
\newcount\inf@bad \inf@bad=1000000
\newcount\maxint \maxint=2147483647
\let\int@a=\@tempcnta
\let\int@b=\@tempcntb
\let\int@c=\count@
\let\dim@a\@tempdima
\let\dim@b\@tempdimb
\let\dim@c\@tempdimc
\let\dim@d\dimen@
\let\dim@e\dimen@ii
\let\dim@A\dimen@i
\let\skip@a\@tempskipa
\let\skip@b\@tempskipb
\let\skip@c\skip@
\let\toks@a\@temptokena
\let\toks@b\toks@
\toksdef\toks@c=2
\toksdef\toks@d=4
\toksdef\toks@e=6
\toksdef\toks@f=8
\def\abs@num#1{\ifnum#1<\z@-\fi#1}
\def\@ifnext#1#2#3{%
  \let\@tempd= #1\def\@tempa{#2}\def\@tempb{#3}%
  \futurelet\@tempc\@ifnexta
}
\def\@ifnexta{\ifx\@tempc\@tempd \let\@tempb\@tempa \fi \@tempb}
\def\@ifstar#1#2{%
  \let\@tempd*\def\@tempa*{#1}\def\@tempb{#2}%
  \futurelet\@tempc\@ifnexta
}
\def\@optarg#1#2{\@ifnext[{#1}{#1[#2]}}
\def\@True{00}
\def\@False{01}
\def\@Not#1{0\ifcase#11 \or\@xp 1\else \@xp 0\fi}
\def\@And#1#2{0\ifcase#1#2 \@xp 0\else \@xp 1\fi}
\def\@Or#1#2{0\ifnum#1#2<101 \@xp 0\else \@xp 1\fi}
\def\theb@@le#1{\if#1 True\else False\fi}
\def\freeze@glue#1{#11#1\relax}
\def\z@rule{\vrule\@width\z@}% no \relax ! use with care
\def\keep@glue{\z@rule\relax}
\begingroup \catcode`\&=11
\gdef\replicate#1{%
  \csname &\expandafter\replicate@a\romannumeral\number\number#1 000q\endcsname
}
\endgroup
\long\def\replicate@a#1#2\endcsname#3{#1\endcsname{#3}#2}
\begingroup \catcode`\&=11
\long\gdef\&m#1#2{#1\csname &#2\endcsname{#1}}
\endgroup
\@xp\let\csname\string &q\endcsname\@gobble
\ExplSyntaxOn
\g@addto@macro\mathchars@reset{%
  %\let\@symRel\@secondoftwo \let\@symBin\@secondoftwo
  %\let\@symDeL\@secondoftwo \let\@symDeR\@secondoftwo
  %\let\@symDeB\@secondoftwo
  \cs_set_eq:NN \math_csym_Rel:Nn \use_ii:nn
  \cs_set_eq:NN \math_csym_Bin:Nn \use_ii:nn
  \cs_set_eq:NN \math_csym_DeL:Nn \use_ii:nn
  \cs_set_eq:NN \math_csym_DeR:Nn \use_ii:nn
  \cs_set_eq:NN \math_csym_DeB:Nn \use_ii:nn
}
\ExplSyntaxOff
\def\eq@cons#1#2{%
  \begingroup \let\@elt\relax \xdef#1{\@elt{#2}#1}\endgroup
}
\providecommand{\@saveprimitive}[2]{%
  \begingroup
  \edef\@tempa{\string#1}\edef\@tempb{\meaning#1}%
  \ifx\@tempa\@tempb \global\let#2#1%
  \else
    \edef\@tempb{\meaning#2}%
    \ifx\@tempa\@tempb
    \else \@saveprimitive@a#1#2%
    \fi
  \fi
  \endgroup
}
\providecommand\@saveprimitive@a[2]{%
  \begingroup
  \def\@tempb##1#1##2{\edef\@tempb{##2}\@car{}}%
  \@tempb\nullfont{select font nullfont}%
    \topmark{\string\topmark:}%
    \firstmark{\string\firstmark:}%
    \botmark{\string\botmark:}%
    \splitfirstmark{\string\splitfirstmark:}%
    \splitbotmark{\string\splitbotmark:}%
    #1{\string#1}%
    \@nil % for the \@car
  \edef\@tempa{\expandafter\strip@prefix\meaning\@tempb}%
  \edef\@tempb{\meaning#1}%
  \ifx\@tempa\@tempb \global\let#2#1%
  \else
    \PackageError{breqn}%
      {Unable to properly define \string#2; primitive
      \noexpand#1no longer primitive}\@eha
    \fi
  \fi
  \endgroup
}
\begingroup \catcode`\$=\thr@@ % just to make sure
  \global\let\@@math=$ \gdef\@@display{$$}% $$$
\endgroup
\let\@@endmath=\@@math
\let\@@enddisplay=\@@display
\@saveprimitive\vadjust\@@vadjust
\@saveprimitive\insert\@@insert
\@saveprimitive\mark\@@mark
\@ifundefined{listwidth}{\newdimen\listwidth}{}
\listwidth=\z@
\def\eqfontsize{}         % Inherit from context    [NOT USED?]
\def\eqcolor{black}       % Default to black        [NOT USED?]
\newdimen\eqnumsep \eqnumsep=10pt        % Min space between equ number and body
\newdimen\eqmargin \eqmargin=8pt         % For `multline' gap emulation
\def\eqindent{C}%         % C or I, centered or indented
\def\eqnumside{R}%        % R or L, right or left
\def\eqnumplace{M}%       % M or T or B, middle top or bottom
\def\eqnumfont{}%         % Null for easier debugging [mjd,1997/09/26]
\def\eqnumform#1{(#1\@@italiccorr)} % Add parens
\def\eqnumsize{}          % Allow numbers to have different typesize ...
\def\eqnumcolor{}         % ... or color than eq body e.g. \color{blue}
\newlength\eqlinespacing \eqlinespacing=14pt plus2pt % Base-to-base space between lines
\newlength\eqlineskip \eqlineskip=3pt plus2pt % Min space if eqlinespacing too small
\newdimen\eqlineskiplimit \eqlineskiplimit=2pt  % Threshold for switching to eqlineskip
\newmuskip \eqbinoffset \eqbinoffset=15mu minus-3mu % Offset from mathrel alignment pt for mathbins
\newmuskip\eqdelimoffset \eqdelimoffset=2mu    % Additional offset for break inside delims
\newdimen\eqindentstep \eqindentstep=8pt     % Indent used when LHS wd is n/a or too large
\newtoks\eqstyle           % Customization hook
\newcount\eqbreakdepth \eqbreakdepth=2       % Allow breaks within delimiters to this depth
\newcount \eqinterlinepenalty \eqinterlinepenalty=10000 % No page breaks between equation lines
\newcount \intereqpenalty \intereqpenalty=1000   % Pagebreak penalty between equations [BRM: Was \@M]
\newlength \intereqskip \intereqskip=3pt plus2pt % Additional vert space between equations
\newcount\prerelpenalty \prerelpenalty=-\@M   % Linebreak penalty before mathrel symbols
\newcount\prebinoppenalty \prebinoppenalty=888  % Linebreak penalty before mathbins
\newmuskip \Dmedmuskip \Dmedmuskip=4mu minus 3mu % medmuskip in displays
\newmuskip \Dthickmuskip \Dthickmuskip=5mu minus 2mu % thickmuskip in displays
\def\eq@number{}          % Internal variable
\newlength\eqleftskip \eqleftskip=\@centering  % Space on the left  [NOT USED?]
\newlength\eqrightskip \eqrightskip=\@centering % Space on the right [NOT USED?]
\newlength\eq@vspan \eq@vspan=\z@skip     % Glue used to vcenter the eq number
\newmuskip\eq@binoffset \eq@binoffset=\eqbinoffset % Roughly, \eqbinoffset + \eqdelimoffset
\newsavebox\EQ@box               % Storage for equation body
\newsavebox\EQ@copy              % For eq body sans vadjust/insert/mark material
\newsavebox\EQ@numbox            % For equation number
\newdimen\eq@wdNum         % width of number + separation [NEW]
\newsavebox\GRP@numbox            % For group number [NEW]
\newdimen\grp@wdNum         % width of number + separation [NEW]
%%B\EQ@vimbox            % Vadjust, insert, or mark material
%%B\EQ@vimcopy           % Spare copy of same
%%B\eq@impinging         % Temporary box for measuring number placement
\newcount \eq@lines          % Internal counter, actual number of lines
\newcount \eq@curline       % Loop counter
\newcount \eq@badness      % Used in testing for overfull lines
\newcount \EQ@vims          % For bookkeeping
\def\@eq@numbertrue{\let\eq@hasNumber\@True}%
\def\@eq@numberfalse{\let\eq@hasNumber\@False}%
\let\eq@hasNumber\@False
\newdimen\eq@dp         % Depth of last line
\newdimen\eq@wdL        % Width of the left-hand-side
\newdimen\eq@wdT        % Total width for framing
\newdimen\eq@wdMin      % Width of narrowest line in equation
\newdimen\grp@wdL       % Max width of LHS's in a group
\newdimen\grp@wdR       % Max RHS of all equations in a group
\newdimen\grp@wdT
\newdimen\eq@wdRmax
\newdimen\eq@firstht    % Height of first line
\newdimen\eq@wdCond
\newdimen\eq@indentstep % Indent amount when LHS is not present
\newdimen\eq@linewidth  % Width actually used for display
\newdimen\grp@linewidth % Max eq@linewidth over a group
\newdimen\eq@hshift
\let\eq@isIntertext\@False
\eq@indentstep=\maxdimen
\newdimen\eq@given@sidespace
\def\eq@overrun{0pt}
\@ifpackagewith{amsmath}{leqno}{%
  \@ifpackagewith{amsmath}{reqno}{}{\def\eqnumside{L}}%
}{%
  \def\@tempa#1,leqno.clo,#2#3\@nil{%
    \ifx @#2\relax\else \def\eqnumside{L}\fi
  }%
  \@xp\@tempa\@filelist,leqno.clo,@\@nil
  \if L\eqnumside
  \else
    \@ifundefined{iftagsleft@}{}{%
      \edef\eqnumside{%
        \if TT\csname fi\endcsname\csname iftagsleft@\endcsname
          L\else R\fi
      }%
    }
  \fi
}
\@ifpackagewith{amsmath}{fleqn}{%
  \def\eqindent{I}%
}{%
  \def\@tempa#1,fleqn.clo,#2#3\@nil{%
    \ifx @#2\relax\else \def\eqindent{I}\fi
  }%
  \@xp\@tempa\@filelist,fleqn.clo,@\@nil
  \if I\eqindent
  \else
    \@ifundefined{if@fleqn}{}{%
      \edef\eqindent{%
        \if TT\csname fi\endcsname\csname if@fleqn\endcsname
          I\else C\fi
      }%
    }%
  \fi
}
  \@ifundefined{mathindent}{%
    \newdimen\mathindent
  }{%
    \@ifundefined{@mathmargin}{}{%
      \mathindent\@mathmargin
    }%
  }
\let\EQ@hasLHS=\@False
\let\EQ@QED=\@empty
\def\mark@lhs#1{%
  \ifnum\lr@level<\@ne
    \let\mark@lhs\relax
    \global\let\EQ@hasLHS=\@True
    \global\let\EQ@prebin@space\EQ@prebin@space@a
    \mark@lhs@a
    \penalty9999 % instead of normal \rel@break
  % else no penalty = forbid break
  \fi
}
\def\mark@lhs@a{%
  \mskip\thickmuskip \@@vadjust{\penalty\tw@}\penalty-\@Mi\@@vadjust{}%
}
\newcommand\hiderel[1]{\mathrel{\advance\lr@level\@ne#1}}
%%%%\let\m@@Bin\m@Bin
%%%%%\let\m@@Rel\m@Rel
\let\EQ@prebin@space\relax
\def\EQ@prebin@space@a{\mskip-\eq@binoffset \keep@glue \mskip\eq@binoffset}
\def\bin@break{\ifnum\lastpenalty=\z@\penalty\prebinoppenalty\fi
  \EQ@prebin@space}
\def\rel@break{%
  \ifnum\abs@num\lastpenalty <\abs@num\prerelpenalty
    \penalty\prerelpenalty
  \fi
}
\ExplSyntaxOn
%%%\def\d@@Bin{\bin@break \m@@Bin}
%%%%\def\d@@Rel{\mark@lhs \rel@break \m@@Rel}
\cs_set:Npn \math_dsym_Bin:Nn {\bin@break\math_bsym_Bin:Nn}
\cs_set:Npn \math_dsym_Rel:Nn {\mark@lhs \rel@break \math_bsym_Rel:Nn }
\ExplSyntaxOff
\ExplSyntaxOn
%%\let\m@@symRel\@symRel
%%%\def\d@@symRel{\mark@lhs \rel@break \m@@symRel}

\cs_set_protected:Npn \math_dcsym_Bin:Nn {\bin@break \math_bcsym_Bin:Nn}
\cs_set_protected:Npn \math_dcsym_Rel:Nn { \mark@lhs \rel@break \math_bcsym_Rel:Nn}

%%\let\m@@symBin\@symBin \def\d@@symBin{\bin@break \m@@symBin}
%%\let\m@@symDel\@symDel
%%\let\m@@symDeR\@symDeR
%%\let\m@@symDeB\@symDeB
%%\let\m@@symDeA\@symDeA

\def\display@setup{%
  \medmuskip\Dmedmuskip \thickmuskip\Dthickmuskip
   \math_setup_display_symbols:
  %%\let\m@Bin\d@@Bin \let\m@Rel\d@@Rel
  %%\let\@symRel\d@@symRel \let\@symBin\d@@symBin
  %%\let\m@DeL\d@@DeL \let\m@DeR\d@@DeR \let\m@DeB\d@@DeB
  %%\let\m@DeA\d@@DeA
  %%\let\@symDeL\d@@symDeL \let\@symDeR\d@@symDeR
  %%\let\@symDeB\d@@symDeB \let\@symDeA\d@@symDeA
  \let\left\eq@left \let\right\eq@right \global\lr@level\z@
  \global\eq@wdCond\z@          %BRM: new
  \everyhbox{\everyhbox\@emptytoks
    \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
  }%
  \everyvbox{\everyvbox\@emptytoks
    \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
  }%
}
\def\dseries@display@setup{%
  \medmuskip\Dmedmuskip \thickmuskip\Dthickmuskip
  \math_setup_display_symbols:
%%%%  \let\m@Bin\d@@Bin
%%%\let\m@Rel\d@@Rel
%%%  \let\@symRel\d@@symRel
%%% \let\@symBin\d@@symBin
%%%  \let\m@DeL\d@@DeL \let\m@DeR\d@@DeR \let\m@DeB\d@@DeB
%%%  \let\m@DeA\d@@DeA
%%%  \let\@symDeL\d@@symDeL \let\@symDeR\d@@symDeR
%%%  \let\@symDeB\d@@symDeB \let\@symDeA\d@@symDeA
  \let\left\eq@left \let\right\eq@right \global\lr@level\z@
  \everyhbox{\everyhbox\@emptytoks
    \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
  }%
  \everyvbox{\everyvbox\@emptytoks
    \let\display@setup\relax \textmath@setup \let\textmath@setup\relax
  }%
 \displaystyle
}
\def\textmath@setup{%
   \math_setup_inline_symbols:
%%%%  \let\m@Bin\m@@Bin \let\m@Rel\m@@Rel
%%%%  \let\@symRel\m@@symRel \let\@symBin\m@@symBin
%%%%  \let\m@DeL\m@@DeL \let\m@DeR\m@@DeR \let\m@DeB\m@@DeB
%%%%  \let\m@DeA\m@@DeA
%%%%  \let\@symDeL\m@@symDeL \let\@symDeR\m@@symDeR
%%%%  \let\@symDeB\m@@symDeB \let\@symDeA\m@@symDeA
  \let\left\@@left \let\right\@@right
}

\ExplSyntaxOff
\@ifundefined{@displaytrue}{%
  \@xp\newif\csname if@display\endcsname
  \everydisplay\@xp{\the\everydisplay \@displaytrue}%
}{}
\define@key{breqn}{label}{%
  \edef\next@label{\noexpand\label{\next@label@pre#1}}%
  \let\next@label@pre\@empty}
\define@key{breqn}{labelprefix}{\def\next@label@pre{#1}}
\global\let\next@label\@empty
\global\let\next@label@pre\@empty
\define@key{breqn}{number}{\def\eq@number{#1}%
  \let\@currentlabel\eq@number
}
\define@key{breqn}{shiftnumber}{\let\eq@shiftnumber\@True}
\define@key{breqn}{holdnumber}{\let\eq@holdnumber\@True}
\define@key{breqn}{density}{\def\eq@density@factor{#1}}
\define@key{breqn}{indentstep}{\eqindentstep#1\relax}
\define@key{breqn}{compact}[-99]{\prerelpenalty=#1\relax}
\define@key{breqn}{layout}[?]{%
  \edef\eq@layout{\@car#1?\@nil}%
}
\define@key{breqn}{spread}{%
  \addtolength\eqlinespacing{#1}%
  \addtolength\eqlineskip{#1}%
  \eqlineskiplimit\eqlineskip
}
\define@key{breqn}{sidespace}{%
  \setlength\eq@given@sidespace{#1}%
}
\define@key{breqn}{style}{\eqstyle\@xp{\the\eqstyle #1}}
\define@key{breqn}{shortskiplimit}{\def\eq@shortskiplimit{#1}}
\def\eq@shortskiplimit{2em}
\define@key{breqn}{frame}[\fboxrule]{\def\eq@frame{T}%
  \dim@a#1\relax\edef\eq@framewd{\the\dim@a}%
  \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
}
\define@key{breqn}{fullframe}[]{\def\eq@frame{U}%
  \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
}
\def\eq@frame{F} % no frame
\def\eq@framewd{\fboxrule}
\define@key{breqn}{framesep}[\fboxsep]{%
  \if\eq@frame F\def\eq@frame{T}\fi
  \dim@a#1\relax \edef\eq@framesep{\the\dim@a}%
  \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
}
\def\eq@framesep{\fboxsep}
\define@key{breqn}{background}{\def\eq@background{#1}%
  \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
}
\define@key{breqn}{color}{\def\eq@foreground{#1}}
\define@key{breqn}{center}[]{\let\eq@centerlines\@True}
\define@key{breqn}{nocenter}[]{\let\eq@centerlines\@False}
\let\eq@centerlines\@False
\define@key{breqn}{noalign}[]{\let\grp@aligned\@False}
\let\grp@aligned\@True % default
\define@key{breqn}{breakdepth}{\eqbreakdepth#1\relax}
\define@key{breqn}{cols}{\global\let\@preamble\@empty
  \darray@mkpream#1\@percentchar
}
\newenvironment{dmath}{%
 \let\eq@hasNumber\@True \@optarg\@dmath{}}{}
\def\@dmath[#1]{%
  \everydisplay\expandafter{\the\everydisplay \display@setup}%
  \if@noskipsec \leavevmode \fi
  \if@inlabel \leavevmode \global\@inlabelfalse \fi
  \if\eq@group\else\eq@prelim\fi
  \setkeys{breqn}{#1}%
  \the\eqstyle
  \eq@setnumber
  \begingroup
  \eq@setup@a
  \eq@startup
}
\def\enddmath#1{\check@punct@or@qed}
\def\end@dmath{%
  \gdef\EQ@setwdL{}% Occasionally undefined ???
  \eq@capture
  \endgroup
  \EQ@setwdL
  \eq@measure
  \if\eq@group \grp@push \else \eq@finish\fi
}
\newenvironment{dmath*}{%
  \let\eq@hasNumber\@False \@optarg\@dmath{}%
}{}
\@namedef{end@dmath*}{\end@dmath}
\@namedef{enddmath*}#1{\check@punct@or@qed}
\def\eq@prelim{%
  \if@inlabel \indent \par \fi
  \if@nobreak \global\@nobreakfalse \predisplaypenalty\@M \fi
  \everypar\@emptytoks
  \noindent
  \eq@nulldisplay
  \par %% \eq@saveparinfo %% needs work
  \let\intertext\breqn@intertext
}
\def\breqn@parshape@warning{%
  \PackageWarning{breqn}{%
    Complex paragraph shape cannot be followed by this equation}%
}
\let\eq@prevshape\@empty
\def\eq@saveparinfo{%
  \count@\prevgraf \advance\count@-\thr@@ % for the null display
  \edef\eq@prevshape{\prevgraf\the\count@\space}%
  \ifcase\parshape
    % case 0: no action required
  \or \edef\eq@prevshape{\eq@prevshape
        \parshape\@ne\displayindent\displaywidth\relax
      }%
  \else
    \breqn@parshape@warning
  \fi
}
\def\eq@setnumber{%
  \eq@wdNum\z@
  \if\eq@hasNumber
    \ifx\eq@number\@empty
      \stepcounter{equation}\let\eq@number\theequation
    \fi
 % This sets up numbox, etc, even if unnumbered?????
    \ifx\eq@number\@empty
    \else
      \set@label{equation}\eq@number
      \global\sbox\EQ@numbox{%
        \next@label \global\let\next@label\@empty
        \eqnumcolor\eqnumsize\eqnumfont{\eqnumform{\eq@number}}%
      }%
      \global\eq@wdNum\wd\EQ@numbox\global\advance\eq@wdNum\eqnumsep
    \fi
  \fi
}
\newcount\eq@final@linecount
\let\eq@GRP@first@dmath\@True
\def\eq@finish{%
  \begingroup
    \if F\eq@frame\else
      \freeze@glue\eqlinespacing \freeze@glue\eqlineskip
    \fi
    \csname eq@\eqindent @setsides\endcsname % Compute \leftskip,\rightskip
    \adjust@parshape\eq@parshape% Final adjustment of parshape for left|right skips
    \if\eq@group
      \if\eq@GRP@first@dmath
        \global\let\eq@GRP@first@dmath\@False
        \xdef\dmath@first@leftskip{\leftskip=\the\leftskip\relax}%
      \else
        \eq@topspace{\vskip\parskip}% Set top spacing
      \fi
    \else
      \eq@topspace{\vskip\parskip}% Set top spacing
    \fi
    \afterassignment\remove@to@nnil
    \eq@final@linecount=\expandafter\@gobble\eq@parshape\@nnil
    \if\eq@hasNumber
      \if\eq@shiftnumber
        \csname eq@typeset@\eqnumside Shifted\endcsname
      \else
        \ifnum\eq@final@linecount=\@ne
          \csname eq@typeset@\eqnumside @single\endcsname
        \else
          \csname eq@typeset@\eqnumside\eqnumplace\endcsname
        \fi
      \fi
    \else
      \eq@typeset@Unnumbered
    \fi
  \endgroup
  \eq@botspace
}
\def\eq@typeset@L@single{%
  \nobreak
  \eq@params\eq@parshape
  \nointerlineskip\noindent
  \add@grp@label
  \rlap{\kern-\leftskip\box\EQ@numbox}%
  \if F\eq@frame
  \else
    \rlap{\raise\eq@firstht\hbox to\z@{\eq@addframe\hss}}%
  \fi
  \eq@dump@box\unhbox\EQ@box \@@par
}
\def\eq@typeset@R@single{%
  \nobreak
  \eq@params\eq@parshape
  \nointerlineskip\noindent
  \add@grp@label
  \if F\eq@frame
  \else
    \rlap{\raise\eq@firstht\hbox to\z@{\eq@addframe\hss}}%
  \fi
  \rlap{\kern-\leftskip\kern\linewidth\kern-\wd\EQ@numbox\copy\EQ@numbox}%
  \eq@dump@box\unhbox\EQ@box
  \@@par
}
\def\peek@branch#1#2{%
  \let\peek@b#1\let\peek@space#2\futurelet\@let@token\peek@a
}
\def\peek@skipping@spaces#1{\peek@branch#1\peek@skip@space}
\def\peek@a{%
  \ifx\@let@token\@sptoken \expandafter\peek@space
  \else \expandafter\peek@b\fi
}
\lowercase{\def\peek@skip@space} {\futurelet\@let@token\peek@a}%
\def\check@punct{\futurelet\@let@token\check@punct@a}
\def\check@punct@a{%
  \edef\@tempa{%
    \ifx\@let@token\@sptoken\@nx\finish@end
    \else\ifx\@let@token ,\@nx\check@qed
    \else\ifx\@let@token .\@nx\check@qed
    \else\check@punct@b % check the less common possibilities
    \fi\fi\fi
  }%
  \@tempa
}
\begingroup
\toks@a{%
  \ifx\@let@token ;\@nx\check@qed
  \else\ifx\@let@token ?\@nx\check@qed
  \else\ifx\@let@token !\@nx\check@qed
}
\toks@c{\fi\fi\fi}% matching with \toks@a
\catcode`\.=\active \catcode`\,=\active \catcode`\;=\active
\catcode`\?=\active \catcode`\!=\active
\toks@b{%
  \else\ifx\@let@token ,\@nx\check@qed
  \else\ifx\@let@token .\@nx\check@qed
  \else\ifx\@let@token ;\@nx\check@qed
  \else\ifx\@let@token ?\@nx\check@qed
  \else\ifx\@let@token !\@nx\check@qed
  \else\@nx\finish@end
  \fi\fi\fi\fi\fi
}
\xdef\check@punct@b{%
  \the\toks@a\the\toks@b\the\toks@c
}
\endgroup
\let\found@punct\@empty
\def\check@qed#1{%
  \gdef\found@punct{#1}%
  \peek@skipping@spaces\check@qed@a
}
\def\check@qed@a{%
  \ifx\end\@let@token \@xp\check@qed@b
  \else \@xp\finish@end
  \fi
}
\def\check@qed@b#1#2{%
  \@ifundefined{#2qed}{}{%
    \toks@\@xp{\found@punct\csname#2qed\endcsname}%
    \xdef\found@punct{\the\toks@}%
  }%
  \finish@end
  \end{#2}%
}
\def\@tempa#1\endcsname#2\@nil{\def\latex@end##1{#2}}
\expandafter\@tempa\end{#1}\@nil
\def\end#1{\csname end#1\endcsname \latex@end{#1}}%
\def\check@punct@or@qed#1{%
  \xdef\found@punct{\@empty}% BRM: punctuation was being remembered past this eqn.
  % WSPR: err, why isn't that just \global\let\found@punct\@empty ?
  \def\finish@end{\csname end@#1\endcsname\latex@end{#1}}%
  \check@punct
}
\newcommand\eqpunct[1]{\thinspace#1}
\providecommand\set@label[2]{\protected@edef\@currentlabel{#2}}
\def\eq@topspace#1{%
  \begingroup
    \global\let\EQ@shortskips\@False
    \if\@And{\eq@group}{\@Not\eq@GRP@first@dmath}%
        \parskip\intereqskip \penalty\intereqpenalty
    \else
      \eq@check@shortskip
      \if\EQ@shortskips
        \parskip\abovedisplayshortskip
        \aftergroup\belowdisplayskip\aftergroup\belowdisplayshortskip
        \ifdim\predisplaysize>\z@\nointerlineskip\fi
      \else
        \parskip\abovedisplayskip
      \fi
    \fi
    \if F\eq@frame
    \else
      \addtolength\parskip{\eq@framesep+\eq@framewd}%
    \fi
    #1%
  \endgroup
}
\def\eq@check@shortskip {%
  \global\let\EQ@shortskips\@False
  \setlength\dim@a{\abovedisplayskip+\ht\EQ@numbox}%
  \ifdim\leftskip<\predisplaysize
  \else
    \ifdim -\maxdimen=\predisplaysize
    \else
      \if R\eqnumside
        \global\let\EQ@shortskips\@True
      \else
        \if\eq@shiftnumber
        \else
          \if T\eqnumplace
            \ifdim\dim@a<\eq@firstht
              \global\let\EQ@shortskips\@True
            \fi
          \else
            \setlength\dim@b{\eq@vspan/2}%
            \ifdim\dim@a<\dim@b
              \global\let\EQ@shortskips\@True
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}
\def\eq@botspace{%
  \penalty\postdisplaypenalty
  \if F\eq@frame
  \else
    \addtolength\belowdisplayskip{\eq@framesep+\eq@framewd}%
  \fi
  \vskip\belowdisplayskip
  \@endpetrue % kill parindent if current paragraph continues
  \global\@ignoretrue % ignore following spaces
  \eq@resume@parshape
}
\def\eq@resume@parshape{}
\def\eq@startup{%
  \global\let\EQ@hasLHS\@False
  \setbox\z@\vbox\bgroup
    \noindent \@@math \displaystyle
    \penalty-\@Mi
}
\def\eq@setup@a{%
  \everymath\everydisplay
  %\let\@newline\eq@newline % future possibility?
  \let\\\eq@newline
  \let\insert\eq@insert \let\mark\eq@mark \let\vadjust\eq@vadjust
  \hsize\maxdimen \pretolerance\@M
  \linepenalty\@m
  \rightskip\z@\@plus\@M\p@ \leftskip\z@skip \parfillskip\z@skip
  \clubpenalty\@ne \widowpenalty\z@ \interlinepenalty\z@
  \global\let\EQ@prebin@space\relax
  \binoppenalty\@M \relpenalty\@M
}
\newdimen\eq@wdR\eq@wdR\z@%BRM
\def\eq@capture{%
  \ifnum\lastpenalty>-\@M \penalty-\@Mi \fi
  \keep@glue\@@endmath
  \eq@addpunct
  \@@par
  \eq@wdL\z@
  \setbox\tw@\lastbox
  \global\setbox\EQ@box\hbox{\unhbox\tw@\unskip\unskip\unpenalty}%
  \unskip\unpenalty
  \global\setbox\EQ@copy\copy\EQ@box
%%  \global\setbox\EQ@vimcopy\copy\EQ@vimbox
  \clubpenalty\z@
  \eq@wdR\z@%BRM: eq@wdL patch
  \eq@repack % recursive
  \setbox\tw@\lastbox
  \global\setbox\EQ@box\hbox{\unhcopy\tw@\unskip\unpenalty \unhbox\EQ@box}%
  \global\setbox\EQ@copy\hbox{\unhbox\tw@\unskip\unpenalty \unhbox\EQ@copy}%
  \ifdim\eq@wdR>\z@% BRM:  eq@wdL patch
    \setlength\dim@a{\wd\EQ@box-\eq@wdR
    % Apparently missing a \thickmuskip = 5mu = 5/18em=0.27777777777.. ?
       + 0.2777777777777em}% FUDGE??!?!?!
    \ifdim\dim@a>\eq@wdL
      \eq@wdL\dim@a
      \xdef\EQ@setwdL{\eq@wdL\the\eq@wdL\relax}%
    \fi
  \fi
  \egroup % end vbox started earlier
}
\def\eq@addpunct{%
  \ifx\found@punct\@empty
  \else \eqpunct{\found@punct}%
  \fi
  % BRM: Added; the punctuation kept  getting carried to following environs
  \xdef\found@punct{\@empty}%
  \EQ@afterspace
}
\global\let\EQ@afterspace\@empty
\def\eq@repack{%
  \ifcase\lastpenalty
     % case 0: normal case
    \setbox\tw@\lastbox
    \eq@repacka\EQ@copy \eq@repacka\EQ@box
    \unskip
  \or % case 1: finished recursing
    \unpenalty
    \setbox\tw@\lastbox
    \eq@repacka\EQ@copy \eq@repacka\EQ@box
    \@xp\@gobble
  \or % case 2: save box width = LHS width
    \unpenalty
    \setbox\tw@\lastbox
    \setbox\z@\copy\tw@ \setbox\z@\hbox{\unhbox\z@\unskip\unpenalty}%
    \addtolength\eq@wdL{\wd\z@}
    \setlength\eq@wdR{\wd\EQ@box}% BRM:  eq@wdL patch
    \xdef\EQ@setwdL{\eq@wdL\the\eq@wdL\relax}%
    \global\setbox\EQ@copy\hbox{%
      \hbox{\unhcopy\tw@\unskip\unpenalty\unskip}%
      \box\EQ@copy
    }%
    \global\setbox\EQ@box\hbox{%
      \hbox{\unhbox\tw@\unskip\unpenalty\unskip}%
      \box\EQ@box
    }%
    \unskip
  \or % case 3: unpack left-right box
    \unpenalty
    \eq@lrunpack
  \else
    \breqn@repack@err
  \fi
  \eq@repack % RECURSE
}
\def\breqn@repack@err{%
  \PackageError{breqn}{eq@repack penalty neq 0,1,2,3}\relax
}
\def\eq@repacka#1{%
  \global\setbox#1\hbox{\unhcopy\tw@ \unskip
    \count@-\lastpenalty
    \ifnum\count@<\@M \else \advance\count@-\@M \fi
    \unpenalty
    \ifx\EQ@copy#1\ifnum\count@>\thr@@ \count@\@ne\fi\fi
    \ifcase\count@
        % case 0, normal line break
      \penalty-\@M % put back the linebreak penalty
    \or % case 1, do nothing (end of equation)
      \relax
    \or % case 2, no-op (obsolete case)
    \or % case 3, transfer vspace and/or penalty
      \ifx#1\EQ@box \eq@revspace \else \eq@revspaceb \fi
    \or % case 4, put back an insert
      \eq@reinsert
    \or % case 5, put back a mark
      \eq@remark
    \or % case 6, put back a vadjust
      \eq@readjust
    \else % some other break penalty
      \penalty-\count@
    \fi
    \unhbox#1}%
}
\def\eq@nulldisplay{%
  \begingroup \frozen@everydisplay\@emptytoks
  \@@display
  \predisplaypenalty\@M \postdisplaypenalty\@M
  \abovedisplayskip\z@skip \abovedisplayshortskip\z@skip
  \belowdisplayskip\z@skip \belowdisplayshortskip\z@skip
  \xdef\EQ@displayinfo{%
    \prevgraf\the\prevgraf \predisplaysize\the\predisplaysize
    \displaywidth\the\displaywidth \displayindent\the\displayindent
    \listwidth\the\linewidth
    \ifdim\displayindent>\z@
      \advance\listwidth\the\leftmargin
      \advance\listwidth\the\rightmargin
    \fi
    \relax}%
  \halign{##\cr}%
  \@@enddisplay
  \par
  \endgroup
  \EQ@displayinfo
}
\def\eq@newline{%
  \@ifstar{\eq@newlinea\@M}{\eq@newlinea\eqinterlinepenalty}}
\def\eq@newlinea#1{%
  \@ifnext[{\eq@newlineb{#1}}{\eq@newlineb{#1}[\maxdimen]}}
\def\eq@newlineb#1[#2]{\penalty-\@M}
\def\eq@revspace{%
  \global\setbox\EQ@vimbox\vbox{\unvbox\EQ@vimbox
    \unpenalty
    \global\setbox\@ne\lastbox}%
  \@@vadjust{\unvbox\@ne}%
  \penalty-\@M
}
\def\eq@revspaceb{%
  \global\setbox\EQ@vimcopy\vbox{\unvbox\EQ@vimcopy
    \unpenalty
    \global\setbox\@ne\lastbox}%
  \@@vadjust{\unvbox\@ne}%
  \penalty-\@M
}
\def\eq@break#1{\penalty-1000#1 \keep@glue}
\let\@parshape\@empty
\def\eq@measure{%
  \ifdim\eq@indentstep=\maxdimen \eq@indentstep\eqindentstep \fi
  \ifdim\eq@linewidth=\z@ \else \edef\eq@linewidths{{\the\eq@linewidth}}\fi
  \begingroup \eq@params
  \leftskip\z@skip
  \rightskip\z@\@plus\columnwidth\@minus\hfuzz
  \global\EQ@continue{\eq@trial}%
  \eq@trial % uses \eq@linewidths
  \eq@failout % will be a no-op if the trial succeeded
  \endgroup
  \EQ@trial
}
\let\EQ@trial\@empty
\newtoks\EQ@continue
\let\EQ@widths\@empty
\let\EQ@fallback\@empty
\def\eq@linewidths{\displaywidth\linewidth\columnwidth}
\def\eq@trial{%
  \ifx\@empty\eq@linewidths
    \global\EQ@continue{}%
  \else
    \iffalse{\fi \@xp\eq@trial@a \eq@linewidths}%
  \fi
  \the\EQ@continue
}
\def\eq@trial@a#1{%
  \dim@c#1\relax
  \if T\eq@frame \eq@frame@adjust\dim@c \fi
  \ifdim\dim@c>\eq@linewidth
    \eq@linewidth\dim@c
    \let\eq@trial@b\eq@trial@d
    \csname eq@try@layout@\eq@layout\endcsname
  \fi
  \edef\eq@linewidths{\iffalse}\fi
}
\def\eq@frame@adjust#1{%
  %\addtolength#1{-2\eq@framewd-2\eq@framesep}%
  \dim@a\eq@framewd \advance\dim@a\eq@framesep
  \advance#1-2\dim@a
}
\def\eq@trial@succeed{%
  \aftergroup\@gobbletwo % cancel the \EQ@fallback code; see \eq@trial@c (?)
  \global\EQ@continue{\eq@trial@done}%
}
\def\eq@trial@done{%
  \let\eq@failout\relax
}
\def\eq@trial@init{\global\let\EQ@fallback\eq@nextlayout}
\def\eq@nextlayout#1{%
  \endgroup
  \begingroup #1%
}
\def\eq@failout{%
  \global\let\EQ@trial\EQ@last@trial
}
\def\eq@trial@save#1{%
  \xdef#1{%
    \eq@linewidth\the\eq@linewidth
    % save info about the fit
    \eq@lines\the\eq@lines \eq@badness\the\eq@badness \def\@nx\eq@badline{\eq@badline}%
    % save size info
    \eq@wdT\the\eq@wdT \eq@wdMin\the\eq@wdMin
    \eq@vspan\the\eq@vspan \eq@dp\the\eq@dp \eq@firstht\the\eq@firstht
    % save info about the LHS
    \eq@wdL\the\eq@wdL \def\@nx\EQ@hasLHS{\EQ@hasLHS}%
    % save info about the numbering
    \def\@nx\eq@hasNumber{\eq@hasNumber}%
    % save info about the chosen layout
    \def\@nx\eq@layout{\eq@layout}%
    \def\@nx\eq@parshape{\@parshape}%
    \def\@nx\eq@measurements{\eq@measurements}%
    \def\@nx\adjust@rel@penalty{\adjust@rel@penalty}%
    \def\@nx\eq@shiftnumber{\eq@shiftnumber}%
    \def\@nx\eq@isIntertext{\@False}%
  }%
}
\def\eq@trial@b{\eq@trial@c}
\def\eq@trial@c#1#2{%
  \begingroup
  \eq@trial@init
  \def\eq@layout{#1}%
  \setbox\z@\vbox{%
    \hfuzz\maxdimen
    \eq@trial@p % run the given parshape
    \if\@Not{\eq@badline}%
      \eq@trial@save\EQ@trial
      \if\eq@hasNumber\eq@retry@with@number\fi
      \if L\eq@layout \eq@check@density
      \else
        \if\@Not{\eq@badline}%
           \eq@trial@succeed
        \fi
      \fi
    \else
      \eq@trial@save\EQ@last@trial
    \fi
  }%
  \EQ@fallback{#2}%
  \endgroup
}
\def\eq@trial@d#1#2{\eq@trial@c{#1}{}}
\def\eq@check@density{%
  \if\@Or{\@Not\EQ@hasLHS}{\eq@shortLHS}%
    \eq@trial@succeed
  \else\if\eq@dense@enough
    \eq@trial@succeed
  \fi\fi
}
\def\eq@shortLHS{\ifdim\eq@wdL>.44\eq@wdT 1\else 0\fi 0}
\def\eq@trial@p{%
  \@parshape %
  \eq@dump@box\unhcopy\EQ@copy
  {\@@par}% leave \parshape readable
  \eq@lines\prevgraf
  \eq@fix@lastline
  \let\eq@badline\@False
  \if i\eq@layout \ifnum\eq@lines>\@ne \let\eq@badline\@True \fi\fi
  \eq@curline\eq@lines % loop counter for eq@measure@lines
  \let\eq@measurements\@empty
  \eq@ml@record@indents
  \eq@measure@lines
  \eq@recalc
}
\let\adjust@rel@penalty\@empty
\def\eq@fix@lastline{%
  \setbox\tw@\lastbox \dim@b\wd\tw@
  \eq@dp\dp\tw@
  \nointerlineskip\hbox to\dim@b{\unhbox\tw@
    \skip@c\lastskip \unskip\unskip\hskip\skip@c
  }%
}
\def\eq@recalc{%
  \eq@wdT\z@ \eq@wdMin\maxdimen \eq@vspan\z@skip \eq@badness\z@
  \let\@elt\eq@recalc@a \eq@measurements \let\@elt\relax
}
\def\eq@recalc@a#1x#2+#3\@endelt{%
  \eq@firstht#2\relax
  \let\@elt\eq@recalc@b
  \@elt#1x#2+#3\@endelt
}
\def\eq@recalc@b#1X#2,#3x#4+#5@#6\@endelt{%
  \setlength\dim@a{#2+#3}%
  \ifdim\dim@a>\eq@wdT \eq@wdT\dim@a \fi
  \ifdim\dim@a<\eq@wdMin \eq@wdMin\dim@a \fi
  \eq@dp#5\relax
  \addtolength\eq@vspan{#1+#4+\eq@dp}%
  \ifnum#6>\eq@badness \eq@badness#6\relax\fi
}
\def\eq@layout{?}
\@namedef{eq@try@layout@?}{%
  \let\eq@trial@b\eq@trial@c
  \edef\@parshape{\parshape 1 0pt \the\eq@linewidth\relax}%
  \setlength\dim@a{\wd\EQ@copy-2em}% Fudge; can't shrink more than this?
  % if we're in a numbered group, try hard to fit within the numbers
  \dim@b\eq@linewidth
  \if\eq@shiftnumber\else\if\eq@group
    \if\eq@hasNumber\addtolength\dim@b{-\wd\EQ@numbox-\eqnumsep}%
    \else\if\grp@hasNumber\addtolength\dim@b{-\wd\GRP@numbox-\eqnumsep}%
  \fi\fi\fi\fi
  \ifdim\dim@a<\dim@b% Do we even have a chance of fitting to one line?
    \setlength\dim@b{\columnwidth-\dim@a+\eq@wdCond}%
    \rightskip\z@\@plus\dim@b\@minus\hfuzz
    \eq@trial@b{i}{\eq@try@layout@multi}%
  \else
   \eq@try@layout@multi
  \fi
}
\def\eq@try@layout@multi{%
  \if\EQ@hasLHS
    \ifdim\eq@wdL>\eq@linewidth
       \setlength\dim@a{\wd\EQ@copy-\eq@wdL}%
       \ifdim\dim@a<.25\eq@linewidth \eq@try@layout@S
       \else \eq@try@layout@l
       \fi
    % BRM: Originally .7: Extreme for L since rhs has to wrap within the remaining 30+%!
    \else\ifdim\eq@wdL>.50\eq@linewidth
      \eq@try@layout@D
    \else
      \eq@try@layout@L
    \fi\fi
  \else
    \eq@try@layout@S % (already checked case i)
  \fi
}
\def\eq@try@layout@D{%
  \setlength\dim@a{\eq@linewidth -\eq@indentstep}%
  \edef\@parshape{\parshape 2
    0pt \the\eq@wdL\space \the\eq@indentstep\space \the\dim@a\relax
  }%
  \def\adjust@rel@penalty{\penalty-99 }%
  \eq@trial@b{D}{\eq@try@layout@A}%
}
\def\eq@try@layout@L{%
  \setlength\dim@b{\eq@linewidth-\eq@wdL}%
  \edef\@parshape{\parshape 2 0pt \the\eq@linewidth\space
    \the\eq@wdL\space \the\dim@b\relax
  }%
  \eq@trial@b{L}{\eq@try@layout@D}%
}
\def\eq@try@layout@S{%
  \setlength\dim@b{\eq@linewidth-2\eqmargin}% \advance\dim@b-1em%
  \int@a\wd\EQ@copy \divide\int@a\dim@b
  \addtolength\dim@b{-\int@a\eq@indentstep}%
  \if\eq@hasNumber
    \ifdim\dim@b>15em%
      \addtolength\dim@b{-\eq@wdNum}%
    \fi
  \fi
  \int@b\z@
  \def\@tempa{\dim}%
  \edef\@parshape{\parshape 2 0pt \the\dim@b\space
    \the\eqmargin\space\the\dim@b\relax}%
  \eq@trial@b{S}{\eq@try@layout@A}%
}
\def\eq@try@layout@l{%
  \setlength\dim@a{\eq@linewidth -\eq@indentstep}%
  \int@a\eq@wdL \divide\int@a\dim@a
  \advance\int@a\tw@
  \edef\@parshape{\parshape \number\int@a\space
    0pt \the\eq@linewidth
  }%
  \advance\int@a-\tw@
  \setlength\dim@b{2\eq@indentstep}%
  \setlength\dim@c{\eq@linewidth -\dim@b}%
  \edef\@parshape{\@parshape
    \replicate{\int@a}{\space\the\eq@indentstep\space\the\dim@a}%
    \space\the\dim@b\space\the\dim@c\relax
  }%
  \eq@trial@b{l}{\eq@try@layout@A}%
}
\def\eq@try@layout@A{%
  \edef\@parshape{\parshape 1 0pt \the\eq@linewidth\relax}%
  \if\EQ@hasLHS \def\adjust@rel@penalty{\penalty-99 }\fi
  \eq@trial@b{A}{}%
}
\let\eq@shiftnumber\@False
\def\eq@retry@with@number{%
 \if\eq@shiftnumber
 \else
    \ifdim\eq@wdCond>\z@\if R\eqnumside
      \let\eq@shiftnumber\@True
    \fi\fi
    \dim@b\eq@wdNum
    \if L\eqnumside
      \ifdim\@totalleftmargin>\dim@b\dim@b\@totalleftmargin\fi
    \else
      \addtolength\dim@b{\@totalleftmargin}%
    \fi
    \setlength\dim@a{\eq@linewidth-\dim@b}%\advance\dim@a1em\relax% Allowance for shrink?
    \int@a\@ne\if\eq@group\int@a\maxint\fi
    \if\eq@shiftnumber               % Already know we need to shift
    \else\ifdim\eq@wdT<\dim@a % Fits!
    \else
      \setlength\leftskip{\eq@wdNum}%
      \setlength\rightskip{\z@\@plus\dim@a}%
      \adjust@parshape\@parshape
      \nointerlineskip
      \edef\eq@prev@lines{\the\eq@lines}%
      \edef\eq@prev@badness{\the\eq@badness}% BRM
      \eq@trial@p
      \int@a\eq@prev@badness\relax\advance\int@a 50\relax%?
      \int@b\eq@prev@lines  \if\eq@group\advance\int@b\@ne\fi% Allow 1 extra line in group
      \ifnum\eq@lines>\int@b % \eq@prev@lines
        \let\eq@shiftnumber\@True
      \else\if\eq@badline
        \let\eq@shiftnumber\@True
      \else\ifnum\eq@badness>\int@a % BRM: New case
        \let\eq@shiftnumber\@True
      \else
      \fi\fi%\fi
   \fi\fi\fi
   \if\eq@shiftnumber
     \EQ@trial% Restore parshape & other params,
     \leftskip\z@\let\eq@shiftnumber\@True % But set shift & leftskip
     \edef\@parshape{\eq@parshape}% And copy saved parshape back to `working copy' !?!?
   \fi
   \eq@trial@save\EQ@trial      % Either way, save the trial state.
 \fi
}
\def\adjust@parshape#1{%
  \@xp\adjust@parshape@a#1\relax
  \edef#1{\temp@a}%
}
\def\adjust@parshape@a#1 #2\relax{%
  \setlength\dim@a{\leftskip+\rightskip}%
  \edef\temp@a{#1}%
  \adjust@parshape@b#2 @ @ \relax
}
\def\adjust@parshape@b#1 #2 {%
  \ifx @#1\edef\temp@a{\temp@a\relax}%
    \@xp\@gobble
  \else
    \dim@b#1\relax
    \dim@c#2\relax
    \addtolength\dim@c{\dim@a+\dim@b}%
    \ifdim\dim@c>\eq@linewidth\setlength\dim@c{\eq@linewidth}\fi
     \addtolength\dim@c{-\dim@b}%
    \edef\temp@a{\temp@a\space\the\dim@b\space\the\dim@c}%
  \fi
  \adjust@parshape@b
}
\def\eq@ml@record@indents{%
  \int@a\z@
  \def\@tempa{%
    \advance\int@a\@ne
    \@xp\edef\csname eq@i\number\int@a\endcsname{\the\dim@a}%
    \ifnum\int@a<\int@b \afterassignment\@tempb \fi
    \dim@a
  }%
  \def\@tempb{\afterassignment\@tempa \dim@a}%
  \def\@tempc##1##2 {\int@b##2\afterassignment\@tempa\dim@a}%
  \@xp\@tempc\@parshape
}
\chardef\@endelt=`\?
\def\eq@measurements{%
  \@elt 4.5pt/5.0pt,66.0ptx6.8pt+2.4pt@27\@endelt
  ...
}
\def\eq@measure@lines{%
  \let\eq@ml@continue\eq@measure@lines
  \setbox\tw@\lastbox \dim@b\wd\tw@ % find target width of line
  \setbox\z@\hbox to\dim@b{\unhbox\tw@}% check for overfull
  \eq@badness\badness
  \ifnum\eq@badness<\inf@bad \else \let\eq@badline\@True \fi
  \eq@ml@a \eq@ml@continue
}
\def\eq@ml@a{%
  \setbox\tw@\hbox{\unhbox\z@ \unskip}% find natural width
  \ifdim\dim@b<\wd\tw@ \setlength\dim@a{\dim@b}% shrunken line
  \else                \setlength\dim@a{\wd\tw@}% OK to use natural width
  \fi
  \addtolength\dim@a{-\leftskip}% BRM: Deduct the skip if we're retrying w/number
  \skip@a\lastskip \unskip \unpenalty
  \ifdim\skip@a=\z@
    \let\eq@ml@continue\relax % end the recursion
  \else
    % Sum repeated vskips if present
    \def\@tempa{%
      \ifdim \lastskip=\z@
      \else \addtolength\skip@a{\lastskip}\unskip\unpenalty \@xp\@tempa
      \fi
    }%
  \fi
  \edef\eq@measurements{\@elt
    \the\skip@a\space X% extra space to facilitate extracting only the
                        % dimen part later
    \csname eq@i%
      \ifnum\eq@curline<\parshape \number\eq@curline
      \else\number\parshape
      \fi
    \endcsname,\the\dim@a x\the\ht\tw@+\the\dp\tw@ @\the\eq@badness\@endelt
    \eq@measurements
  }%
  \advance\eq@curline\m@ne
  \ifnum\eq@curline=\z@ \let\eq@ml@continue\relax\fi
}
\def\eq@ml@vspace{%
  \global\advance\eq@vspan\lastskip \unskip\unpenalty
  \ifdim\lastskip=\z@ \else \@xp\eq@ml@vspace \fi
}
\def\eq@dense@enough{%
  \ifnum\eq@lines<\thr@@
    \@True
  \else
    \ifdim\eq@wdL >.7\eq@wdT
      \@False
    \else \@xp\@xp\@xp\eq@dense@enough@a
    \fi
  \fi
}
\def\true@true@true   {\fi\fi\iftrue \iftrue \iftrue }
\def\true@false@true  {\fi\fi\iftrue \iffalse\iftrue }
\def\false@true@false {\fi\fi\iffalse\iftrue \iffalse}
\def\false@false@false{\fi\fi\iffalse\iffalse\iffalse}
\def\eq@density@factor{.475}
\def\eq@dense@enough@a{%
  \@True \fi
  \ifnum\eq@lines>\sixt@@n
    \eq@dense@enough@b
  \else
    \dim@b\z@ \let\@elt\eq@delt \eq@measurements
    \dim@c\eq@density@factor\eq@wdT \multiply\dim@c\eq@lines
    \ifdim\dim@b>\dim@c \true@false@true \else \false@false@false \fi
  \fi
}
\def\eq@delt#1X#2,#3x#4+#5@#6\@endelt{\addtolength\dim@b{#3}}%
\def\eq@dense@enough@b{%
  \int@b\eq@wdT \divide\int@b\p@
  \dim@b\eq@wdL \divide\dim@b\int@b
  \dim@c\eq@lines\p@ \multiply\dim@c\f@ur
  \int@b\eq@lines \multiply\int@b 9 \advance\int@b -10%
  \divide\dim@c\int@b
  \ifdim\dim@b<\dim@c \true@true@true \else \false@true@false \fi
}
\let\eq@parshape\@empty
\def\eq@params{%
  \baselineskip\eqlinespacing
  \lineskip\eqlineskip \lineskiplimit\eqlineskiplimit
  \clubpenalty\@M \widowpenalty\@M \interlinepenalty\eqinterlinepenalty
  \linepenalty199 \exhyphenpenalty5000 % was 9999: make breaks at, eg. \* a bit easier.
  \ifdim\hfuzz<\p@ \hfuzz\p@ \fi
  \parfillskip\z@skip
  \tolerance9999 \pretolerance\m@ne
}
\def\eq@dump@box#1#2{%
  \noindent #1#2\setbox\f@ur\lastbox \setbox\tw@\lastbox
  \if L\eq@layout \box\tw@ \else\unhbox\tw@\fi
  \adjust@rel@penalty \unhbox\f@ur
}
\def\eq@typeset@Unnumbered{%
  \eq@typeset@frame
  \eq@typeset@equation
}
\def\eq@typeset@LM{%
  \setlength\dim@a{(\eq@vspan+\ht\EQ@numbox-\dp\EQ@numbox)/2}%
  \eq@typeset@leftnumber
  \eq@typeset@frame
  \eq@typeset@equation
}
\def\eq@typeset@LT{%
  \dim@a\eq@firstht
  \eq@typeset@leftnumber
  \eq@typeset@frame
  \eq@typeset@equation
}
\def\eq@typeset@LShifted{%
  % place number
  \copy\EQ@numbox \penalty\@M
  \dim@a\eqlineskip
  \if F\eq@frame\else
     \setlength\dim@a{\eq@framesep+\eq@framewd}%
  \fi
  \kern\dim@a
  \eq@typeset@frame
  \eq@typeset@equation
}
\def\eq@typeset@RM{%
  \setlength\dim@a{(\eq@vspan+\ht\EQ@numbox-\dp\EQ@numbox)/2}%
  \eq@typeset@rightnumber
  \eq@typeset@frame
  \eq@typeset@equation
}
\def\eq@typeset@RB{%
  % NOTE: is \eq@dp useful here
  \setlength\dim@a{\eq@vspan-\ht\EQ@numbox-\dp\EQ@numbox}%
  \eq@typeset@rightnumber
  \eq@typeset@frame
  \eq@typeset@equation
}
\def\eq@typeset@RShifted{%
  % place number
  \eq@typeset@frame
  \eq@typeset@equation
  \penalty\@M
  \dim@a\eqlineskip
  \if F\eq@frame\else
    \addtolength\dim@a{\eq@framesep+\eq@framewd}%
  \fi
  \parskip\dim@a
  \hbox to\hsize{\hfil\copy\EQ@numbox}\@@par%
}
\def\eq@C@setsides{%
  % \dim@c = space for number, if any, and not shifted.
  \dim@c\z@
  \if\eq@hasNumber\if\eq@shiftnumber\else
    \dim@c\eq@wdNum
  \fi\fi
  % \dim@e = space for condition(on right), if any and formula is only a single line.(to center nicely)
  % but only count it as being right-aligned if we're not framing, since the frame must enclose it.
  \dim@e\z@
  \if F\eq@frame
    \ifnum\eq@lines=\@ne\ifdim\eq@wdCond>\z@
      \setlength\dim@e{\eq@wdCond+\conditionsep}%
  \fi\fi\fi
  % \dim@b = minimum needed on left max(totalleftmargin, left number space)
  \dim@b\z@
  \if L\eqnumside\ifdim\dim@b<\dim@c
    \dim@b\dim@c
  \fi\fi
  \ifdim\dim@b<\@totalleftmargin
    \dim@b\z@
  \else
    \addtolength\dim@b{-\@totalleftmargin}%
  \fi
  % \dim@d = minimum needed on right max(condition, right number space)
  \dim@d\dim@e
  \if R\eqnumside\ifdim\dim@d<\dim@c
    \dim@d\dim@c
  \fi\fi
  % \dim@a = left margin; initially half available space
  % \dim@c = right margin;  ditto
  \setlength\dim@a{(\eq@linewidth-\eq@wdT+\dim@e+\@totalleftmargin)/2}%
  \dim@c=\dim@a
  % If too far to the left
  \ifdim\dim@a<\dim@b
     \addtolength\dim@c{\dim@a-\dim@b}%
     \ifdim\dim@c<\z@\dim@c=\z@\fi
     \dim@a=\dim@b
  % Or if too far to the right
  \else\ifdim\dim@c<\dim@d
     \addtolength\dim@a{\dim@c-\dim@d}%
     \ifdim\dim@a<\z@\dim@a=\z@\fi
     \dim@c=\dim@d
  \fi\fi
  % Now, \dim@d,\dim@e is the left & right glue to center each line for centerlines
  \setlength\dim@e{\eq@wdT-\eq@wdMin}\dim@d=\z@
  \dim@d\z@
  \if\eq@centerlines
    \divide\dim@e2\relax
    \dim@d=\dim@e
  \fi
  \setlength\leftskip{\dim@a\@plus\dim@d}%
  \addtolength\dim@e{\dim@c}%
  \setlength\rightskip{\z@\@plus\dim@e}%\@minus5\p@
  % Special case: if framing, reduce the stretchiness of the formula (eg. condition)
  % Or if we have a right number, FORCE space for it
  \dim@b\z@
  \if F\eq@frame\else
    \dim@b\dim@c
  \fi
  \if\@And{\eq@hasNumber}{\@Not{\eq@shiftnumber}}%
    \if R\eqnumside
      \dim@c\eq@wdNum
      \ifdim\dim@c>\dim@b
        \dim@b\dim@c
      \fi
    \fi
  \fi
  % If either of those cases requires hard rightskip, move that part from glue.
  \ifdim\dim@b>\z@
    \addtolength\dim@e{-\dim@c}%
    \rightskip\dim@b\@plus\dim@e%\@minus5\p@
  \fi
  % And peculiar further special case: in indented environs, width isn't where it would seem
  \ifdim\eq@wdCond>\z@
    \addtolength\rightskip{-\@totalleftmargin}%
  \fi
  \parfillskip\z@skip
}
\def\eq@I@setsides{%
  \leftskip\mathindent
  \if\eq@shiftnumber
    \setlength\dim@a{\eq@linewidth-\eq@wdT-\mathindent}%
    \ifdim\dim@a<\z@
      \leftskip=\z@ % Or something minimal?
    \fi
  \fi
  \dim@a=\z@
  \setlength\dim@b{\eq@linewidth-\leftskip-\eq@wdMin}%
  \if F\eq@frame
  \else
    \setlength\dim@a{\eq@linewidth-\leftskip-\eq@wdT}
    \addtolength\dim@b{-\dim@a}%
  \fi
  % Or force the space for right number, if needed
  \if\@And{\eq@hasNumber}{\@Not{\eq@shiftnumber}}%
    \if R\eqnumside
      \dim@c=\eq@wdNum
      \if\dim@c>\dim@a
        \addtolength\dim@b{-\dim@c}%
        \dim@a=\dim@c
      \fi
    \fi
  \fi
  \setlength\rightskip{\dim@a\@plus\dim@b \@minus\hfuzz }%\hfuzz\z@
  \parfillskip\z@skip
}
\def\eq@typeset@leftnumber{%
  \setlength\skip@c{\dim@a-\ht\EQ@numbox}%
  \vglue\skip@c% NON discardable
  \copy\EQ@numbox \penalty\@M
  \kern-\dim@a
}
\def\eq@typeset@rightnumber{%
  \setlength\skip@c{\dim@a-\ht\EQ@numbox}%
  \vglue\skip@c% NON discardable
  \hbox to \hsize{\hfil\copy\EQ@numbox}\penalty\@M
  \kern-\dim@a
}
\def\eq@typeset@equation{%
  \nobreak
  \eq@params\eq@parshape
  \nointerlineskip\noindent
  \add@grp@label
  \eq@dump@box\unhbox\EQ@box\@@par
}
\newcommand\eqframe[2]{%
  \begingroup
  \fboxrule=\eq@framewd\relax\fboxsep=\eq@framesep\relax
  \framebox{\z@rule\@height#2\kern#1}%
  \endgroup
}
\def\eq@addframe{%
  \hbox to\z@{%
    \setlength\dim@a{\eq@framesep+\eq@framewd}%
    \kern-\dim@a
    \vbox to\z@{\kern-\dim@a
      \hbox{\eqframe{\eq@wdT}{\eq@vspan}}%
      \vss
    }%
    \hss
  }%
}
\def\eq@typeset@frame{%
  \if F\eq@frame\else
   % Tricky: put before \noindent, so it's not affected by glue in \leftskip
   \nobreak\nointerlineskip
   \vbox to\eq@firstht{\moveright\leftskip\hbox to\z@{\eq@addframe\hss}\vss}%
   \kern-\eq@firstht
  \fi
}
\@saveprimitive\left\@@left
\@saveprimitive\right\@@right
\newcount\lr@level
\ExplSyntaxOn
\def\eq@left{%
  \@ifnext .{\eq@nullleft}{\begingroup \let\math_delimiter:NNnNn \eq@left@a}%
}
\def\eq@right{%
  \@ifnext .{\eq@nullright}{\begingroup \let \math_delimiter:NNnNn \eq@right@a}%
}
\def\eq@left@a#1#2#3#4#5#6{\endgroup
  \@@left \math_delimiter:NNnNn #1#2{#3}#4{#5}\after@open}
\def\eq@right@a#1#2#3#4#5#6{\endgroup
  \@@right \math_delimiter:NNnNn #1#2{#3}#4{#5}\after@close \ss@scan{#1#2{#3}#4{#5}}%
}
\ExplSyntaxOff
\def\eq@nullleft#1{\@@left#1\after@open}
\def\eq@nullright#1{\@@right#1\after@close}
\def\delim@reset{%
  \let\after@open\relax \let\after@close\relax
  \let\left\@@left \let\right\@@right
}
\@ifundefined{bBigg@}{% not defined
  \let\big@size\p@
  \def\big{\bBigg@{8.5}}\def\Big{\bBigg@{11.5}}%
  \def\bigg{\bBigg@{14.5}}\def\Bigg{\bBigg@{17.5}}%
  \def\biggg{\bBigg@{20.5}}\def\Biggg{\bBigg@{23.5}}%
}{}
\def\bBigg@#1#2{%
  {\delim@reset
   \left#2%
   \vrule\@height#1\big@size\@width-\nulldelimiterspace
   \right.
  }%
}
\def\bigl#1{\mathopen\big{#1}\after@open}
\def\Bigl#1{\mathopen\Big{#1}\after@open}
\def\biggl#1{\mathopen\bigg{#1}\after@open}
\def\Biggl#1{\mathopen\Bigg{#1}\after@open}
\def\bigggl#1{\mathopen\biggg{#1}\after@open}
\def\Bigggl#1{\mathopen\Biggg{#1}\after@open}

\def\bigr#1{\mathclose\big{#1}\after@close}
\def\Bigr#1{\mathclose\Big{#1}\after@close}
\def\biggr#1{\mathclose\bigg{#1}\after@close}
\def\Biggr#1{\mathclose\Bigg{#1}\after@close}
\def\bigggr#1{\mathclose\biggg{#1}\after@close}
\def\Bigggr#1{\mathclose\Biggg{#1}\after@close}

%% No change needed, I think. [mjd,1998/12/04]
%%\def\bigm{\mathrel\big}
%%\def\Bigm{\mathrel\Big}
%%\def\biggm{\mathrel\bigg}
%%\def\Biggm{\mathrel\Bigg}
%%\def\bigggm{\mathrel\biggg}
%%\def\Bigggm{\mathrel\Biggg}
\ExplSyntaxOn
\cs_set:Npn \math_dsym_DeL:Nn #1#2{\math_bsym_DeL:Nn #1{#2}\after@open}
\cs_set:Npn \math_dsym_DeR:Nn #1#2{\math_bsym_DeR:Nn #1{#2}\after@close}
\cs_set:Npn \math_dsym_DeB:Nn #1#2{\math_bsym_DeB:Nn #1{#2}\after@bidir}

%%%%%
%%%%%\let\m@@DeL\m@DeL \let\m@@DeR\m@DeR \let\m@@DeB\m@DeB
%%%%%\def\d@@DeL#1#2#3{%
%%%%%  \delimiter"4\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 \after@open
%%%%%}
%%%%%\def\d@@DeR#1#2#3{%
%%%%%  \delimiter"5\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 \after@close
%%%%%}
%%%%%\def\d@@DeB#1#2#3{%
%%%%%  \delimiter"0\@xp\delim@a\csname sd@#1#2#3\endcsname #1#2#3 \after@bidir
%%%%%}
%%BRM: These weren't defined, but apparently should be.
%%%%%%\let\m@@DeA\m@DeA\let\d@@DeA\m@DeA%
\let\after@bidir\@empty
\mathchardef\zero@bop=888 \relax
\mathchardef\bop@incr=4444 \relax
\def\after@open{%
  \global\advance\lr@level\@ne
  \prebinoppenalty\bop@incr \multiply\prebinoppenalty\lr@level
  \advance\prebinoppenalty\zero@bop
  \ifnum\eqbreakdepth<\lr@level
     \cs_set_eq:NN \math_sym_Bin:Nn \math_isym_Bin:Nn %%%%%%\let\m@Bin\m@@Bin
  \else
    \eq@binoffset=\eqbinoffset
    \advance\eq@binoffset\lr@level\eqdelimoffset plus1fill\relax
    \def\dt@fill@cancel{\hskip\z@ minus1fill\relax}%
  \fi
  \penalty\@M % BRM: discourage break after an open fence?
}
\def\after@close{%
  \global\advance\lr@level\m@ne
  \prebinoppenalty\bop@incr \multiply\prebinoppenalty\lr@level
  \advance\prebinoppenalty\zero@bop
  \ifnum\eqbreakdepth<\lr@level
  \else \cs_set_eq:NN \math_sym_Bin:Nn \math_dsym_Bin:Nn %%%%%%\let\m@Bin\d@@Bin
  \fi
  \ifnum\lr@level<\@ne \eq@binoffset=\eqbinoffset\relax \fi
}

\ExplSyntaxOff

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\subsup@flag=\count@
\def\ss@delim@a@new#1#2#3#4#5{\xdef\right@delim@code{\number"#4#5}}
\def\ss@scan#1{%
  \begingroup
    \ss@delim@a@new #1%
  \endgroup
  \subsup@flag\@M \afterassignment\ss@scan@a \let\@let@token=}
\def\ss@scan@a{%
  \let\breqn@next\ss@scan@b
  \ifx\@let@token\sb \advance\subsup@flag\@ne\else
  \ifx\@let@token\@@subscript \advance\subsup@flag\@ne\else
  \ifx\@let@token\@@subscript@other \advance\subsup@flag\@ne\else
  \ifx\@let@token\sp \advance\subsup@flag\tw@\else
  \ifx\@let@token\@@superscript \advance\subsup@flag\tw@\else
  \ifx\@let@token\@@superscript@other \advance\subsup@flag\tw@\else
    \ss@finish
    \let\breqn@next\relax
  \fi\fi\fi\fi\fi\fi
  \breqn@next\@let@token
}
\ExplSyntaxOn
\def\ss@scan@b#1#2{#1{%
  %%%%%\let\m@Bin\m@@Bin  \let\m@Rel\m@@Rel
  \cs_set_eq:NN \math_sym_Bin:Nn \math_isym_Bin:Nn
  \cs_set_eq:NN \math_sym_Rel:Nn \math_isym_Rel:Nn
  #2}\afterassignment\ss@scan@a \let\@let@token=}%
\ExplSyntaxOff
\def\ss@finish{%
  \@@vadjust{\penalty\thr@@}%
  \penalty\right@delim@code \penalty-\subsup@flag \keep@glue
}
\def\eq@lrunpack{\setbox\z@\lastbox
  \unskip \nointerlineskip
  \noindent\unhbox\z@ \unskip
  \subsup@flag-\lastpenalty \unpenalty
  \xdef\right@delim@code{\number\lastpenalty}%
  \unpenalty
  \ifnum\subsup@flag>\@M
    \advance\subsup@flag-\@M
    \setbox\tw@\lastbox
  \else \setbox\tw@\box\voidb@x
  \fi
  \setbox\z@\lastbox
  \ifvoid\tw@ \unhbox\z@
  \else \lrss@reattach % uses \subsup@flag, box\z@, box\tw@
  \fi
  \penalty-\@Mi\z@rule\@@par
  \setbox\z@\lastbox \unskip\unpenalty
%%{\showboxbreadth\maxdimen\showboxdepth99\showlists}%
}
\dimendef\sub@depth=8 \dimendef\sup@base=6
\dimendef\prelim@sub@depth=4 \dimendef\prelim@sup@base=2
\def\sym@xheight{\fontdimen5\textfont\tw@}
\def\sup@base@one{\fontdimen13\textfont\tw@}
\def\sub@base@one{\fontdimen16\textfont\tw@}
\def\sub@base@two{\fontdimen17\textfont\tw@}
\def\sup@drop{\fontdimen18\scriptfont\tw@}
\def\sub@drop{\fontdimen19\scriptfont\tw@}
\providecommand{\mathaxis}{\fontdimen22\textfont\tw@}
\def\lrss@reattach{%
  \begingroup
  % "The TeXbook" Appendix G step 18:
  \setlength\prelim@sup@base{\ht\z@-\sup@drop}%
  \setlength\prelim@sub@depth{\dp\z@ +\sub@drop}%
  \unhbox\z@
  \ifcase\subsup@flag      % case 0: this can't happen
  \or \lr@subscript   % case 1: subscript only
  \or \lr@superscript % case 2: superscript only
  \else \lr@subsup    % case 3: sub and superscript both
  \fi
  \endgroup
}
\def\lr@subscript{%
  \sub@depth\sub@base@one
  \ifdim\prelim@sub@depth>\sub@depth \sub@depth\prelim@sub@depth\fi
  \setlength\dim@a{\ht\tw@  -.8\sym@xheight}%
  \ifdim\dim@a>\sub@depth \sub@depth=\dim@a \fi
  \twang@adjust\sub@depth
  \lower\sub@depth\box\tw@
}
\def\lr@superscript{%
  \sup@base\sup@base@one
  \ifdim\prelim@sup@base>\sup@base \sup@base\prelim@sup@base\fi
  \setlength\dim@a{\dp\tw@ -.25\sym@xheight}%
  \ifdim\dim@a>\sup@base \sup@base\dim@a \fi
  \twang@adjust\sup@base
  \raise\sup@base\box\tw@
}
\def\lr@subsup{%
  \sub@depth\sub@base@two
  \ifdim\prelim@sub@depth>\sub@depth \sub@depth\prelim@sub@depth \fi
  \twang@adjust\sub@depth
  \lower\sub@depth\box\tw@
}
\def\twang@adjust#1{%
  \begingroup
    \@ifundefined{twang@\right@delim@code}{}{%
      \setlength\dim@d{#1-\mathaxis}%
      % put an upper limit on the adjustment
      \ifdim\dim@d>1em \dim@d 1em \fi
      \kern\csname twang@\right@delim@code\endcsname\dim@d
    }%
  \endgroup
}
\newcommand{\DeclareTwang}[2]{%
  \ifcat.\@nx#1\begingroup
    \lccode`\~=`#1\lowercase{\endgroup \DeclareTwang{~}}{#2}%
  \else
    \@xp\decl@twang#1?\@nil{#2}%
  \fi
}
\def\decl@twang#1#2#3#4#5#6#7\@nil#8{%
  \@namedef{twang@\number"#4#5#6}{#8}%
}
\DeclareTwang{\rangle}{-.4}
\DeclareTwang{)}{-.33}
\DeclareTwang{\rbrace}{-.25}
\newenvironment{dseries}{\let\eq@hasNumber\@True \@optarg\@dseries{}}{}%
\def\enddseries#1{\check@punct@or@qed}%
\newenvironment{dseries*}{\let\eq@hasNumber\@False \@optarg\@dseries{}}{}%
\@namedef{enddseries*}#1{\check@punct@or@qed}%
\@namedef{end@dseries*}{\end@dseries}%
\def\@dseries[#1]{%
  \let\display@setup\dseries@display@setup
  % Question: should this be the default for dseries???
  \global\eq@wdCond\z@
  \@dmath[layout={M},#1]%
  \mathsurround\z@\@@math \penalty\@Mi
  \let\endmath\ends@math
  \def\premath{%
    \ifdim\lastskip<.3em \unskip
    \else\ifnum\lastpenalty<\@M \dquad\fi\fi
}%
  \def\postmath{\unpenalty\eq@addpunct \penalty\intermath@penalty \dquad \@ignoretrue}%
\ignorespaces
}
\def\end@dseries{%
  \unskip\unpenalty
  \@@endmath \mathsurround\z@ \end@dmath
}
\def\eq@try@layout@M{%
  \edef\@parshape{\parshape 1 0pt \the\eq@linewidth\relax}%
  \eq@trial@b{M}{}%
}
\def\intermath@penalty{-221}%
\newcommand\dquad{\hskip0.6em minus.3em}
\newcommand\premath{}\newcommand\postmath{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewenvironment{math}{%
  \leavevmode \premath
  \ifmmode\@badmath\else\@@math\fi
}{%
  \ifmmode\@@endmath\else\@badmath\fi
}
\def\ends@math#1{\check@punct@or@qed}
\def\end@math{%
  \ifmmode\@@endmath\else\@badmath\fi
  \postmath
}
\let\eq@group\@False
\let\grp@shiftnumber\@False
\let\grp@hasNumber\@False
\let\grp@eqs@numbered\@False
\let\grp@aligned\@True
\newenvironment{dgroup}{%
  \let\grp@hasNumber\@True\@optarg\@dgroup{}%
}{%
  \end@dgroup
}
\newtoks\GRP@queue
\newenvironment{dgroup*}{%
  \let\grp@hasNumber\@False\@optarg\@dgroup{}%
}{%
  \end@dgroup
}
\def\@dgroup[#1]{%
  \let\eq@group\@True \global\let\eq@GRP@first@dmath\@True
  \global\GRP@queue\@emptytoks \global\setbox\GRP@box\box\voidb@x
  \global\let\GRP@label\@empty
  \global\grp@wdL\z@\global\grp@wdR\z@\global\grp@wdT\z@
  \global\grp@linewidth\z@\global\grp@wdNum\z@
  \global\let\grp@eqs@numbered\@False
  \global\let\grp@aligned\@True
  \global\let\grp@shiftnumber\@False
  \eq@prelim
  \setkeys{breqn}{#1}%
  \if\grp@hasNumber \grp@setnumber \fi
}
\def\end@dgroup{%
  \EQ@displayinfo \grp@finish
  \if\grp@hasNumber\grp@resetnumber\fi
}
\@ifundefined{c@parentequation}{\newcounter{parentequation}}{}
\global\let\GRP@label\@empty
\def\add@grp@label{%
  \ifx\@empty\GRP@label
  \else \GRP@label \global\let\GRP@label\@empty
  \fi
}
\def\grp@setnumber{%
  \global\let\GRP@label\next@label \global\let\next@label\@empty
  % Trick \eq@setnumber to doing our work for us.
  \let\eq@hasNumber\@True
  \eq@setnumber
  \global\sbox\GRP@numbox{\unhbox\EQ@numbox}%
  \grp@wdNum\eq@wdNum
  \let\eq@hasNumber\@False
  \let\eq@number\@empty
  \eq@wdNum\z@
  \protected@edef\theparentequation{\theequation}%
  \setcounter{parentequation}{\value{equation}}%
  \setcounter{equation}{0}%
  \def\theequation{\theparentequation\alph{equation}}%
}
\def\grp@resetnumber{%
  \setcounter{equation}{\value{parentequation}}%
}
\newbox\GRP@box
\newbox\GRP@wholebox
\def\grp@push{%
  \global\GRP@queue\@xp\@xp\@xp{\@xp\the\@xp\GRP@queue
    \@xp\@elt\@xp{\EQ@trial}%
  }%
  \global\setbox\GRP@box\vbox{%
    \hbox{\box\EQ@box\box\EQ@copy\penalty\@ne\copy\EQ@numbox}%
    \unvbox\GRP@box
  }%
  \EQ@trial
  \if\eq@isIntertext\else
    \ifdim\eq@wdL>\grp@wdL \global\grp@wdL\eq@wdL \fi
    \ifdim\eq@wdT>\grp@wdT \global\grp@wdT\eq@wdT \fi
    \setlength\dim@a{\eq@wdT-\eq@wdL}%
    \ifdim\dim@a>\grp@wdR \global\grp@wdR\dim@a \fi
    \ifdim\eq@linewidth>\grp@linewidth \global\grp@linewidth\eq@linewidth\fi
    \if\eq@hasNumber
       \global\let\grp@eqs@numbered\@True
       \ifdim\eq@wdNum>\grp@wdNum\global\grp@wdNum\eq@wdNum\fi
    \fi
    \if\EQ@hasLHS\else\global\let\grp@aligned\@False\fi
    \if D\eq@layout \global\let\grp@aligned\@False\fi % Layout D (usually) puts rel on 2nd line.
    \if\eq@shiftnumber\global\let\grp@shiftnumber\@True\fi % One eq shifted forces all.
  \fi
}
\def\grp@finish{%
  \setlength\dim@a{\grp@wdL+\grp@wdR-4em}% Allowance for shrink?
  \if\grp@aligned
    \ifdim\dim@a>\grp@linewidth
      \global\let\grp@aligned\@False
    \fi
  \fi
  \addtolength\dim@a{\grp@wdNum }% Effective length
  \if\grp@shiftnumber
  \else
    \if\@And{\grp@hasNumber}{\@Not\grp@eqs@numbered}
      \ifdim\dim@a>\grp@linewidth
        \global\let\grp@shiftnumber\@True
      \fi
    \fi
  \fi
  \if\grp@aligned
     \global\grp@wdT\grp@wdL
     \global\advance\grp@wdT\grp@wdR
  \fi
  \setbox\GRP@wholebox\vbox{%
    \let\@elt\eqgrp@elt
    \the\GRP@queue
  }%
  \global\let\eq@GRP@first@dmath\@True
  \begingroup
  \dmath@first@leftskip
  \eq@topspace{\vskip\parskip}%
  \endgroup
  \if\@And{\grp@hasNumber}{\@Not{\grp@eqs@numbered}}%
    \if\grp@shiftnumber
      \copy\GRP@numbox \penalty\@M
      \kern\eqlineskip
    \else
      \setlength\dim@a{%
        (\ht\GRP@wholebox+\dp\GRP@wholebox+\ht\GRP@numbox-\dp\GRP@numbox)/2}%
      \setlength\skip@c{\dim@a-\ht\GRP@numbox}%
      \vglue\skip@c% NON discardable
      \copy\GRP@numbox \penalty\@M
      \kern-\dim@a
      \kern-\abovedisplayskip % To cancel the topspace above the first eqn.
    \fi
  \fi
  \unvbox\GRP@wholebox
  \let\@elt\relax
  \eq@botspace % not needed unless bottom number?
}
\def\eqgrp@elt#1{%
  \global\setbox\GRP@box\vbox{%
    \unvbox\GRP@box
    \setbox\z@\lastbox
    \setbox\tw@\hbox{\unhbox\z@
      \ifnum\lastpenalty=\@ne
      \else
        \global\setbox\EQ@numbox\lastbox
      \fi
      \unpenalty
      \global\setbox\EQ@copy\lastbox
      \global\setbox\EQ@box\lastbox
    }%
  }%
  \begingroup \let\eq@botspace\relax
  #1%
  \if\eq@isIntertext
    \vskip\belowdisplayskip
    \unvbox\EQ@copy
  \else
    \grp@override
    \eq@finish
  \fi
  \endgroup
}
\def\grp@override{%
  \def\eqindent{I}%
  \setlength\dim@a{(\grp@linewidth-\grp@wdT)/2}%
  \ifdim\dim@a<\z@\dim@a=\z@\fi
  \dim@b\if L\eqnumside\grp@wdNum\else\z@\fi
  \if\grp@shiftnumber\else
    \ifdim\dim@b>\dim@a\dim@a\dim@b\fi
  \fi
  \if\grp@aligned
    \addtolength\dim@a{\grp@wdL-\eq@wdL}%
  \fi
  \mathindent\dim@a
  \ifdim\dim@b>\dim@a
    \let\eq@shiftnumber\@True
  \fi
}
\newskip\darraycolsep \darraycolsep 20pt plus1fil minus12pt
\newcount\cur@row \newcount\cur@col
\def\@tempa#1#2#3{%
  \cur@col#1 \hfil
  \setbox\z@\hbox{$\displaystyle####\m@th$}\@nx\col@box
  \tabskip\z@skip
  &\cur@col#2 \hfil
  \setbox\z@\hbox{$\displaystyle\mathord{}####\mathord{}\m@th$}\@nx\col@box
  \hfil
  &\cur@col#3 \setbox\z@\hbox{$\displaystyle####\m@th$}\@nx\col@box
  \hfil\tabskip\darraycolsep
}
\xdef\darray@preamble{%
  \@tempa 123&\@tempa 456&\@tempa 789%
  &\@tempa{10}{11}{12}&\@tempa{13}{14}{15}&\@tempa{16}{17}{18}%
  \cr
}
\@ifundefined{Mathstrut@}{\let\Mathstrut@\strut}{}
\def\darray@cr{\Mathstrut@\cr}
\def\col@box{%
  \unhbox\z@
}
\newenvironment{darray}{\@optarg\@darray{}}{}
\def\@darray[#1]{%
  \if\eq@group\else\eq@prelim\fi
  \global\let\@preamble\@empty
  \setkeys{breqn}{#1}%
  \the\eqstyle \eq@setnumber
  \ifx\@preamble\@empty \global\let\@preamble\darray@preamble \fi
  \check@mathfonts
  % \let\check@mathfonts\relax % tempting, but too risky
  \@xp\let\csname\string\ \endcsname\darray@cr
  \setbox\z@\vbox\bgroup
  \everycr{\noalign{\global\advance\cur@row\@ne}}%
  \tabskip\z@skip \cur@col\z@
  \global\cur@row\z@
  \penalty\@ne % flag for \dar@repack
  \halign\@xp\bgroup\@preamble
}
\def\enddarray#1{\check@punct@or@qed}
\def\end@darray{%
  \ifvmode\else \eq@addpunct \Mathstrut@\fi\crcr \egroup
  \dar@capture
  \egroup
}
\def\dar@capture{%
%% \showboxbreadth\maxdimen\showboxdepth99\showlists
  \eq@wdL\z@ \eq@wdRmax\z@
  \dar@repack
}
\def\dar@repack{%
  \unpenalty
  \setbox\tw@\lastbox
  \global\setbox\EQ@box\hbox{%
    \hbox{\unhcopy\tw@\unskip}\penalty-\@M \unhbox\EQ@box}%
  \global\setbox\EQ@copy\hbox{%
    \hbox{\unhbox\tw@\unskip}\penalty-\@M \unhbox\EQ@copy}%
  \unskip
  \ifcase\lastpenalty \else\@xp\@gobble\fi
  \dar@repack
}
\newskip\conditionsep \conditionsep=10pt minus5pt%
\newcommand{\conditionpunct}{,}
\newcommand\condition{%
  \begingroup\@tempswatrue
    \@ifstar{\@tempswafalse \condition@a}{\condition@a}}
\newcommand\condition@a[2][\conditionpunct]{%
  \unpenalty\unskip\unpenalty\unskip % BRM Added
  \hbox{#1}%
  \penalty -201\relax\hbox{}% Penalty to allow breaks here.
  \hskip\conditionsep
  \setbox\z@\if@tempswa\hbox{#2}\else\hbox{$\textmath@setup #2$}\fi
  \usebox\z@
  \endgroup}
\newenvironment{XXXXdsuspend}{%
  \global\setbox\EQ@box\vbox\bgroup \@parboxrestore
    \parshape 1 \displayindent \displaywidth\relax
    \hsize=\columnwidth \noindent\ignorespaces
}{%
  \par\egroup
  \global\setbox\GRP@box\vbox{%
    \vbox{\copy\EQ@box\vtop{\unvbox\EQ@box}}%
    \unvbox\GRP@box
  }%
  \global\GRP@queue\@xp{\the\GRP@queue
    \@elt{\gdef\EQ@trial{}}%
  }%
}
\newenvironment{dsuspend}{%
  \global\setbox\EQ@box\vbox\bgroup \@parboxrestore
    \parshape 1 \displayindent \displaywidth\relax
    \hsize=\columnwidth \noindent\ignorespaces
}{%
  \par\egroup
  \global\setbox\GRP@box\vbox{%
    \hbox{\copy\EQ@box\vtop{\unvbox\EQ@box}}%
    \unvbox\GRP@box
  }%
  \global\GRP@queue\@xp{\the\GRP@queue
     \@elt{\let\eq@isIntertext\@True}%
  }%
}
\newcommand\breqn@intertext[1]{\dsuspend#1\enddsuspend}
\renewcommand{\*}{%
  \if@display
    \setbox\z@\hbox{\mathsurround\z@$\mkern\eq@binoffset$}%
    \discretionary{}{%
      \kern\the\wd\z@ \textchar\discretionarytimes
    }{}%
    \thinspace
  \else
    \discretionary{\thinspace\textchar\discretionarytimes}{}{}%
  \fi
}
\newcommand{\discretionarytimes}{\times}
\def\nref#1{\@xp\@nref\csname r@#1\endcsname}
\def\@nref#1#2{\ifx\relax#1??\else \@xp\@firstoftwo#1\fi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\endinput
%%
%% End of file `breqn.sty'.
