texlive[74778] Master/texmf-dist: eqnlines (28mar25)

commits+karl at tug.org commits+karl at tug.org
Fri Mar 28 22:33:10 CET 2025


Revision: 74778
          https://tug.org/svn/texlive?view=revision&revision=74778
Author:   karl
Date:     2025-03-28 22:33:10 +0100 (Fri, 28 Mar 2025)
Log Message:
-----------
eqnlines (28mar25)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/eqnlines/README.txt
    trunk/Master/texmf-dist/doc/latex/eqnlines/eqnlines.pdf
    trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.dtx
    trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.ins
    trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines-dev.sty
    trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines.sty

Modified: trunk/Master/texmf-dist/doc/latex/eqnlines/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/eqnlines/README.txt	2025-03-28 21:33:02 UTC (rev 74777)
+++ trunk/Master/texmf-dist/doc/latex/eqnlines/README.txt	2025-03-28 21:33:10 UTC (rev 74778)
@@ -1,4 +1,4 @@
-eqnlines v0.6
+eqnlines v0.6.1
 Copyright 2024-2025 Niklas Beisert
 
 Based on the latex package amsmath:
@@ -30,10 +30,10 @@
 
 Run "(pdf)latex eqnlines.dtx" to compile the manual eqnlines.pdf.
 
-Run "latex eqnlines.ins" to create the package eqnlines.sty and the
-development version eqnlines-dev.sty.
-Copy the file eqnlines.sty to an appropriate directory of your LaTeX
-distribution, e.g. texmf-root/tex/latex/eqnlines.
+Run "latex eqnlines.ins" to create the package eqnlines.sty
+and the development version eqnlines-dev.sty.
+Copy the file eqnlines.sty to an appropriate directory
+of your LaTeX distribution, e.g. texmf-root/tex/latex/eqnlines.
 
 This work may be distributed and/or modified under the
 conditions of the LaTeX Project Public License, either version 1.3

Modified: trunk/Master/texmf-dist/doc/latex/eqnlines/eqnlines.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.dtx	2025-03-28 21:33:02 UTC (rev 74777)
+++ trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.dtx	2025-03-28 21:33:10 UTC (rev 74778)
@@ -23,10 +23,10 @@
 % and the derived files eqnlines.sty.
 %
 %<package|sample>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
-%<package&!dev>\ProvidesPackage{eqnlines}[2025/03/11 v0.6 Single- and multi-line equations]
-%<package&dev>\ProvidesPackage{eqnlines-dev}[2025/03/11 v0.6 Single- and multi-line equations (development)]
+%<package&!dev>\ProvidesPackage{eqnlines}[2025/03/27 v0.6.1 Single- and multi-line equations]
+%<package&dev>\ProvidesPackage{eqnlines-dev}[2025/03/27 v0.6.1 Single- and multi-line equations (development)]
 %<*driver>
-\def\thedate#1{2025/03/11}\def\theversion#1{v0.6}
+\def\thedate#1{2025/03/27}\def\theversion#1{v0.6.1}
 \ProvidesFile{eqnlines.dtx}[\thedate{} \theversion{} eqnlines reference manual file]
 \PassOptionsToClass{10pt,a4paper}{article}
 \documentclass{ltxdoc}
@@ -40,6 +40,7 @@
 \hypersetup{urlbordercolor={.5 1 1}}
 \hypersetup{linkbordercolor={1 .7 .7}}
 \AddToHook{begindocument/before}{\hypersetup{pdfstartview=FitH}}
+\hypersetup{keeppdfinfo=true}
 \hypersetup{pdfsource={}}
 \hypersetup{pdflang={en-UK}}
 \hypersetup{pdfurl={https://ctan.org/pkg/eqnlines}}
@@ -237,7 +238,7 @@
 This simplifies the construction of continuing equations
 in an aligned context.
 \item
-Equation lines are subject to shrinking of white space
+Equation lines are subject to shrinking of space
 if the available space does not suffice
 (analogously to single-line equations).
 \item
@@ -282,7 +283,7 @@
 \label{sec:usage}
 
 % \TODO notice regarding v0.5
-\textbf{Notice regarding package version v0.5:}
+\textbf{Notice regarding package version \theversion{}:}
 Please note that this package is still in a development and testing stage
 in the present version.
 This mainly applies to the documentation of features and code:
@@ -336,15 +337,16 @@
 Furthermore, the environment accepts some modifiers
 (like the star modifier `|*|' for many other \LaTeX\ macros)
 which will be explained further below.
-These follow the scheme |{ !t~ !t* !t! !o !e{@} }| 
+These follow the scheme |{ !t~ !t* !t! !o !e{@} }|
 according to the syntax of |\NewDocumentCommand|.
 
-We note that the equations environment should be started with a white space
+We note that the equations environment should be started with a whitespace
 character `\texttt{\textvisiblespace}'
 which provides a clear separation
 from optional arguments `|[|\textit{opts}|]|'
 and/or modifiers which must immediately follow
-the environment declaration |\begin{equations}|.
+the environment declaration |\begin{equations}|
+without whitespaces.
 
 \DescribeKey{single}
 \DescribeKey{lines}
@@ -578,7 +580,7 @@
 Each pair of subsequent columns forms a unit which is aligned at the
 intermediate alignment marker `|&|'.
 These columns are distributed evenly over the available horizontal space.
-Here, the outer space left and right of the set of columns can
+Here, the outer space left and right of the set of columns
 is treated on equal footing to the space between the columns
 (option |margins=on|),
 but it can be eliminated so that the outer columns
@@ -655,16 +657,34 @@
 via |layout=center|, |layout=left| or |center|, |left| for short.
 
 \DescribeKey{tagmargin}
-In central alignment mode, there is the option of imposing a tag margin
+\DescribeKey{tagmargin*}
+\DescribeKey{tagmargincalc}
+\DescribeKey{tagmarginratio}
+In central alignment layout, there is the option of imposing a tag margin
 |tagmargin={|\textit{dimen}|}|
 which allocates some space to the tag
 such that equation content is centred in the remaining horizontal space.
+The margin can also be set to the width of some text by
+|tagmargin*={|\textit{text}|}| or it can be calculated
+as the maximum width of tags by |tagmargincalc|.
+The option |tagmarginratio={|\textit{ratio}|}|
+uses the tag margin only for equation blocks
+with a ratio of tags to rows above the given (decimal) ratio
+(a value above 1 uses the tag margin only for single equations with tags).
+The option |tagmarginthreshold={|\textit{threshold}|}|
+uses the tag margin only if the ratio of spacings is below
+the given (decimal) threshold.
+The latter two options together with some tag margin
+can produce a more appealing layout for equation blocks of mixed filling.
 
 \DescribeKey{leftmargin}
+\DescribeKey{leftmargin*}
 \DescribeKey{minleftmargin}
 \DescribeKey{maxleftmargin}
-In left alignment mode, all equations are left aligned to a left margin
-(|leftmargin| initialised to the first level of enumerations and itemisations).
+In left alignment layout, all equations are left aligned to a left margin
+(|leftmargin| is initialised
+to the first level of enumerations and itemisations).
+It can be set to the width of some text by |leftmargin*={|\textit{text}|}|.
 Depending on the situation, the left margin may be
 reduced or extended to |minleftmargin| or |maxleftmargin|, respectively.
 
@@ -889,13 +909,13 @@
 These keys also take the values |above|, |below| or |both|.
 
 \DescribeKey{par}
-The key |par| controls to whether 
-the equations environment end in horizontal mode (value |cont|)
+The key |par| controls whether
+the equation environments end in horizontal mode (value |cont|)
 or in vertical mode (value |par|, default)
 with a dedicated amount of glue |belowparskip|.
-An environment can also end in vertical mode
+An environment can also be made to end in vertical mode
 without interline skip (value |top|)
-and with glue |belowtopskip|.
+using the glue |belowtopskip|.
 
 \DescribeKey{...skip}
 \DescribeInterfaceMacro{\vspace}
@@ -1047,9 +1067,9 @@
 \begin{tabular}{ll}
 option & description \\
 \hline
-|defaults=classic| 
+|defaults=classic|
   & mimic classic \LaTeX/\ctanpkg{amsmath} (layout and dimensions) \\
-|defaults=eqnlines| 
+|defaults=eqnlines|
   & \ctanpkg{eqnlines} layout with fontsize-relative dimensions \\
 |rescan| & rescan environment body to allow special commands (e.g.\ |\verb|) \\
 |linesfallback| & single column in align mode reverts to lines mode \\
@@ -1285,22 +1305,87 @@
 \begin{itemize}
 \item
 a proper manual
+%
 \item
 complete code documentation
+%
 \item
 sample document
+%
+\item
+version of |\eqref| that can handle multiple references and ranges
+enclosed by the default formatting for equation tags
+% syntax such as a - b, c, d (spaces to separate?, labels enclosed by {}?)
+% or completely manual such as \eqref*{\ref{...}--\ref{...},~\ref{...}}
+%
+\item
+switch to allow scanning of |\par| within body
+%
+\item
+numbering scheme to place a number
+where there is the most available space
+%
 \end{itemize}
 
+\iffalse
+Some technical and/or internal items to be done include:
+%
+\begin{itemize}
+\item
+might change optional argument parsing to more recent
+\LaTeX{} mechanisms |\NewDocumentCommand|
+(but need to pay attention to `|&|')
+%
+\item
+change |\@ifpackageloaded| to |\IfPackageLoaded...|
+when command is less recent.
+%
+\item
+allow amsmath loading after eqnlines when pdf tagging is active
+(cannot put a hook on latex-lab-amsmath)
+%
+\item
+simplify |\advance| using |\dimexpr|, |\glueexpr|, |\numexpr|
+\end{itemize}
+\fi
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subsection{Revision History}
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\iffalse
+\paragraph{vN.N.N+:} 20YY/MM/NN
+
+\begin{itemize}
+\item
+\ldots
+\end{itemize}
+\fi
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\paragraph{v0.6.1:} 2025/03/27
+
+\begin{itemize}
+\item
+|\eqnpunct| can place punctuation within the current equation field
+\item
+|numberline=none| now acts as |numberline=all| and |nonumber|
+\item
+fixed and extended |tagmargin|
+with |tagmargincalc|, |tagmarginratio| and |tagmarginthreshold|
+\item
+padding now applies to single-line equations as well
+\end{itemize}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \paragraph{v0.6:} 2025/03/11
 
 \begin{itemize}
 \item
-preliminary pdf tagging support 
-(\url{https://latex3.github.io/tagging-project/})
+preliminary pdf tagging support
+(\url{https://latex3.github.io/tagging-project/};
+\ctanpkg{amsmath} \emph{must} be loaded \emph{before} \ctanpkg{eqnlines}
+to avoid errors
 \item
 classic \LaTeX/\ctanpkg{amsmath} vs.\ \ctanpkg{eqnlines} presets
 \item
@@ -1394,6 +1479,45 @@
 %    \end{macrocode}
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \subsection{Supporting Definitions}
+%
+%   \ebool{\eql at false}
+%   \ebool{\eql at true}
+% Rather than the standard \LaTeX{} scheme of
+% |\|\textit{xxx}|false|, |\|\textit{xxx}|true| and |\if|\textit{xxx}
+% for boolean variables \textit{xxx},
+% we use a scheme where |\|\textit{xxx}
+% is either undefined or defined (to an empty macro)
+% and is tested against by the $\varepsilon$-\TeX{}
+% conditional |\ifdefined\|\textit{xxx}.
+% In order to make the scheme more tangible,
+% we define the two expected values for boolean variables:
+%    \begin{macrocode}
+\let\eql at false\@undefined
+\let\eql at true\@empty
+%    \end{macrocode}
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \subsection{Dollardollar Abstraction}
+%
+%   \macro{\eql at dollardollar@begin}
+%   \macro{\eql at dollardollar@end}
+% As of 2025 \LaTeX{} defines |\dollardollar at begin| and |\dollardollar at end|
+% to represent (and adjust) the beginning and end of
+% bare \TeX{} display equations (`|$$|').
+% For the time being, we make sure to revert to `|$$|' if these
+% macros are not yet available:
+%    \begin{macrocode}
+\ifdefined\dollardollar at begin
+  \def\eql at dollardollar@begin{\dollardollar at begin}
+  \def\eql at dollardollar@end{\dollardollar at end}
+\else
+  \def\eql at dollardollar@begin{$$}
+  \def\eql at dollardollar@end{$$}
+\fi
+%    \end{macrocode}
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Look-Ahead in Alignment}
 %
 % Scanning for optional arguments |[|\ldots|]| or modifiers such as `|*|'
@@ -1408,7 +1532,7 @@
 %   \macro{\eql at ifnextchar@tight}
 % To address the first challenge, we can force the special characters to
 % follow immediately the macro invocation.
-% For clarify, we copy \LaTeX's original |\@ifnextchar|
+% For clarity, we copy \LaTeX's original |\@ifnextchar|
 % in |\kernel at ifnextchar| which skips over spaces as |\eql at ifnextchar@loose|.
 % We replicate the \ctanpkg{amsgen} version |\new at ifnextchar|
 % that does not skip over spaces as |\eql at ifnextchar@loose|.
@@ -1429,7 +1553,11 @@
 }
 %    \end{macrocode}
 %
-% \TODO describe
+%   \macro{\eql at atxii}
+% Capture `|@|' as a character (catcode 12)
+% rather than a letter (catcode 11) as |\eql at atxii|
+% so that we can look-ahead for `|@|' with both
+% |\makeatother| and |\makeatletter| modes:
 %    \begin{macrocode}
 \begingroup
   \makeatother
@@ -1608,7 +1736,98 @@
 \def\eql at amsmath@let#1#2{\eql at amsmath@undefine#1\let#1#2}
 %    \end{macrocode}
 %
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \subsection{Tagging Support}
 %
+%   \macro{\eql at tagging@...}
+% Proper PDF tagging
+% \unskip\footnote{see \url{https://latex3.github.io/tagging-project/}}
+% support requires a \LaTeX{} version at least of 2025.
+% For the time being, we define an abstraction layer so that
+% the package will collaborate with \LaTeX{} versions around 2020:
+%    \begin{macrocode}
+\let\eql at tagging@on\eql at false
+\IfFormatAtLeastTF{2025-06-01}{%
+  \csname tag_if_active:T\endcsname{\let\eql at tagging@on\eql at true}}{}
+\ifdefined\eql at tagging@on
+  \def\eql at tagging@mathsave{%
+    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
+  \def\eql at tagging@mathaddlast{%
+    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
+  \def\eql at tagging@tagbegin{%
+    \UseTaggingSocket{math/display/tag/begin}}
+  \def\eql at tagging@tagend{%
+    \UseTaggingSocket{math/display/tag/end}}
+  \def\eql at tagging@tagsave{%
+    \UseTaggingSocket{math/luamml/mtable/tag/save}}
+  \def\eql at tagging@tagaddbox{%
+    \setbox\z@\copy\eql at tagbox@%
+    \UseTaggingSocket{math/luamml/mtable/tag/set}}
+  \def\eql at tagging@tablesaveinner{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
+  \def\eql at tagging@tableaddinner{%
+    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
+  \def\eql at tagging@tablesavelines{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
+  \def\eql at tagging@tablesavealign{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
+  \def\eql at tagging@alignleft{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
+  \def\eql at tagging@aligncenter{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
+  \def\eql at tagging@alignright{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
+%    \end{macrocode}
+% We need to get hold of the equation body in all cases
+% so that we can feed it into the tagging mechanism:
+%    \begin{macrocode}
+  \let\eql at single@doscan\eql at true
+  \let\eql at scan@body\eql at scan@body at rescan
+%    \end{macrocode}
+%   \macro{\eql at tagging@start}
+%   \macro{\eql at tagging@end}
+% We need to activate tagging for display equations
+% for environments and for enclosures |\[...\]| and |\<...\>|.
+% The tagging interface registration macro |\RegisterMathEnvironment|
+% will work only partially for our cases, hence we
+% replicate code from |\math_register_halign_env:nn|.
+% Make sure collection is not yet active (|\l__math_collected_bool|).
+% Then feed collected environment name,
+% options and body into |\__math_process:nn|.
+% Indicate the start of a display equation:
+%    \begin{macrocode}
+  \ExplSyntaxOn
+  \def\eql at tagging@start{%
+    \bool_if:NF\l__math_collected_bool{%
+      \toks@\expandafter{\eql at tagging@opt}%
+      \edef\eql at tmp{{\@currenvir}{[\the\toks@] \the\eql at scan@reg@}}%
+      \expandafter\__math_process:nn\eql at tmp
+      \@kernel at math@registered at begin
+      \bool_set_true:N\l__math_collected_bool
+    }%
+  }
+  \def\eql at tagging@end{}
+  \ExplSyntaxOff
+\else
+  \def\eql at tagging@mathsave{}
+  \def\eql at tagging@mathaddlast{}
+  \def\eql at tagging@tagbegin{}
+  \def\eql at tagging@tagend{}
+  \def\eql at tagging@tagsave{}
+  \def\eql at tagging@tagaddbox{}
+  \def\eql at tagging@tablesaveinner{}
+  \def\eql at tagging@tableaddinner{}
+  \def\eql at tagging@tablesavelines{}
+  \def\eql at tagging@tablesavealign{}
+  \def\eql at tagging@alignleft{}
+  \def\eql at tagging@aligncenter{}
+  \def\eql at tagging@alignright{}
+  \def\eql at tagging@start{}
+  \def\eql at tagging@end{}
+\fi
+%    \end{macrocode}
+%
+%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \section{Parameters and Registers}
@@ -1616,49 +1835,10 @@
 % In the following, we collect parameter and register definitions.
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Supporting Definitions}
+% \subsection{Parameters}
 %
-%   \ebool{\eql at false}
-%   \ebool{\eql at true}
-% Rather than the standard \LaTeX{} scheme of
-% |\|\textit{xxx}|false|, |\|\textit{xxx}|true| and |\if|\textit{xxx}
-% for boolean variables \textit{xxx},
-% we use a scheme where |\|\textit{xxx}
-% is either undefined or defined (to an empty macro)
-% and is tested against by the $\varepsilon$-\TeX{}
-% conditional |\ifdefined\|\textit{xxx}.
-% In order to make the scheme more tangible,
-% we define the two expected values for boolean variables:
-%    \begin{macrocode}
-\let\eql at false\@undefined
-\let\eql at true\@empty
-%    \end{macrocode}
+% \TODO describe
 %
-%   \lskip{\eql at regunset@}
-%   \macro{\eql at regsetdelayed}
-% Some dimension registers need to be initialised to values
-% which may depend on fonts and styles, e.g.\ |1em|.
-% As |\@mathmargin| of \ctanpkg{amsmath},
-% we use the special value |-1sp| to indicate that this
-% register should be initialised at the end of the preamble,
-% and we define a skip register to hold this value.
-% The macro |\eql at regsetdelayed| performs the delayed initialisation:
-%    \begin{macrocode}
-\newskip\eql at regunset@
-\eql at regunset@-1sp\relax
-\def\eql at regsetdelayed#1#2{%
-  #1\eql at regunset@\relax
-  \AtBeginDocument{%
-    \ifdim#1=\eql at regunset@
-      #1\glueexpr#2\relax
-    \fi
-  }%
-}
-%    \end{macrocode}
-%
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Parameters}
-%
 % \TODO maybe sort parameters into sections
 % \TODO or sort parameters in sections here
 %
@@ -1671,15 +1851,16 @@
 %
 %   \ebool{\eql at flushleft}
 % The boolean parameter |\eql at flushleft|
-% specifies whether the layout is flush left or centered:
+% specifies whether to use left or central alignment layout:
 %    \begin{macrocode}
 \let\eql at flushleft\eql at false
 %    \end{macrocode}
 %
 %   \ldimen{\eql at flushleftmargin@}
+%   \macro{\eql at flushleftmargin@val}
 %   \ldimen{\eql at flushleftmarginmin@}
 %   \ldimen{\eql at flushleftmarginmax@}
-% The default width of the left margin in flush-left mode
+% The default width of the left margin in left alignment layout
 % is specified by |\eql at flushleftmargin@|.
 % It may be pushed down to |\eql at flushleftmarginmin@|
 % and up to |\eql at flushleftmarginmax@|:
@@ -1687,17 +1868,29 @@
 \newdimen\eql at flushleftmargin@
 \newdimen\eql at flushleftmarginmin@
 \newdimen\eql at flushleftmarginmax@
-\eql at regsetdelayed\eql at flushleftmargin@\leftmargini
+\def\eql at flushleftmargin@val{\leftmargini}
 \eql at flushleftmarginmin@\z@
 \eql at flushleftmarginmax@.5\maxdimen
 %    \end{macrocode}
 %
 %   \ldimen{\eql at tagmargin@}
-% The intended margin width for tags in centered layout
-% is specified by |\eql at tagmargin@|:
+%   \ldimen{\eql at tagmargin@ratio@}
+%   \macro{\eql at tagmargin@val}
+%   \macro{\eql at tagmargin@threshold}
+% The intended margin width for tags in centeral alignment layout
+% is stored in |\eql at tagmargin@| which is sourced by |\eql at tagmargin@val|.
+% An undefined |\eql at tagmargin@val| will compute the margin width
+% as the maximum width of tags (without separation).
+% |\eql at tagmargin@ratio@| describes the maximum ratio
+% of lines with tags to total number of lines
+% for which |\eql at tagmargin@| is set to zero:
+% \TODO threshold
 %    \begin{macrocode}
 \newdimen\eql at tagmargin@
-\eql at tagmargin@\z@
+\let\eql at tagmargin@val\@undefined
+\newdimen\eql at tagmargin@ratio@
+\eql at tagmargin@ratio@\p@
+\def\eql at tagmargin@threshold{0.5}
 %    \end{macrocode}
 %
 %   \ldimen{\eql at indent@}
@@ -1862,18 +2055,15 @@
 %    \end{macrocode}
 %
 %   \ldimen{\eql at colsepmin@}
-%   \ldimen{\eql at colsepmax@}
 %   \macro{\eql at colsepmin@val}
 %   \macro{\eql at colsepmax@val}
-% The minimum and maximum intercolumn separatation is specified
-% by |\eql at colsepmin@| and |\eql at colsepmax@|.
-% These dimension registers are set to the macros
-% |\eql at colsepmin@val| and |\eql at colsepmax@val|, respectively,
-% when entering the equation environments
-% to allow font-dependent values including \ctanpkg{calc} evaluations:
+% The minimum intercolumn separatation is specified by |\eql at colsepmin@|.
+% This dimension register is set to |\eql at colsepmin@val|
+% when entering the equation environments to allow font-dependent values.
+% Furthermore, |\eql at colsepmax@val|
+% specifies the maximum intercolumn separation:
 %    \begin{macrocode}
 \newdimen\eql at colsepmin@
-\newdimen\eql at colsepmax@
 \def\eql at colsepmin@val{1em}
 \def\eql at colsepmax@val{.5\maxdimen}
 %    \end{macrocode}
@@ -1888,27 +2078,101 @@
 %   \ldimen{\eql at tagsepmin@}
 % The minimum separation between an equation and its tag
 % is given by |\eql at tagsepmin@|.
-% \TeX's built-in value is half a quad in
-% font number 2 (|.5\fontdimen6\textfont\tw@|).
+% \TeX's built-in value is half a quad
+% \unskip\footnote{another half of a quad
+% is left empty at the other end of the line.}
+% in font number 2.
 % As the tag is processed in text mode, we use |0.5em| instead.
-% \TODO may set within environment
 %    \begin{macrocode}
 \newdimen\eql at tagsepmin@
-\eql at regsetdelayed\eql at tagsepmin@{.5em}
+\def\eql at tagsepmin@val{.5\fontdimen6\textfont\tw@}
 %    \end{macrocode}
 %
+%   \macro{\eql at equations@sqr at opt}
+%   \macro{\eql at equations@ang at opt}
+% The macros |\eql at equations@sqr at opt| and |\eql at equations@ang at opt|
+% store the default arguments for |\[...\]| and |\<...\>|, respectively:
+%    \begin{macrocode}
+\def\eql at equations@sqr at opt{equation,nonumber}
+\def\eql at equations@ang at opt{align,nonumber}
+%    \end{macrocode}
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Multi-Line Align Mode.}
+%
+%    \begin{macrocode}
+\let\eql at align@margins\eql at true
+%    \end{macrocode}
+%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Registers}
 %
+% \TODO describe
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{General.}
+%
+%   \lbox{\eql at fieldbox@}
+%   \lbox{\eql at tagbox@}
+%   \ldimen{\eql at fieldwidth@}
+%   \ldimen{\eql at tagwidth@}
+% The box |\eql at fieldbox@| holds the present alignment component
+% and |\eql at tagbox@| the tag for the present line.
+% The corresponding dimensions |\eql at fieldwidth@| and |\eql at tagwidth@|
+% hold their widths:
+%    \begin{macrocode}
+\newbox\eql at fieldbox@
+\newbox\eql at tagbox@
+\newdimen\eql at fieldwidth@
+\newdimen\eql at tagwidth@
+%    \end{macrocode}
+%
+%   \ldimen{\eql at totalwidth@}
+%   \ldimen{\eql at tagwidth@max@}
+%    \begin{macrocode}
+\newdimen\eql at totalwidth@
+\newdimen\eql at tagwidth@max@
+%    \end{macrocode}
+%
+%   \ldimen{\eql at line@height@}
+%   \ldimen{\eql at line@depth@}
+% The dimension registers |\eql at line@height@| and |\eql at line@depth@| keep
+% track of the height and depth of the present line in an alignment:
+%    \begin{macrocode}
+\newdimen\eql at line@height@
+\newdimen\eql at line@depth@
+%    \end{macrocode}
+%
+%   \ldimen{\eql at line@width@}
+%   \ldimen{\eql at line@avail@}
+%   \ldimen{\eql at line@pos@}
+%    \begin{macrocode}
+\newdimen\eql at line@width@
+\newdimen\eql at line@avail@
+\newdimen\eql at line@pos@
+%    \end{macrocode}
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Rows and Columns.}
+%
 %   \tcounter{\eql at row@}
 %   \tcounter{\eql at totalrows@}
+%   \tcounter{\eql at tagrows@}
 % |\eql at row@| counts the present row (1-based)
 % and |\eql at totalrows@| holds the total number of rows:
 %    \begin{macrocode}
 \newcount\eql at row@
 \newcount\eql at totalrows@
+\newcount\eql at tagrows@
 %    \end{macrocode}
 %
+%   \macro{\eql at column@}
+%   \macro{\eql at totalcolumns@}
+%    \begin{macrocode}
+\newcount\eql at column@
+\newcount\eql at totalcolumns@
+%    \end{macrocode}
+%
 %   \ldimen{\eql at colsep@}
 % The dimension of the intercolumn separation for align environments
 % is stored in |\eql at colsep@|:
@@ -1916,6 +2180,14 @@
 \newdimen\eql at colsep@
 %    \end{macrocode}
 %
+%   \tcounter{\eql at align@inter@}
+%    \begin{macrocode}
+\newcount\eql at align@inter@
+%    \end{macrocode}
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Vertical Spacing Adjustments.}
+%
 %   \ldimen{\eql at display@firstavail@}
 %   \macro{\eql at display@firstavail at set}
 % The unused space on the first line of an alignment is stored in
@@ -1941,30 +2213,9 @@
 \newcount\eql at raisetag@firstlast@
 %    \end{macrocode}
 %
-%   \lbox{\eql at fieldbox@}
-%   \lbox{\eql at tagbox@}
-%   \ldimen{\eql at fieldwidth@}
-%   \ldimen{\eql at tagwidth@}
-% The box |\eql at fieldbox@| holds the present alignment component
-% and |\eql at tagbox@| the tag for the present line.
-% The corresponding dimensions |\eql at fieldwidth@| and |\eql at tagwidth@|
-% hold their widths:
-%    \begin{macrocode}
-\newbox\eql at fieldbox@
-\newbox\eql at tagbox@
-\newdimen\eql at fieldwidth@
-\newdimen\eql at tagwidth@
-%    \end{macrocode}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Shared Registers.}
 %
-%   \ldimen{\eql at line@height@}
-%   \ldimen{\eql at line@depth@}
-% The dimension registers |\eql at line@height@| and |\eql at line@depth@| keep
-% track of the height and depth of the present line in an alignment:
-%    \begin{macrocode}
-\newdimen\eql at line@height@
-\newdimen\eql at line@depth@
-%    \end{macrocode}
-%
 %   \lcond{\ifmeasuring@}
 % All display environments get typeset twice -- once during a
 % ``measuring'' phase and then again during a ``production'' phase.
@@ -1975,7 +2226,6 @@
 % We should tell \ctanpkg{hyperref} about measuring processes
 % as we're not \ctanpkg{amsmath} and not being catered for:
 %    \begin{macrocode}
-% \newif\ifmeasuring@
 \ifdefined\measuring at true\else
   \expandafter\newif\csname ifmeasuring@\endcsname
 \fi
@@ -1993,7 +2243,6 @@
 % We provide it in case \ctanpkg{amsmath} is absent,
 % and initialise it:
 %    \begin{macrocode}
-% \newif\if at display
 \ifdefined\@displaytrue\else
   \expandafter\newif\csname if at display\endcsname
   \everydisplay\expandafter{\the\everydisplay\@displaytrue}
@@ -2028,76 +2277,7 @@
 %
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \section{Tagging Support}
-%
-%    \begin{macrocode}
-\let\eql at tagging@on\eql at false
-\IfFormatAtLeastTF{2025-06-01}{%
-  \csname tag_if_active:T\endcsname{\let\eql at tagging@on\eql at true}}{}
-\ifdefined\eql at tagging@on
-  \def\eql at tagging@mathsave{%
-    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
-  \def\eql at tagging@mathaddlast{%
-    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
-  \def\eql at tagging@tagbegin{%
-    \UseTaggingSocket{math/display/tag/begin}}
-  \def\eql at tagging@tagend{%
-    \UseTaggingSocket{math/display/tag/end}}
-  \def\eql at tagging@tagsave{%
-    \UseTaggingSocket{math/luamml/mtable/tag/save}}
-  \def\eql at tagging@tagaddbox{%
-    \setbox\z@\copy\eql at tagbox@%
-    \UseTaggingSocket{math/luamml/mtable/tag/set}}
-  \def\eql at tagging@tablesaveinner{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
-  \def\eql at tagging@tableaddinner{%
-    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
-  \def\eql at tagging@tablesavelines{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
-  \def\eql at tagging@tablesavealign{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
-  \def\eql at tagging@alignleft{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
-  \def\eql at tagging@aligncenter{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
-  \def\eql at tagging@alignright{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
-  \let\eql at single@doscan\eql at true
-  \let\eql at scan@body\eql at scan@body at rescan
-  \ExplSyntaxOn
-  \def\eql at tagging@start{%
-    \bool_if:NF\l__math_collected_bool{%
-      \toks@\expandafter{\eql at tagging@opt}%
-      \edef\eql at tmp{{\@currenvir}{[\the\toks@] \the\eql at scan@reg@}}%
-      \expandafter\__math_process:nn\eql at tmp
-      \@kernel at math@registered at begin
-      \bool_set_true:N\l__math_collected_bool
-    }%
-  }
-  \def\eql at tagging@end{}
-  \ExplSyntaxOff
-\else
-  \def\eql at tagging@mathsave{}
-  \def\eql at tagging@mathaddlast{}
-  \def\eql at tagging@tagbegin{}
-  \def\eql at tagging@tagend{}
-  \def\eql at tagging@tagsave{}
-  \def\eql at tagging@tagaddbox{}
-  \def\eql at tagging@tablesaveinner{}
-  \def\eql at tagging@tableaddinner{}
-  \def\eql at tagging@tablesavelines{}
-  \def\eql at tagging@tablesavealign{}
-  \def\eql at tagging@alignleft{}
-  \def\eql at tagging@aligncenter{}
-  \def\eql at tagging@alignright{}
-  \def\eql at tagging@start{}
-  \def\eql at tagging@end{}
-\fi
-%    \end{macrocode}
-%
-%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \section{Punctuation}
 %
 % The equations environments supply an automatic punctuation scheme
@@ -2129,7 +2309,7 @@
 %   \imacro{\eqnpunct}
 % Set the punction for columns, lines and blocks.
 % Note that the macro |\eqnpunct| sets the punctuation for the
-% next equation block (only).
+% following equation block or for the current field.
 % Starred versions clear the punctuation for the respectively levels:
 %    \begin{macrocode}
 \def\eqnpunctcol{\eql at ifstar@tight\eql at punct@col at setrelax\eql at punct@col at set}
@@ -2139,11 +2319,25 @@
 \def\eql at punct@line at set#1{\def\eql at punct@line{#1}\ignorespaces}
 \def\eql at punct@line at setrelax{\let\eql at punct@line\relax\ignorespaces}
 \def\eqnpunctmain{\eql at ifstar@tight\eql at punct@main at setrelax\eql at punct@main at set}
-\def\eql at punct@main at set#1{\eqnlinesset{punct={#1}}\ignorespaces}
-\def\eql at punct@main at setrelax{\eqnlinesset{punct*}\ignorespaces}
+\def\eql at punct@main at set#1{\def\eql at punct@main{#1}\ignorespaces}
+\def\eql at punct@main at setrelax{\let\eql at punct@main\relax\ignorespaces}
 \def\eqnpunct{\eql at ifstar@tight\eql at punct@next at setrelax\eql at punct@next at set}
-\def\eql at punct@next at set#1{\eqnaddopt{punct={#1}}\ignorespaces}
-\def\eql at punct@next at setrelax{\eqnaddopt{punct*}\ignorespaces}
+\def\eql at punct@next at set#1{%
+  \ifmmode
+    \def\eql at punct@col{#1}%
+    \def\eql at punct@line{#1}%
+    \def\eql at punct@block{#1}%
+  \else
+    \eqnaddopt{punct={#1}}%
+  \fi
+  \ignorespaces}
+\def\eql at punct@next at setrelax{%
+  \ifmmode
+    \let\eql at punct@block\relax
+  \else
+    \eqnaddopt{punct*}%
+  \fi
+  \ignorespaces}
 %    \end{macrocode}
 %
 %   \macro{\eql at punct@apply at col}
@@ -2547,8 +2741,8 @@
 \def\eql at tag@boxedform#1{\eql at tag@box{\eql at tag@form{#1}}}
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%    \paragraph{Raise Tags}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Raise Tags.}
 %
 %   \ldimen{\eql at raisetag@amount@}
 %    \begin{macrocode}
@@ -2847,19 +3041,6 @@
 }
 %    \end{macrocode}
 %
-% \TODO describe
-%    \begin{macrocode}
-\def\eql at compose@null{%
-  \ifdefined\eql at nexttag\else
-    \stepcounter{equation}%
-  \fi
-  \ifnum\eql at numbering@target@<\z@
-    \global\let\eql at nextlabel\@undefined
-    \global\let\eql at nexttag\@undefined
-  \fi
-}
-%    \end{macrocode}
-%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Tagbox Methods}
 %
@@ -2988,6 +3169,10 @@
   \ifcsname eql at numbering@tab@#1\endcsname
     \expandafter\let\expandafter\eql at numbering@mode
       \csname eql at numbering@tab@#1\endcsname
+    \ifx\eql at numbering@mode\eql at numbering@tab at none
+      \let\eql at numbering@mode\eql at numbering@tab at all
+      \let\eql at numbering@active\eql at false
+    \fi
   \else
     \eql at error{numbering mode `#1' unknown: setting to `all'}%
     \let\eql at numbering@mode\eql at numbering@tab at all
@@ -3007,9 +3192,6 @@
 \def\eql at numbering@mode at sub{%
   \eql at numbering@target@\m at ne
   \let\eql at numbering@subeq at use\eql at true}
-\def\eql at numbering@mode at none{%
-  \eql at numbering@target@\m at ne
-  \let\eql at numbering@active\eql at false}
 \def\eql at numbering@mode at first{%
   \eql at numbering@target@\@ne}
 \def\eql at numbering@mode at last{%
@@ -3206,8 +3388,8 @@
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \paragraph{Single-Line}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Single Line.}
 %
 % \TODO describe
 %
@@ -3238,8 +3420,8 @@
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \paragraph{Multi-Line Measuring Pass}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Multi-Line Measuring Pass.}
 %
 % \TODO describe
 %
@@ -3301,8 +3483,8 @@
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \paragraph{Multi-Line Print Pass}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Multi-Line Print Pass.}
 %
 % \TODO describe
 %
@@ -3538,7 +3720,6 @@
 \def\eql at subequations@addlabel#1#2{\eqnaddopt{label={#2}}#1}
 %    \end{macrocode}
 %
-%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Subequation Scheme}
 %
@@ -3842,13 +4023,17 @@
   \advance\abovedisplayskip\eql at abovespace@
   \advance\belowdisplayskip\eql at belowspace@
   \advance\belowdisplayskip\eql at vspaceskip@
-  \abovedisplayshortskip\abovedisplayskip
-  \belowdisplayshortskip\belowdisplayskip
   \count@\prevgraf
   \advance\count@\eql at row@
   \advance\count at -\tw@
   \prevgraf\count@
   \global\eql at skip@mode at leave@\eql at skip@mode at leave@
+% \TODO temporary fix
+  \ifdefined\eql at tagging@on
+    \ifdefined\dollardollar at begin\else
+      \belowdisplayskip-\belowdisplayskip
+    \fi
+  \fi
 }
 %    \end{macrocode}
 %
@@ -4063,8 +4248,10 @@
     \eql at stack@save at reg\eql at line@width@
     \eql at stack@save at reg\eql at line@depth@
     \eql at stack@save at reg\eql at line@height@
+    \eql at stack@save at reg\eql at tagwidth@max@
     \eql at stack@save at reg\eql at numbering@target@
     \eql at stack@save at reg\eql at row@
+    \eql at stack@save at reg\eql at tagrows@
   }%
 }
 \def\eql at stack@save at boxed@{%
@@ -4199,7 +4386,7 @@
 %   \macro{\eql at shape@center at ...}
 %   \macro{\eql at shape@left at ...}
 % Define the uniform shape schemes |left|, |center|, |right| and |default|
-% for the centered and flush-left layout.
+% for the central and left alignment layout.
 % The scheme functions determine the desired alignment and indentation
 % for the current row:
 %    \begin{macrocode}
@@ -4238,8 +4425,8 @@
 %
 % The |hanging| scheme implements left alignment with
 % hanging indentation for the first line (unless there is only one line).
-% In centered layout all but the first line are indented
-% while in flush-left layout the first line has negative indentation:
+% In centeral alignment layout all but the first line are indented
+% while in left aligned layout the first line has negative indentation:
 %    \begin{macrocode}
 \def\eql at shape@center at hanging{%
   \eql at shape@pos@\z@
@@ -4263,8 +4450,8 @@
 %
 % The |steps| scheme implements singles out the first and last lines
 % which are shifted left and right, respectively.
-% In centered layout the shift operates on the alignment
-% whereas in flush-left layout the shift uses indentation:
+% In centeral alignment layout the shift operates on the alignment
+% whereas in left alignment layout the shift uses indentation:
 %    \begin{macrocode}
 \def\eql at shape@center at steps{%
   \eql at shape@amount@\z@
@@ -4447,8 +4634,40 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at adjust@calc}
+% \TODO any init needed for left alignment layout? marginleft is used per line!
+%    \begin{macrocode}
+\def\eql at adjust@calc{%
+  \ifdefined\eql at flushleft
+    \eql at flushleftmargin@\glueexpr\eql at flushleftmargin@val\relax
+  \else
+    \eql at align@inter@\z@
+    \eql at adjust@tagmargin
+    \ifdefined\eql at paddingmax
+      \eql at marginleft@\z@
+      \eql at marginright@\z@
+    \else
+      \dimen@\displaywidth
+      \advance\dimen at -\eql at totalwidth@
+      \advance\dimen at -\eql at tagmargin@
+      \divide\dimen@\tw@
+      \eql at marginleft@\dimen@
+      \advance\eql at marginleft@-\glueexpr\eql at paddingleft@val\relax
+      \ifdim\eql at marginleft@<\z@
+        \eql at marginleft@\z@
+      \fi
+      \eql at marginright@\dimen@
+      \advance\eql at marginright@-\glueexpr\eql at paddingright@val\relax
+      \ifdim\eql at marginright@<\z@
+        \eql at marginright@\z@
+      \fi
+    \fi
+  \fi
+}
+%    \end{macrocode}
+%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Centered Layout}
+% \subsection{Centeral Alignment Layout}
 %
 % \TODO describe
 %
@@ -4723,8 +4942,47 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at adjust@tagmargin}
+%    \begin{macrocode}
+\def\eql at adjust@tagmargin{%
+  \ifdefined\eql at tagmargin@val
+    \eql at tagmargin@\glueexpr\eql at tagmargin@val\relax
+  \else
+    \eql at tagmargin@\eql at tagwidth@max@
+    \ifdim\eql at tagmargin@>\z@
+      \advance\eql at tagmargin@-\eql at tagsepmin@
+    \fi
+  \fi
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+  \dimen@\eql at tagrows@\p@
+  \ifnum\eql at totalrows@=\@ne
+    \ifnum\eql at tagrows@=\@ne
+      \advance\dimen at 1sp\relax
+    \fi
+  \fi
+  \ifdim\dimen@>\eql at totalrows@\eql at tagmargin@ratio@\else
+    \eql at tagmargin@\z@
+  \fi
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+  \@tempdima\displaywidth
+  \advance\@tempdima-\eql at totalwidth@
+  \advance\@tempdima-\eql at align@inter@\eql at colsepmin@
+  \@tempdimb\@tempdima
+  \advance\@tempdimb-\tw@\eql at tagmargin@
+  \ifdim\@tempdimb>\z@
+    \ifdim\eql at tagmargin@threshold\@tempdima<\@tempdimb
+      \eql at tagmargin@\z@
+    \fi
+  \fi
+}
+%    \end{macrocode}
+%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Flush-Left Layout}
+% \subsection{Left Alignment Layout}
 %
 % \TODO describe
 %
@@ -4968,7 +5226,7 @@
 \def\eql at single@start{%
   \eql at halign@catchprevdepth
   \eql at tagging@start
-  $$%$$
+  \eql at dollardollar@begin
   \eql at numbering@eval at mode
   \let\eql at numbering@subeq at use\eql at false
   \eql at stack@save at single
@@ -5001,7 +5259,7 @@
   \eql at hook@eqout
   \eql at single@end at sel
   \eql at stack@restore
-  $$%$$
+  \eql at dollardollar@end
   \eql at tagging@end
   \eql at halign@leave
 }
@@ -5055,12 +5313,9 @@
   \let\shoveleft\eql at adjust@shoveleft
   \let\shovecenter\eql at adjust@shovecenter
   \let\shoveright\eql at adjust@shoveright
-  \ifdefined\eql at flushleft\else
-    \eql at marginleft@\z@
-    \eql at marginright@\z@
-  \fi
   \eql at adjust@init
   \eql at shape@eval
+  \eql at halign@init{}%
 %    \end{macrocode}
 %
 %    \begin{macrocode}
@@ -5086,14 +5341,29 @@
   \eql at fieldwidth@\wd\eql at fieldbox@
   \eql at line@height@\ht\eql at fieldbox@
   \eql at line@depth@\dp\eql at fieldbox@
+  \eql at totalwidth@\eql at fieldwidth@
+  \eql at totalrows@\@ne
 %    \end{macrocode}
 %
 %    \begin{macrocode}
-  \eql at halign@init{}%
+  \if at eqnsw
+    \eql at tagbox@make\eql at compose@print
+    \eql at tagrows@\@ne
+  \else
+    \eql at tagwidth@\z@
+    \eql at tagrows@\z@
+  \fi
+  \eql at tagwidth@max@\eql at tagwidth@
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+  \eql at adjust@calc
+%    \end{macrocode}
+%
+%    \begin{macrocode}
   \halign{##\cr
     \noalign{\eql at halign@before}%
     \if at eqnsw
-      \eql at tagbox@make\eql at compose@print
       \eql at adjust@sel at tag
     \else
       \eql at adjust@sel at notag
@@ -5109,6 +5379,7 @@
 %
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \section{Multi-Line Support}
 %
 % \TODO describe
@@ -5116,27 +5387,8 @@
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Registers}
 %
-%   \macro{\eql at column@}
-%   \macro{\eql at totalcolumns@}
-%    \begin{macrocode}
-\newcount\eql at column@
-\newcount\eql at totalcolumns@
-%    \end{macrocode}
-%
-%   \ldimen{\eql at totalwidth@}
-%    \begin{macrocode}
-\newdimen\eql at totalwidth@
-%    \end{macrocode}
-%
-%   \ldimen{\eql at line@width@}
-%   \ldimen{\eql at line@avail@}
-%   \ldimen{\eql at line@pos@}
-%    \begin{macrocode}
-\newdimen\eql at line@width@
-\newdimen\eql at line@avail@
-\newdimen\eql at line@pos@
-%    \end{macrocode}
-%
+% \TODO can we unite |\eql at fieldlength@tab| and |\eql at tagwidth@tab|
+% \TODO then process sequentially not using ifcase?
 %   \macro{\eql at fieldlength@tab}
 %   \macro{\eql at fieldlength@save}
 %   \macro{\eql at fieldlength@get}
@@ -5182,6 +5434,24 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at colwidth@tab}
+%    \begin{macrocode}
+\let\eql at colwidth@tab\@empty
+%    \end{macrocode}
+%
+%   \macro{\eql at align@colwidth at get}
+%    \begin{macrocode}
+\def\eql at align@colwidth at get#1{%
+  \ifcase\expandafter#1\eql at colwidth@tab\else\z@\fi
+}
+\def\eql at align@colwidth at save{%
+  \begingroup
+    \let\or\relax
+    \global\edef\eql at colwidth@tab{\or\the\wd\thr@@\eql at colwidth@tab}%
+  \endgroup
+}
+%    \end{macrocode}
+%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Measure Support}
 %
@@ -5465,7 +5735,7 @@
 \def\eql at multi@main{%
   \eql at halign@catchprevdepth
   \eql at tagging@start
-  $$%$$
+  \eql at dollardollar@begin
   \eql at numbering@eval at mode
   \eql at stack@save at multi
   \ifdefined\eql at subequations@active
@@ -5508,7 +5778,7 @@
     \eql at numbering@subeq at close
   \fi
   \eql at stack@restore
-  $$%$$
+  \eql at dollardollar@end
   \eql at tagging@end
   \eql at halign@leave
 }
@@ -5579,7 +5849,13 @@
 \def\eql at lines@measure at tag{%
   \ifnum\eql at numbering@target@<\z@
     \if at eqnsw
-      \eql at compose@null
+      \eql at tagbox@make\eql at compose@measure
+      \ifdim\eql at tagwidth@>\eql at tagwidth@max@
+        \global\eql at tagwidth@max@\eql at tagwidth@
+      \fi
+      \global\advance\eql at tagrows@\@ne
+    \else
+      \eql at tagwidth@\z@
     \fi
   \fi
 }
@@ -5589,6 +5865,8 @@
 %    \begin{macrocode}
 \def\eql at lines@measure{%
 %<dev>\eql at dev@enter\eql at lines@measure
+  \eql at tagwidth@max@\z@
+  \eql at tagrows@\z@
   \eql at measure@savecounters
   \setbox\z@\vbox{%
     \eql at numbering@measure at init
@@ -5626,8 +5904,17 @@
     }%
     \global\advance\eql at row@-\tw@
     \eql at numbering@measure at eval
+    \ifnum\eql at numbering@target@>\z@
+      \eql at tagbox@make\eql at compose@measure
+      \global\eql at tagwidth@max@\eql at tagwidth@
+      \global\eql at tagrows@\@ne
+    \fi
   }%
   \eql at totalrows@\eql at row@
+  \ifdefined\eql at numbering@subeq at use
+    \eql at numbering@subeq at test
+  \fi
+  \eql at measure@restorecounters
   \setbox\z@\vbox{%
     \unvbox\z@
     \unpenalty
@@ -5634,10 +5921,9 @@
     \global\setbox\@ne\lastbox
   }%
   \eql at totalwidth@\wd\@ne
-  \ifdefined\eql at numbering@subeq at use
-    \eql at numbering@subeq at test
-  \fi
-  \eql at measure@restorecounters
+%    \end{macrocode}
+%
+%    \begin{macrocode}
 %<dev>\eql at dev@leave\eql at lines@measure
 }
 %    \end{macrocode}
@@ -5647,7 +5933,7 @@
 %
 % \TODO describe
 %
-%   \macro{\eql at lines@math at cr}
+%   \macro{\eql at lines@print at line@begin}
 %    \begin{macrocode}
 \def\eql at lines@print at line@begin{%
 %<dev>\eql at dev{starting line \the\eql at row@}%
@@ -5685,30 +5971,8 @@
 \def\eql at lines@print{%
 %<dev>\eql at dev@enter\eql at lines@print
   \eql at display@init
-  \ifdefined\eql at flushleft
-% \TODO any init needed here? marginleft is used per line!
-  \else
-    \ifdefined\eql at paddingmax
-      \eql at marginleft@\z@
-      \eql at marginright@\z@
-    \else
-      \dimen@\displaywidth
-      \advance\dimen at -\eql at totalwidth@
-      \advance\dimen at -\eql at tagmargin@
-      \divide\dimen@\tw@
-      \eql at marginleft@\dimen@
-      \advance\eql at marginleft@-\glueexpr\eql at paddingleft@val\relax
-      \ifdim\eql at marginleft@<\z@
-        \eql at marginleft@\z@
-      \fi
-      \eql at marginright@\dimen@
-      \advance\eql at marginright@-\glueexpr\eql at paddingright@val\relax
-      \ifdim\eql at marginright@<\z@
-        \eql at marginright@\z@
-      \fi
-    \fi
-  \fi
   \eql at adjust@init
+  \eql at adjust@calc
   \eql at numbering@print at init
   \eql at print@init\eql at lines@print at line@begin
   \eql at let@cr\eql at lines@print at line@end
@@ -5764,65 +6028,188 @@
 % \TODO describe
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Registers}
+% \subsection{Columns Processing}
 %
 % \TODO describe
 %
+%   \macro{\eql at align@add at amp}
+%   \macro{\eql at align@completerow}
 %    \begin{macrocode}
-\let\eql at align@margins\eql at true
+\def\eql at align@add at amp#1{\if m#1&\omit\expandafter\eql at align@add at amp\fi}
+\def\eql at align@completerow{%
+  \count@\eql at totalcolumns@
+  \advance\count at -\eql at column@
+  \advance\count@\@ne
+  \edef\eql at tmp{%
+    \expandafter\eql at align@add at amp\romannumeral\number\count@ 000q}%
+  \eql at tmp
+}
 %    \end{macrocode}
 %
-%   \macro{\eql at align@inter@}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \subsection{Measure}
+%
+% \TODO describe
+%
+%   \macro{\eql at align@measure at line@begin}
 %    \begin{macrocode}
-\newcount\eql at align@inter@
+\def\eql at align@measure at line@begin{%
+%<dev>\eql at dev{starting line \the\eql at row@}%
+  \global\eql at column@\z@
+  \eql at numbering@measure at line@begin
+  \eql at hook@linein
+}
 %    \end{macrocode}
 %
-%   \macro{\eql at colwidth@tab}
 %    \begin{macrocode}
-\let\eql at colwidth@tab\@empty
+\def\eql at align@measure at field{%
+  \eql at fieldlength@save\eql at column@
+  \kern\wd\eql at fieldbox@
+}
 %    \end{macrocode}
 %
-%   \macro{\eql at align@colwidth at get}
+%   \macro{\eql at align@measure at line@end}
 %    \begin{macrocode}
-\def\eql at align@colwidth at get#1{%
-  \ifcase\expandafter#1\eql at colwidth@tab\else\z@\fi
+\def\eql at align@measure at line@end{%
+  \eql at punct@apply at line
+  \eql at hook@lineout
+  &\omit
+  \ifnum\eql at column@>\eql at totalcolumns@
+    \global\eql at totalcolumns@\eql at column@
+  \fi
+  \eql at align@measure at tag
 }
-\def\eql at align@colwidth at save{%
-  \begingroup
-    \let\or\relax
-    \global\edef\eql at colwidth@tab{\or\the\wd\thr@@\eql at colwidth@tab}%
-  \endgroup
+%    \end{macrocode}
+%
+%   \macro{\eql at align@measure at tag}
+%    \begin{macrocode}
+\def\eql at align@measure at tag{%
+  \ifnum\eql at numbering@target@<\z@
+    \if at eqnsw
+      \eql at tagbox@make\eql at compose@measure
+      \ifdim\eql at tagwidth@>\eql at tagwidth@max@
+        \global\eql at tagwidth@max@\eql at tagwidth@
+      \fi
+      \global\advance\eql at tagrows@\@ne
+    \else
+      \eql at tagwidth@\z@
+    \fi
+    \eql at tagwidth@save
+  \fi
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{General Processing, Preamble}
+%   \macro{\eql at align@measure}
+%    \begin{macrocode}
+\def\eql at align@measure{%
+%<dev>\eql at dev@enter\eql at align@measure
+  \eql at totalcolumns@\z@
+  \eql at tagwidth@max@\z@
+  \let\eql at tagwidth@tab\@empty
+  \let\eql at fieldlength@tab\@empty
+  \eql at tagrows@\z@
+  \eql at measure@savecounters
+  \setbox\z@\vbox{%
+    \eql at numbering@measure at init
+    \eql at measure@init\eql at align@measure at line@begin
+    \eql at let@cr\eql at align@measure at line@end
+    \tabskip\z at skip
+    \halign{%
+      &%
+        \global\advance\eql at column@\@ne
+        \hfil
+        \global\setbox\eql at fieldbox@\hbox{%
+          \@lign
+          $\m at th\displaystyle
+            \eql at hook@colin
+            ##%
+            \eql at class@innerleft
+            \eql at hook@innerleft
+          $%
+        }%
+        \global\eql at fieldwidth@\wd\eql at fieldbox@
+        \eql at align@measure at field
+      &%
+        \global\advance\eql at column@\@ne
+        \setbox\eql at fieldbox@\hbox{%
+          \@lign
+          $\m at th\displaystyle
+            \eql at hook@innerright
+            \eql at class@innerright at sel
+            ##%
+            \eql at punct@apply at col
+            \eql at hook@colout
+          $%
+        }%
+        \eql at align@measure at field
+        \hfil
+      \crcr
+      \noalign{%
+        \eql at hook@blockbefore
+      }%
+      \eql at hook@blockin
+      \eql at scan@body
+%    \end{macrocode}
+%    \TODO test for vmode okay?!
+%    \begin{macrocode}
+      \ifvmode\else
+        \eql at punct@apply at block
+        \eql at hook@blockout
+        \eql at align@measure at line@end
+        \cr
+      \fi
+      \noalign{%
+        \eql at hook@blockafter
+      }%
+%    \end{macrocode}
+%    \TODO should we enforce even columns already here?!
+%    \TODO should we guard against no columns at all?!
+%    \begin{macrocode}
+      \eql at align@completerow
+      \cr
+    }%
+    \global\advance\eql at row@-\tw@
+    \eql at numbering@measure at eval
+    \ifnum\eql at numbering@target@>\z@
+      \eql at tagbox@make\eql at compose@measure
+      \global\eql at tagwidth@max@\eql at tagwidth@
+      \global\eql at tagrows@\@ne
+      \eql at tagwidth@savezero
+    \fi
+  }%
+  \eql at totalrows@\eql at row@
+  \ifdefined\eql at numbering@subeq at use
+    \eql at numbering@subeq at test
+  \fi
+  \eql at measure@restorecounters
+%  \eql at totalwidth@\wd\z@
+%    \end{macrocode}
 %
-% \TODO describe
+%    \begin{macrocode}
+  \setbox\z@\vbox{%
+    \unvbox\z@
+    \unpenalty
+    \global\setbox\@ne\lastbox
+  }%
+  \eql at totalwidth@\wd\@ne
+%    \end{macrocode}
 %
-%   \macro{\eql at align@add at amp}
-%   \macro{\eql at align@completerow}
+%    \TODO why not recycle box contents altogether?!
 %    \begin{macrocode}
-\def\eql at align@add at amp#1{\if m#1&\omit\expandafter\eql at align@add at amp\fi}
-\def\eql at align@completerow#1{%
-  \begingroup
-  \count@#1%
-  \advance\count at -\eql at column@
-\advance\count@\@ne
-  \edef\eql at tmp{\endgroup
-    \expandafter\eql at align@add at amp\romannumeral\number\count@ 000q}%
-  \eql at tmp
-}
+  \let\eql at colwidth@tab\@empty
+  \loop
+    \setbox\@ne\hbox{%
+      \unhbox\@ne
+      \unskip
+      \global\setbox\thr@@\lastbox
+    }%
+  \ifhbox\thr@@
+    \eql at align@colwidth at save
+  \repeat
 %    \end{macrocode}
 %
 %    \begin{macrocode}
-\def\eql at align@print at trailright{%
-   &\omit
-    \global\advance\eql at column@\@ne
-    \setbox\eql at fieldbox@\hbox{%
-      \kern-\wd\eql at fieldbox@\box\eql at fieldbox@
-    }%
-    \eql at align@print at field
+%<dev>\eql at dev@leave\eql at align@measure
 }
 %    \end{macrocode}
 %
@@ -5831,7 +6218,23 @@
 %
 % \TODO describe
 %
+%   \macro{\eql at align@print at line@begin}
 %    \begin{macrocode}
+\def\eql at align@print at line@begin{%
+%<dev>\eql at dev{starting line \the\eql at row@}%
+  \global\eql at column@\z@
+  \global\eql at line@pos@\eql at marginleft@
+  \global\eql at line@width@\z@
+  \global\eql at line@avail@\eql at totalwidth@
+  \global\eql at line@height@\z@
+  \global\eql at line@depth@\z@
+  \eql at numbering@print at line@begin
+  \eql at hook@linein
+}
+%    \end{macrocode}
+%
+%   \macro{\eql at align@print at field}
+%    \begin{macrocode}
 \def\eql at align@print at field{%
 %    \end{macrocode}
 % determine available and used space
@@ -5860,7 +6263,7 @@
   \fi
   \global\eql at line@pos@\eql at line@pos@
 %    \end{macrocode}
-%    update height and depth
+% update height and depth
 %    \begin{macrocode}
   \ifdim\ht\eql at fieldbox@>\eql at line@height@
     \global\eql at line@height@\ht\eql at fieldbox@
@@ -5898,18 +6301,14 @@
 }
 %    \end{macrocode}
 %
-%   \macro{\eql at align@print at line@begin}
 %    \begin{macrocode}
-\def\eql at align@print at line@begin{%
-%<dev>\eql at dev{starting line \the\eql at row@}%
-  \global\eql at column@\z@
-  \global\eql at line@pos@\eql at marginleft@
-  \global\eql at line@width@\z@
-  \global\eql at line@avail@\eql at totalwidth@
-  \global\eql at line@height@\z@
-  \global\eql at line@depth@\z@
-  \eql at numbering@print at line@begin
-  \eql at hook@linein
+\def\eql at align@print at trailright{%
+   &\omit
+    \global\advance\eql at column@\@ne
+    \setbox\eql at fieldbox@\hbox{%
+      \kern-\wd\eql at fieldbox@\box\eql at fieldbox@
+    }%
+    \eql at align@print at field
 }
 %    \end{macrocode}
 %
@@ -5922,14 +6321,14 @@
   \ifodd\eql at column@
     \expandafter\eql at align@print at trailright
   \fi
-  \eql at align@completerow\eql at totalcolumns@
-  \eql at align@print at line
+  \eql at align@completerow
+  \eql at align@print at tag
 }
 %    \end{macrocode}
 %
-%   \macro{\eql at align@print at line}
+%   \macro{\eql at align@print at tag}
 %    \begin{macrocode}
-\def\eql at align@print at line{%
+\def\eql at align@print at tag{%
   \dimen@\eql at totalwidth@
   \advance\dimen@\eql at colsep@
   \kern-\dimen@
@@ -6026,172 +6425,11 @@
 %    \end{macrocode}
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Measure}
-%
-% \TODO describe
-%
-%   \macro{\eql at align@measure at line@begin}
-%    \begin{macrocode}
-\def\eql at align@measure at line@begin{%
-%<dev>\eql at dev{starting line \the\eql at row@}%
-  \global\eql at column@\z@
-  \eql at numbering@measure at line@begin
-  \eql at hook@linein
-}
-%    \end{macrocode}
-%
-%    \begin{macrocode}
-\def\eql at align@measure at field{%
-  \eql at fieldlength@save\eql at column@
-  \kern\wd\eql at fieldbox@
-}
-%    \end{macrocode}
-%
-%   \macro{\eql at align@measure at line@end}
-%    \begin{macrocode}
-\def\eql at align@measure at line@end{%
-  \eql at punct@apply at line
-  \eql at hook@lineout
-  &\omit
-  \ifnum\eql at column@>\eql at totalcolumns@
-    \global\eql at totalcolumns@\eql at column@
-  \fi
-  \eql at align@measure at tag
-}
-%    \end{macrocode}
-%
-%   \macro{\eql at align@measure at tag}
-%    \begin{macrocode}
-\def\eql at align@measure at tag{%
-  \ifnum\eql at numbering@target@<\z@
-    \if at eqnsw
-      \eql at tagbox@make\eql at compose@measure
-    \else
-      \eql at tagwidth@\z@
-    \fi
-    \eql at tagwidth@save
-  \fi
-}
-%    \end{macrocode}
-%
-%   \macro{\eql at align@measure}
-%    \begin{macrocode}
-\def\eql at align@measure{%
-%<dev>\eql at dev@enter\eql at align@measure
-  \eql at totalcolumns@\z@
-  \let\eql at tagwidth@tab\@empty
-  \let\eql at fieldlength@tab\@empty
-  \eql at measure@savecounters
-  \setbox\z@\vbox{%
-    \eql at numbering@measure at init
-    \eql at measure@init\eql at align@measure at line@begin
-    \eql at let@cr\eql at align@measure at line@end
-    \tabskip\z at skip
-    \halign{%
-      &%
-        \global\advance\eql at column@\@ne
-        \hfil
-        \global\setbox\eql at fieldbox@\hbox{%
-          \@lign
-          $\m at th\displaystyle
-            \eql at hook@colin
-            ##%
-            \eql at class@innerleft
-            \eql at hook@innerleft
-          $%
-        }%
-        \global\eql at fieldwidth@\wd\eql at fieldbox@
-        \eql at align@measure at field
-      &%
-        \global\advance\eql at column@\@ne
-        \setbox\eql at fieldbox@\hbox{%
-          \@lign
-          $\m at th\displaystyle
-            \eql at hook@innerright
-            \eql at class@innerright at sel
-            ##%
-            \eql at punct@apply at col
-            \eql at hook@colout
-          $%
-        }%
-        \eql at align@measure at field
-        \hfil
-      \crcr
-      \noalign{%
-        \eql at hook@blockbefore
-      }%
-      \eql at hook@blockin
-      \eql at scan@body
-%    \end{macrocode}
-%    \TODO test for vmode okay?!
-%    \begin{macrocode}
-      \ifvmode\else
-        \eql at punct@apply at block
-        \eql at hook@blockout
-        \eql at align@measure at line@end
-        \cr
-      \fi
-      \noalign{%
-        \eql at hook@blockafter
-      }%
-%    \end{macrocode}
-%    \TODO should we enforce even columns already here?!
-%    \TODO should we guard against no columns at all?!
-%    \begin{macrocode}
-      \eql at align@completerow\eql at totalcolumns@
-      \cr
-    }%
-    \global\advance\eql at row@-\tw@
-    \eql at numbering@measure at eval
-    \ifnum\eql at numbering@target@>\z@
-      \eql at tagbox@make\eql at compose@measure
-      \eql at tagwidth@savezero
-    \fi
-  }%
-  \eql at totalrows@\eql at row@
-  \ifdefined\eql at numbering@subeq at use
-    \eql at numbering@subeq at test
-  \fi
-  \eql at measure@restorecounters
-%  \eql at totalwidth@\wd\z@
-%    \end{macrocode}
-%
-%    \begin{macrocode}
-  \setbox\z@\vbox{%
-    \unvbox\z@
-    \unpenalty
-    \global\setbox\@ne\lastbox
-  }%
-%    \end{macrocode}
-%
-%    \begin{macrocode}
-% \TODO or this one?!
-  \eql at totalwidth@\wd\@ne
-%    \end{macrocode}
-%
-%    \TODO why not recycle box contents altogether?!
-%    \begin{macrocode}
-  \let\eql at colwidth@tab\@empty
-  \loop
-    \setbox\@ne\hbox{%
-      \unhbox\@ne
-      \unskip
-      \global\setbox\thr@@\lastbox
-    }%
-  \ifhbox\thr@@
-    \eql at align@colwidth at save
-  \repeat
-%<dev>\eql at dev@leave\eql at align@measure
-}
-%    \end{macrocode}
-%
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Adjust}
 %
 % \TODO describe
+% \TODO does this respect the margin for numbers in centre mode?
 %
-%   \TODO does this respect the margin for numbers in centre mode?
-%
 %    \begin{macrocode}
 \def\eql at align@adjust{%
 %    \end{macrocode}
@@ -6198,7 +6436,6 @@
 %
 %    \begin{macrocode}
   \eql at colsepmin@\glueexpr\eql at colsepmin@val\relax
-  \eql at colsepmax@\glueexpr\eql at colsepmax@val\relax
 %    \end{macrocode}
 %
 %    \TODO shouldn't we do this earlier for access to last column?
@@ -6215,6 +6452,7 @@
   \fi
 %    \end{macrocode}
 %
+% Determine the number of intercolumn spaces |\eql at align@inter@|:
 %    \begin{macrocode}
   \eql at align@inter@\eql at totalcolumns@
   \divide\eql at align@inter@\tw@
@@ -6222,10 +6460,25 @@
 %    \end{macrocode}
 %
 %    \begin{macrocode}
+  \ifdefined\eql at flushleft
+    \eql at flushleftmargin@\glueexpr\eql at flushleftmargin@val\relax
+  \else
+    \eql at adjust@tagmargin
+  \fi
+%    \end{macrocode}
+%
+%    \begin{macrocode}
   \eql at colsep@\displaywidth
   \advance\eql at colsep@-\eql at totalwidth@
   \ifdefined\eql at flushleft
     \advance\eql at colsep@-\eql at flushleftmargin@
+  \else
+    \advance\eql at colsep@-\eql at tagmargin@
+    \ifdefined\eql at align@margins\else
+      \ifdim\eql at tagmargin@>\z@
+        \advance\eql at colsep@-\eql at tagsepmin@
+      \fi
+    \fi
   \fi
   \count@\eql at align@inter@
   \ifdefined\eql at align@margins
@@ -6241,17 +6494,19 @@
 %    if there is a single column. nevertheless
 %     it works using the following code.
 %    yet it could be cleaner to treat a single column separately
-%    (may be some distinctions based on flushleft)
+%    (may be some distinctions based on flush left)
 %    \begin{macrocode}
   \ifdim\eql at colsep@<\eql at colsepmin@
     \eql at colsep@\eql at colsepmin@
   \else
-    \ifdim\eql at colsep@>\eql at colsepmax@
-      \eql at colsep@\eql at colsepmax@
+    \dimen@\glueexpr\eql at colsepmax@val\relax
+    \ifdim\eql at colsep@>\dimen@
+      \eql at colsep@\dimen@
     \fi
   \fi
 %    \end{macrocode}
-%
+% Now determine the left margin |\eql at marginleft@|
+% \TODO complete
 %    \begin{macrocode}
   \ifdefined\eql at flushleft
     \ifdim\eql at colsep@=\eql at colsepmin@
@@ -6274,19 +6529,30 @@
       \advance\eql at marginleft@-\eql at totalwidth@
       \advance\eql at marginleft@-\eql at align@inter@\eql at colsep@
       \ifdim\eql at marginleft@<\eql at tagmargin@
-        \ifdim\ifdefined\eql at tagsleft\eql at marginleft@\else-\p@\fi<\z@
-          \eql at marginleft@\z@
-        \fi
+        \eql at marginleft@\z@
       \else
         \advance\eql at marginleft@-\eql at tagmargin@
         \divide\eql at marginleft@\tw@
       \fi
+      \ifdefined\eql at tagsleft
+        \advance\eql at marginleft@\eql at tagmargin@
+      \fi
     \else
-      \eql at marginleft@\z@
+      \ifdefined\eql at tagsleft
+        \eql at marginleft@\eql at tagmargin@
+        \ifdim\eql at tagmargin@>\z@
+          \advance\eql at marginleft@\eql at tagsepmin@
+        \fi
+      \else
+        \eql at marginleft@\z@
+      \fi
     \fi
   \fi
 %    \end{macrocode}
-%
+% Loop through the rows
+% and adjust the intercolumn and margin space
+% to make the tags fit into the available space
+% at the corresponding side as far as possible:
 %    \begin{macrocode}
   \ifdefined\eql at tagsleft
     \let\eql at align@adjust at test\eql at align@adjust at test@tagleft
@@ -6293,7 +6559,14 @@
   \else
     \let\eql at align@adjust at test\eql at align@adjust at test@tagright
   \fi
+  \eql at row@\eql at totalrows@
   \loop\ifnum\eql at row@>\z@
+%    \end{macrocode}
+% Fetch the tag width for the current row depending on
+% whether there are tags for individual rows or one overall tag.
+% If a tag is present, compute the available space and try
+% to adjust spaces if needed:
+%    \begin{macrocode}
     \ifnum\eql at numbering@target@<\z@
       \eql at tagwidth@\eql at tagwidth@get\eql at row@\relax
     \else
@@ -6302,13 +6575,14 @@
       \fi
     \fi
     \ifdim\eql at tagwidth@>\z@
-      \eql at align@adjust at width
+      \eql at align@adjust at calc
       \eql at align@adjust at test
     \fi
     \advance\eql at row@\m at ne
   \repeat
 %    \end{macrocode}
-%
+% From now on |\eql at totalwidth@| will include
+% the left margin and the total intercolumn separation:
 %    \begin{macrocode}
   \advance\eql at totalwidth@\eql at align@inter@\eql at colsep@
   \advance\eql at totalwidth@\eql at marginleft@
@@ -6315,13 +6589,22 @@
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%    \paragraph{Calc Space.}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Calc Space.}
 %
-% \TODO describe
-%
+%   \macro{\eql at align@adjust at calc}
+% Compute the space that is available at the beginning and at the end
+% of a particular row |\eql at row@|.
+% The space available at the beginning is returned in |\eql at line@avail@|
+% and |\@tempcnta| counts the available intercolumn spaces
+% whose width is not contained in |\eql at line@avail@|
+% because it is still flexible at this stage.
+% The total used width is returned in |\eql at line@width@|
+% and |\@tempcntb| describes the last used intercolumn space.
+% The available space at the end of the row is given as the difference
+% to |\eql at totalwidth@| and |\eql at align@inter@|:
 %    \begin{macrocode}
-\def\eql at align@adjust at width{%
+\def\eql at align@adjust at calc{%
   \eql at line@pos@\z@
   \eql at column@\z@
   \eql at line@avail@\eql at totalwidth@
@@ -6330,7 +6613,7 @@
   \@tempcntb\z@
   \edef\@tempb{\eql at fieldlength@get\eql at row@}%
   \@for\@tempa:=\@tempb\do
-    \eql at align@adjust at width@col
+    \eql at align@adjust at calc@col
   \advance\@tempcnta\m at ne
   \divide\@tempcnta\tw@
   \advance\@tempcntb\m at ne
@@ -6338,9 +6621,13 @@
 }
 %    \end{macrocode}
 %
-% \TODO describe
+%   \macro{\eql at align@adjust at calc@col}
+% The macro |\eql at align@adjust at width@col| iterates over columns.
+% When a non-blank field is encountered,
+% the available space on the left will be fixed if it is still undetermined,
+% and the total width is updated to the current position:
 %    \begin{macrocode}
-\def\eql at align@adjust at width@col{%
+\def\eql at align@adjust at calc@col{%
   \advance\eql at column@\@ne
   \@tempdima\@tempa\relax
   \dimen@\eql at align@colwidth at get\eql at column@\relax
@@ -6364,152 +6651,191 @@
   \advance\eql at line@pos@\dimen@
 }
 %    \end{macrocode}
-
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%    \paragraph{Placement for right tags.}
 %
-% \TODO describe
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Placement for Right Tags.}
 %
-%   \macro{\eql at align@adjust at test@r}
+%   \macro{\eql at align@adjust at test@tagright}
+% Test whether the spacing can be adjusted to make the current row fit:
 %    \begin{macrocode}
 \def\eql at align@adjust at test@tagright{%
 %    \end{macrocode}
-%
+% The register |\@tempdima| will hold the amount of available space.
 %    \begin{macrocode}
-  \@tempdima\eql at line@width@
-  \advance\@tempdima\eql at tagwidth@
+  \@tempdima\displaywidth
+  \advance\@tempdima-\eql at line@width@
+  \advance\@tempdima-\eql at tagwidth@
 %    \end{macrocode}
-%
+% Test whether the space at the end of the row
+% is sufficient to hold the tag with the current settings.
 %    \begin{macrocode}
   \dimen@\eql at marginleft@
-  \advance\dimen@\@tempdima
   \advance\dimen@\@tempcntb\eql at colsep@
-  \ifdim\dimen@>\displaywidth
-    \eql at align@adjust at modify@tagright
+  \ifdim\dimen@>\@tempdima
+%    \end{macrocode}
+% If not, determine whether the row and tag may at all
+% fit into the available space with minimal intercolumn spaces
+% and minimal left margin (in left alignment layout).
+%    \begin{macrocode}
+    \dimen@\@tempcntb\eql at colsepmin@
+    \ifdefined\eql at flushleft
+      \advance\dimen@\eql at flushleftmarginmin@
+    \fi
+    \ifdim\dimen@>\@tempdima\else
+%    \end{macrocode}
+% If so, hand over to |\eql at align@adjust at modify@tagright|.
+%    \begin{macrocode}
+      \eql at align@adjust at modify@tagright
+    \fi
   \fi
 }
 %    \end{macrocode}
 %
-% \TODO describe
+%   \macro{\eql at align@adjust at modify@tagright}
+% Adjust the intercolumn space and left margin to make the row fit.
 %    \begin{macrocode}
 \def\eql at align@adjust at modify@tagright{%
-  \dimen@\eql at colsepmin@
-  \multiply\dimen@\@tempcntb
-  \advance\dimen@\@tempdima
-  \ifdefined\eql at flushleft
-    \advance\dimen@\eql at flushleftmarginmin@
-  \fi
-  \ifdim\dimen@>\displaywidth\else
 %    \end{macrocode}
-%
-%    \TODO check full length case?
-%    are the shifts sufficient in all possible cases?!
-%    is the left margin positive?!
+% If there are any intercolumn spaces that contribute to the available space,
+% determine how much intercolumn separation would be needed
+% while keeping the current left margin fixed (in left alignment layout).
+% In central alignment layout,
+% assume that the left margin will be adjusted
+% to match the intercolumn separation
+% by stepping the number of columns to divide by.
 %    \begin{macrocode}
-    \ifnum\@tempcntb>\z@
-      \dimen@\displaywidth
-      \advance\dimen at -\@tempdima
-      \count@\@tempcntb
-      \ifdefined\eql at flushleft
-        \advance\dimen at -\eql at marginleft@
-      \else
-        \ifdefined\eql at align@margins
-          \advance\count@\@ne
-        \fi
+  \ifnum\@tempcntb>\z@
+    \dimen@\@tempdima
+    \count@\@tempcntb
+    \ifdefined\eql at flushleft
+      \advance\dimen at -\eql at marginleft@
+    \else
+      \ifdefined\eql at align@margins
+        \advance\count@\@ne
       \fi
-      \divide\dimen@\count@
-      \ifdim\dimen@<\eql at colsep@
-        \ifdim\dimen@<\eql at colsepmin@
-          \dimen@\eql at colsepmin@
-        \fi
-        \eql at colsep@\dimen@
-      \fi
     \fi
+    \divide\dimen@\count@
 %    \end{macrocode}
-%
-%    \TODO could this possibly be less than the minimum margin?
-%      (we checked above, but under the assumption that
-%      |\eql at colsep@| is minimal!)
+% If smaller, reduce the intercolumn separation,
+% but make sure to not exceed the minumum allowed value.
 %    \begin{macrocode}
-    \dimen@\displaywidth
-    \advance\dimen at -\@tempdima
-    \advance\dimen at -\@tempcntb\eql at colsep@
-    \ifdim\dimen@<\eql at marginleft@
-      \eql at marginleft@\dimen@
+    \ifdim\dimen@<\eql at colsep@
+      \ifdim\dimen@<\eql at colsepmin@
+        \dimen@\eql at colsepmin@
+      \fi
+      \eql at colsep@\dimen@
     \fi
   \fi
+%    \end{macrocode}
+% Now adjust the left margin as much as needed
+% to fit the contents.
+%    \begin{macrocode}
+  \dimen@\@tempdima
+  \advance\dimen at -\@tempcntb\eql at colsep@
+  \ifdim\dimen@<\eql at marginleft@
+    \eql at marginleft@\dimen@
+  \fi
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%    \paragraph{Placement for left tags.}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Placement for Left Tags.}
 %
-% \TODO describe
-%
+%   \macro{\eql at align@adjust at test@tagleft}
+% Test whether the spacing can be adjusted to make the current row fit:
 %    \begin{macrocode}
 \def\eql at align@adjust at test@tagleft{%
+%    \end{macrocode}
+% The register |\@tempdima| will hold the deficit amount of space
+% at the beginning of the row without adjustable space,
+% and the register |\count@| will hold the number of
+% intercolumn spaces that would contribute to space adjustments.
+%    \begin{macrocode}
   \count@\eql at align@inter@
   \advance\count at -\@tempcnta
-  \@tempdima-\eql at line@avail@
-  \advance\@tempdima\eql at tagwidth@
+  \@tempdima\eql at tagwidth@
+  \advance\@tempdima-\eql at line@avail@
+%    \end{macrocode}
+% Test whether the space at the beginning of the row
+% is sufficient to hold the tag with the current settings.
+%    \begin{macrocode}
   \dimen@\eql at marginleft@
   \advance\dimen@\@tempcnta\eql at colsep@
   \ifdim\dimen@<\@tempdima
-    \eql at align@adjust at modify@tagleft
-  \fi
-}
 %    \end{macrocode}
-%
+% If not, first verify that the tag will fit the line
+% (or the maxumal left margin in left alignment layout).
 %    \begin{macrocode}
-\def\eql at align@adjust at modify@tagleft{%
+    \ifdefined\eql at flushleft
+      \dimen@\eql at flushleftmarginmax@
+    \else
+      \dimen@\displaywidth
+    \fi
+    \ifdim\dimen@>\eql at tagwidth@
 %    \end{macrocode}
-%    \TODO implement a maximum shift (if tag+sep exceeds max, don't adjust)
-%    \TODO could this mechanism possibly shift any longer line past the margin?!
+% If so, determine whether the row and tag may at all
+% fit into the available space with minimal intercolumn spaces.
 %    \begin{macrocode}
-  \ifdefined\eql at flushleft
-    \dimen@\eql at flushleftmarginmax@
-  \else
-    \dimen@\displaywidth
+      \dimen@\count@\eql at colsepmin@
+      \advance\dimen@\eql at totalwidth@
+      \advance\dimen@\@tempdima
+      \ifdim\dimen@>\displaywidth\else
+%    \end{macrocode}
+% If so, hand over to |\eql at align@adjust at modify@tagleft|.
+%    \begin{macrocode}
+        \eql at align@adjust at modify@tagleft
+      \fi
+    \fi
   \fi
-  \ifdim\dimen@>\eql at tagwidth@
+}
 %    \end{macrocode}
 %
+% \TODO implement a maximum shift (if tag+sep exceeds max, don't adjust)
+% \TODO could this mechanism possibly shift any longer line past the margin?!
+%   \macro{\eql at align@adjust at modify@tagleft}
+% Adjust the intercolumn space and left margin to make the row fit.
 %    \begin{macrocode}
-    \dimen@\eql at colsepmin@
-    \multiply\dimen@\count@
-    \advance\dimen@\eql at totalwidth@
-    \advance\dimen@\@tempdima
-    \ifdim\dimen@>\displaywidth\else
+\def\eql at align@adjust at modify@tagleft{%
 %    \end{macrocode}
-%
+% If there are any intercolumn spaces that contribute to the available space,
+% determine how much intercolumn separation would be needed
+% while keeping the current right margin fixed.
+% In central alignment layout,
+% assume that the right margin will be adjusted
+% to match the intercolumn separation
+% by stepping the number of columns to divide by.
 %    \begin{macrocode}
-      \ifnum\count@>0
-        \dimen@\displaywidth
-        \advance\dimen at -\eql at totalwidth@
-        \advance\dimen at -\@tempdima
-        \ifdefined\eql at align@margins
-          \advance\count@\@ne
-        \fi
-        \divide\dimen@\count@
-        \ifdim\dimen@<\eql at colsep@
-          \ifdim\dimen@<\eql at colsepmin@
-            \dimen@\eql at colsepmin@
-          \fi
-          \advance\dimen at -\eql at colsep@
-          \advance\eql at marginleft@-\eql at align@inter@\dimen@
-          \advance\eql at colsep@\dimen@
-        \fi
-      \fi
+  \ifnum\count@>\z@
+    \dimen@\displaywidth
+    \advance\dimen at -\eql at totalwidth@
+    \advance\dimen at -\@tempdima
+    \ifdefined\eql at align@margins
+      \advance\count@\@ne
+    \fi
+    \divide\dimen@\count@
 %    \end{macrocode}
-%
+% If smaller, reduce the intercolumn separation,
+% but make sure to not exceed the minumum allowed value.
+% Also adjust the left margin to keep the right margin fixed.
 %    \begin{macrocode}
-      \dimen at -\@tempcnta\eql at colsep@
-      \advance\dimen@\@tempdima
-      \ifdim\dimen@>\eql at marginleft@
-        \eql at marginleft@\dimen@
+    \ifdim\dimen@<\eql at colsep@
+      \ifdim\dimen@<\eql at colsepmin@
+        \dimen@\eql at colsepmin@
       \fi
+      \advance\dimen at -\eql at colsep@
+      \advance\eql at marginleft@-\eql at align@inter@\dimen@
+      \advance\eql at colsep@\dimen@
     \fi
   \fi
+%    \end{macrocode}
+% Now adjust the left margin as much as needed
+% to fit the contents.
+%    \begin{macrocode}
+  \dimen at -\@tempcnta\eql at colsep@
+  \advance\dimen@\@tempdima
+  \ifdim\dimen@>\eql at marginleft@
+    \eql at marginleft@\dimen@
+  \fi
 }
 %    \end{macrocode}
 %
@@ -6519,7 +6845,7 @@
 % \section{Interface}
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Scanning the Environment's Body}
+% \subsection{Scanning the Equation Body}
 %
 % The multi-line equatiuon environment must scan its body twice:
 % once to determine how wide the columns are and then to actually
@@ -6527,13 +6853,25 @@
 % before calling the environment macros.
 % The mechanism and its description follows \ctanpkg{amsmath} closely.
 %
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Token Register.}
+%
 %   \macro{\eql at scan@reg@}
-% We start by defining a token register to contain the body.
+% We start by defining a token register to hold the equation body.
 %    \begin{macrocode}
 \newtoks\eql at scan@reg@
 %    \end{macrocode}
 %
-% \TODO describe
+%   \macro{\eql at scan@body at dump}
+%   \macro{\eql at scan@body at rescan}
+%   \macro{\eql at scan@body}
+% The macro |\eql at scan@body at dump| dumps the equation body
+% from the register so that we do not have to pass it
+% around in arguments. The macro |\eql at scan@body at rescan|
+% rescans the tokens so that special commands
+% such as |\verb| can be processed properly.
+% The register |\eql at scan@body|
+% holds the currently selected mode of operation:
 %    \begin{macrocode}
 \def\eql at scan@body at dump{\the\eql at scan@reg@}
 \def\eql at scan@body at rescan{%
@@ -6542,17 +6880,22 @@
 %    \end{macrocode}
 %
 %   \macro{\eql at scan@addto}
-% Then we define a macro to add something (i.e.\ its argument) to the
-% token register |\@envbody|:
+% We define a macro to append to the token register |\eql at scan@reg@|:
 %    \begin{macrocode}
-\def\eql at scan@addto#1{\eql at scan@reg@\expandafter{\the\eql at scan@reg@#1}}
+\long\def\eql at scan@addto#1{\eql at scan@reg@\expandafter{\the\eql at scan@reg@#1}}
 %    \end{macrocode}
 %
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Environment Body.}
+%
+% The following mechanism scans the contents of an environment
+% taking into account nested environments
+% that may be contained in the body.
+%
 %   \macro{\eql at scan@env}
 % The macro |\eql at scan@env| starts the scan for the |\end{...}|
-% command of the current environment. It takes a macro name as
-% argument. This macro is supposed to take the whole body of the
-% environment as its argument:
+% command of the current environment. The argument is a call-back macro
+% to process the body in |\eql at scan@reg@|:
 %    \begin{macrocode}
 \def\eql at scan@env#1{%
 %<dev>\eql at dev@enter\eql at scan@env
@@ -6559,13 +6902,15 @@
   \def\eql at scan@end{#1\expandafter\end\expandafter{\@currenvir}}%
   \eql at scan@reg@{}\def\eql at scan@stack{b}%
 %    \end{macrocode}
+% We call |\eql at scan@env at iterate| which will scan until
+% the next occurrence of |\end| and then count the number
+% of occurrences of |\begin| before |\end| in |\eql at scan@stack|.
 % If we simply called |\eql at scan@env at iterate| directly,
-% the error message for a |\par| token (usually from a blank line)
+% the error message for an unwanted |\par| token (usually from a blank line)
 % would refer to |\eql at scan@env at iterate| which would not be illuminating.
 % We use a little finesse to get a more intelligible error message:
-% We use the actual
-% environment name as the name of the temporary function that is
-% |\let| to |\eql at scan@env at iterate|:
+% We use the actual environment name as the name of the temporary function
+% that is |\let| to |\eql at scan@env at iterate|:
 %    \begin{macrocode}
   \edef\eql at scan@iterate{\expandafter\noexpand\csname\@currenvir\endcsname}%
   \expandafter\let\expandafter\eql at scan@env at org\eql at scan@iterate
@@ -6574,22 +6919,13 @@
 }
 %    \end{macrocode}
 %
-%   \macro{\eql at scan@env at count}
-% When adding a piece of the current environment's contents to
-% |\eql at scan@reg@|, we scan it to check for additional |\begin|
-% tokens, and add a `b' to the stack for any that we find.
-%    \begin{macrocode}
-\def\eql at scan@env at count#1\begin#2{%
-  \ifx\end#2\else b\expandafter\eql at scan@env at count\fi
-}
-%    \end{macrocode}
-%
 %   \macro{\eql at scan@env at iterate}
 % |\eql at scan@env at iterate| takes two arguments: the first will consist of
 % all text up to the next |\end| command, the second will be the
 % |\end| command's argument. If there are any extra |\begin|
-% commands in the body text, a marker is pushed onto a stack by the
-% |\push at begins| function. Empty state for this stack means that we
+% commands in the body text, a marker is pushed onto a stack
+% via |\eql at scan@env at count|.
+% An empty state for this stack means that we
 % have reached the |\end| that matches our original |\begin|.
 % Otherwise we need to include the |\end| and its argument in the
 % material that we are adding to our environment body accumulator:
@@ -6610,18 +6946,34 @@
 }
 %    \end{macrocode}
 %
-% \TODO describe
+%   \macro{\eql at scan@env at count}
+% When adding a piece of the current environment's contents to
+% |\eql at scan@reg@|, we scan it to check for additional |\begin|
+% tokens, and add a `b' to the stack for any that we find.
 %    \begin{macrocode}
+\long\def\eql at scan@env at count#1\begin#2{%
+  \ifx\end#2\else b\expandafter\eql at scan@env at count\fi
+}
+%    \end{macrocode}
+%
+% The call-back macro |\eql at scan@env at cancel| ignores the body
+% as well as the end clause for the environment:
+%    \begin{macrocode}
 \def\eql at scan@env at cancel{%
   \@namedef{end\@currenvir}{\ignorespacesafterend}%
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \paragraph{square brackets}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Square Brackets.}
 %
-% \TODO describe
+% The following is a version of the above mechanism
+% that scans for an equation body enclosed by |\[...\]|
+% paying attention to potential further instances of the square bracket
+% enclosures contained in the body.
 %
+%   \macro{\eql at scan@sqr}
+% Start scanning for |\]|:
 %    \begin{macrocode}
 \def\eql at scan@sqr#1{%
 %<dev>\eql at dev@enter\eql at scan@sqr
@@ -6633,15 +6985,9 @@
 }
 %    \end{macrocode}
 %
-% \TODO describe
+% Iterate until we find a balanced pairing of square brackets.
+% Then call the call-back macro:
 %    \begin{macrocode}
-\def\eql at scan@sqr at count#1\[#2{%\]
-  \ifx\]#2\else b\expandafter\eql at scan@sqr at count\fi
-}
-%    \end{macrocode}
-%
-% \TODO describe
-%    \begin{macrocode}
 \def\eql at scan@sqr at iterate#1\]{%
   \edef\eql at scan@stack{%
     \eql at scan@sqr at count#1\[\]\expandafter\@gobble\eql at scan@stack}%
@@ -6657,15 +7003,27 @@
 }
 %    \end{macrocode}
 %
+% Push a `b' for every encountered instance of `|\[|':
 %    \begin{macrocode}
+\long\def\eql at scan@sqr at count#1\[#2{%\]
+  \ifx\]#2\else b\expandafter\eql at scan@sqr at count\fi
+}
+%    \end{macrocode}
+%
+% The call-back macro |\eql at scan@sqrang at cancel| ignores the body
+% and the closing bracket:
+%    \begin{macrocode}
 \def\eql at scan@sqrang at cancel{\expandafter\ignorespaces\@gobble}
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \paragraph{anuglar brackets}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Angle Brackets.}
 %
-% \TODO describe
+% The following is another version of the mechanism
+% which scans for an equation body enclosed by |\<...\>|.
 %
+%   \macro{\eql at scan@ang}
+% Start scanning for |\>|:
 %    \begin{macrocode}
 \def\eql at scan@ang#1{%
 %<dev>\eql at dev@enter\eql at scan@ang
@@ -6677,15 +7035,8 @@
 }
 %    \end{macrocode}
 %
-% \TODO describe
+% Iterate until we find a balanced pairing of angle brackets:
 %    \begin{macrocode}
-\def\eql at scan@ang at count#1\<#2{%\>
-  \ifx\>#2\else b\expandafter\eql at scan@ang at count\fi
-}
-%    \end{macrocode}
-%
-% \TODO describe
-%    \begin{macrocode}
 \def\eql at scan@ang at iterate#1\>{%
   \edef\eql at scan@stack{%
     \eql at scan@ang at count#1\<\>\expandafter\@gobble\eql at scan@stack}%
@@ -6701,9 +7052,24 @@
 }
 %    \end{macrocode}
 %
+% Push a `b' for every encountered instance of `|\<|':
+%    \begin{macrocode}
+\long\def\eql at scan@ang at count#1\<#2{%\>
+  \ifx\>#2\else b\expandafter\eql at scan@ang at count\fi
+}
+%    \end{macrocode}
+%
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Options Processing}
 %
+%   \macro{\eql at equations@testall}
+% The macro sequence started by |\eql at equations@testall|
+% scans for optional arguments to the equation environments
+% and appends them to the argument list using |\eqnaddopt|.
+% The argument scheme is roughly |{ !t~ !t* !t! !o !e{@} }|.
+% All arguments are scanned such that any spaces
+% stop the scanning and such that any alignment markers `|&|'
+% cannot interfere:
 %    \begin{macrocode}
 \def\eql at equations@testall{\eql at equations@testtilde}
 \def\eql at equations@testtilde#1{%
@@ -6728,6 +7094,17 @@
     {\eql at equations@addlabel{#1}}%
     {#1}}
 \def\eql at equations@addlabel#1#2{\eqnaddopt{label={#2}}#1}
+%    \end{macrocode}
+%
+%   \macro{\eql at equations@processopt}
+% The macro |\eql at equations@processopt| processes the options
+% recevied by |\eqnaddopt|.
+% First, clear several non-persistent registers
+% (labels, tags, direct vertical spacing).
+% Then process the arguments.
+% Finally evaluate |\eql at indent@val| and |\eql at tagsepmin@val|
+% and prevent main punctuation from being passed to nested environments:
+%    \begin{macrocode}
 \def\eql at equations@processopt{%
   \let\eql at blocklabel\@undefined
   \let\eql at blocktag\@undefined
@@ -6741,13 +7118,23 @@
   \let\eql at punct@block\eql at punct@main
   \let\eql at punct@main\relax
   \eql at indent@\glueexpr\eql at indent@val\relax
+  \eql at tagsepmin@\glueexpr\eql at tagsepmin@val\relax
 }
 %    \end{macrocode}
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \subsection{Environments}
+% \subsection{Equations Environment}
 %
-%  \environment{equations}
+% We now declare the main environment and its symbolic versions.
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Environment.}
+%
+%   \environment{equations}
+% Declare the main equations environment.
+% If already in math mode, fail and cancel the environment body.
+% Otherwise scan for optional arguments
+% and pass on to |\eql at equations@start|:
 %    \begin{macrocode}
 \newenvironment{equations}{%
 %<dev>\eql at dev@enterenv
@@ -6765,6 +7152,11 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at equations@start}
+% The macro |\eql at equations@start| first processes the arguments.
+% Depending on the chosen mode of operation,
+% scan the environment body passing on to |\eql at equations@main|
+% or process a single-line equation via |\eql at single@start|:
 %    \begin{macrocode}
 \def\eql at equations@start{%
   \eql at equations@processopt
@@ -6776,12 +7168,23 @@
 }
 %    \end{macrocode}
 %
-% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \paragraph{square and angle brackets}
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Square Brackets.}
 %
+%   \environment{equations at sqr}
+% Define a pseudo-environment |equations at sqr|
+% such that |\@currenvir| may point to it when needed:
 %    \begin{macrocode}
 \newenvironment{equations at sqr}{}{}
-\def\eql at equations@sqr at opt{equation,nonumber}
+%    \end{macrocode}
+%
+%   \macro{\eql at equations@sqr at open}
+% The macro |\eql at equations@sqr at open| holds the definition for `|\[|'.
+% If already in math mode, ignore the enclosed contents.
+% Otherwise add the default arguments |\eql at equations@sqr at opt|,
+% enter the pseudo-environment, scan for optional arguments,
+% and pass on to |\eql at equations@sqr at start|:
+%    \begin{macrocode}
 \protected\def\eql at equations@sqr at open{%
   \ifmmode
     \eql at error@mathmode{\string\[...\string\]}%
@@ -6796,9 +7199,44 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at equations@sqr at start}
+% Process arguments. Depending on mode of operation,
+% scan and process enclosed contents via |\eql at equations@main|
+% or pass on to |\eql at single@start|:
 %    \begin{macrocode}
+\def\eql at equations@sqr at start{%
+  \eql at equations@processopt
+  \ifdefined\eql at equations@main
+    \expandafter\eql at scan@sqr\expandafter\eql at equations@main
+  \else
+    \expandafter\eql at single@start
+  \fi
+}
+%    \end{macrocode}
+%
+%   \macro{\eql at equations@sqr at close}
+% The macro |\eql at equations@sqr at close| holds the definition for `|\]|'.
+%    \begin{macrocode}
+\protected\def\eql at equations@sqr at close{%
+  \eql at equations@end
+%<dev>\eql at dev@leave{\[...\string\]}%
+  \end{equations at sqr}%
+  \ignorespaces
+}
+%    \end{macrocode}
+%
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% \paragraph{Angle Brackets.}
+%
+%   \environment{equations at ang}
+% Define a pseudo-environment |equations at ang|:
+%    \begin{macrocode}
 \newenvironment{equations at ang}{}{}
-\def\eql at equations@ang at opt{align,nonumber}
+%    \end{macrocode}
+%
+%   \macro{\eql at equations@ang at open}
+% The macro |\eql at equations@ang at open| holds the definition for `|\<|'.
+%    \begin{macrocode}
 \protected\def\eql at equations@ang at open{%
   \ifmmode
     \eql at error@mathmode{\string\<...\string\>}%
@@ -6813,18 +7251,9 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at equations@ang at start}
+% Process arguments and start handling the equation:
 %    \begin{macrocode}
-\def\eql at equations@sqr at start{%
-  \eql at equations@processopt
-  \ifdefined\eql at equations@main
-    \expandafter\eql at scan@sqr\expandafter\eql at equations@main
-  \else
-    \expandafter\eql at single@start
-  \fi
-}
-%    \end{macrocode}
-%
-%    \begin{macrocode}
 \def\eql at equations@ang at start{%
   \eql at equations@processopt
   \ifdefined\eql at equations@main
@@ -6835,16 +7264,9 @@
 }
 %    \end{macrocode}
 %
+%   \macro{\eql at equations@ang at close}
+% The macro |\eql at equations@ang at close| holds the definition for `|\>|'.
 %    \begin{macrocode}
-\protected\def\eql at equations@sqr at close{%
-  \eql at equations@end
-%<dev>\eql at dev@leave{\[...\string\]}%
-  \end{equations at sqr}%
-  \ignorespaces
-}
-%    \end{macrocode}
-%
-%    \begin{macrocode}
 \protected\def\eql at equations@ang at close{%
   \eql at equations@end
 %<dev>\eql at dev@leave{\<...\string\>}%
@@ -6860,7 +7282,6 @@
 % \ctanpkg{amsmath} defines the macro |\eqref|
 % to refer to equation labels in a proper format
 % We provide it for completeness:
-% \TODO versions of eqref for ranges (optional argument) or lists (,)?
 %    \begin{macrocode}
 \DeclareRobustCommand{\eql at eqref}[1]{\textup{\eql at tag@boxedform{\ref{#1}}}}
 %    \end{macrocode}
@@ -6940,11 +7361,11 @@
 % which are used only towards error messages.
 % Argument |#3| contains the value and argument |#4|
 % is a list of values and corresponding actions in the format
-% $$
+% \[
 % |{{{|\textit{val1a}|,|\textit{val1b}|,|\ldots|}{|\textit{act1}|},|
 % |{{|\textit{val2a}|,|\textit{val2b}|,|\ldots|}{|\textit{act2}|},|
 % \ldots|}|.
-% $$
+% \]
 % If no corresponding value is found in the list,
 % an error message is invoked.
 % Single expansion is applied to the list of values:
@@ -7063,11 +7484,16 @@
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % \subsection{Parameter Sets}
 %
-% \TODO: par at above plus parskip?
+% \TODO par at above plus parskip?
 %    \begin{macrocode}
 \def\eql at defaults@classic{%
+  \def\eql at tagsepmin@val{.5\fontdimen6\textfont\tw@}%
   \def\eql at colsepmax@val{.5\maxdimen}%
   \def\eql at spread{\jot}%
+  \let\eql at tagmargin@val\@undefined
+  \eql at tagmargin@ratio@\p@
+  \def\eql at tagmargin@threshold{0.5}%
+  \def\eql at flushleftmargin@val{\leftmargini}%
   \let\eql at display@height\@undefined
   \let\eql at display@depth\@undefined
   \eql at skip@mode at short@\tw@
@@ -7096,8 +7522,13 @@
 % values based on 10pt vs 12pt
 %    \begin{macrocode}
 \def\eql at defaults@eqnlines{%
+  \def\eql at tagsepmin@val{.5em}%
   \def\eql at colsepmax@val{2em}%
   \def\eql at spread{0.2\normalbaselineskip}%
+  \let\eql at tagmargin@val\@undefined
+  \eql at tagmargin@ratio at .334\p@
+  \def\eql at tagmargin@threshold{0.5}%
+  \def\eql at flushleftmargin@val{\leftmargini}%
   \def\eql at display@height{\ht\eql at strutbox@}%
   \def\eql at display@depth{\dp\eql at strutbox@}%
   \eql at skip@mode at short@\@ne
@@ -7108,11 +7539,11 @@
     \@plus0.25\normalbaselineskip\@minus0.4\normalbaselineskip}%
   \let\eql at skip@long at below\eql at skip@long at above
   \def\eql at skip@short at above{0.0\normalbaselineskip
-    \@plus0.2\normalbaselineskip}%
+    \@plus0.25\normalbaselineskip}%
   \def\eql at skip@short at below{0.0\normalbaselineskip
     \@plus0.25\normalbaselineskip}%
-  \def\eql at skip@med at above{0.375\normalbaselineskip
-    \@plus0.225\normalbaselineskip\@minus0.2\normalbaselineskip}%
+  \def\eql at skip@med at above{0.4\normalbaselineskip
+    \@plus0.2\normalbaselineskip\@minus0.2\normalbaselineskip}%
   \let\eql at skip@med at below\eql at skip@med at above
   \def\eql at skip@cont at above{\z at skip}%
   \def\eql at skip@cont at below{\eql at skip@long at below}%
@@ -7388,10 +7819,17 @@
 % \TODO describe
 %    \begin{macrocode}
 \def\eql at keycat{equations,setup}
-\eql at define@key\eql at keycat{tagmargin}{\eql at tagmargin@\glueexpr#1\relax}
-\eql at define@key\eql at keycat{tagmargin*}{\settowidth\eql at tagmargin@{#1}}
-\eql at define@key\eql at keycat{mintagsep}{\eql at tagsepmin@\glueexpr#1\relax}
-\eql at define@key\eql at keycat{mintagwidth}{\eql at tagwidthmin@\glueexpr#1\relax}
+\eql at define@key\eql at keycat{tagmargin}{\def\eql at tagmargin@val{#1}}
+\eql at define@key\eql at keycat{tagmargin*}{%
+  \settowidth\dimen@{#1}\edef\eql at tagmargin@val{\the\dimen@}}
+\eql at define@key\eql at keycat{tagmargincalc}[]{\let\eql at tagmargin@val\@undefined}
+\eql at define@key\eql at keycat{tagmarginratio}{%
+  \eql at tagmargin@ratio@\dimexpr#1pt\relax}
+\eql at define@key\eql at keycat{tagmarginthreshold}{%
+  \def\eql at tagmargin@threshold{#1}}
+\eql at define@key\eql at keycat{mintagsep}{\def\eql at tagsepmin@val{#1}}
+\eql at define@key\eql at keycat{mintagwidth}{%
+  \settowidth\dimen@{#1}\edef\eql at tagsepmin@val{\the\dimen@}}
 \eql at define@key\eql at keycat{mintagwidth*}{\settowidth\eql at tagwidthmin@{#1}}
 %    \end{macrocode}
 %
@@ -7442,8 +7880,9 @@
   {{left,l}{\let\eql at flushleft\eql at true}}}}
 \eql at define@key\eql at keycat{center}[]{\let\eql at flushleft\eql at false}
 \eql at define@key\eql at keycat{flushleft,left}[]{\let\eql at flushleft\eql at true}
-\eql at define@key\eql at keycat{leftmargin}{%
-  \eql at flushleftmargin@\glueexpr#1\relax}
+\eql at define@key\eql at keycat{leftmargin}{\def\eql at flushleftmargin@val{#1}}
+\eql at define@key\eql at keycat{leftmargin*}{%
+  \settowidth\dimen@{#1}\edef\eql at flushleftmargin@val{\the\dimen@}}
 \eql at define@key\eql at keycat{minleftmargin}{%
   \eql at flushleftmarginmin@\glueexpr#1\relax}
 \eql at define@key\eql at keycat{maxleftmargin}{%
@@ -7936,6 +8375,12 @@
 \let\eql at error@packageoption\@gobble
 %    \end{macrocode}
 %
+% Declare math layout options |leqno| and |fleqn| for common \LaTeX{} classes:
+%    \begin{macrocode}
+\DeclareOption{leqno}{\eqnlinesset{tagsleft}}
+\DeclareOption{fleqn}{\eqnlinesset{left}}
+%    \end{macrocode}
+%
 % Pass undeclared options on to \ctanpkg{keyval} processing:
 %    \begin{macrocode}
 \DeclareOption*{\expandafter\eqnlinesset\expandafter{\CurrentOption}}
@@ -7947,7 +8392,7 @@
 %    \end{macrocode}
 %
 %   \macro{\eql at error@packageoption}
-% Enable error message for explusive package options:
+% Enable error message for exclusive package options:
 %    \begin{macrocode}
 \def\eql at error@packageoption#1{%
   \eql at error{may only use `#1' as a package option}%
@@ -7954,7 +8399,10 @@
 }
 %    \end{macrocode}
 %
-% Provide classes of interfaces:
+% Make sure that the \ctanpkg{amsmath} conditionals
+% |\iftagsleft@| and |\if at fleqn| are declared
+% without spelling out their name
+% which may upset the \TeX{} conditional parsing mechanism:
 %    \begin{macrocode}
 \ifdefined\tagsleft at true\else
   \expandafter\newif\csname iftagsleft@\endcsname
@@ -7962,6 +8410,11 @@
 \ifdefined\@fleqntrue\else
   \expandafter\newif\csname if at fleqn\endcsname
 \fi
+%    \end{macrocode}
+%
+% Import \ctanpkg{amsmath} switches |leqno| as |tagsleft|
+% and |fleqn| as |left|:
+%    \begin{macrocode}
 \ifdefined\eql at provide@opt at amsmath
   \let\eql at provide@opt at equation\eql at true
   \eql at amsmath@after{%
@@ -7979,17 +8432,19 @@
 \fi
 %    \end{macrocode}
 %
-% \TODO describe
+% Provide native \LaTeX{} environment |equation|
+% and symbolic shortcut |\[...\]| if desired:
 %    \begin{macrocode}
 \ifdefined\eql at provide@opt at equation\eqnlinesprovide{equation,sqr}\fi
 %    \end{macrocode}
 %
-% \TODO describe
+% Make the ending statements for \ctanpkg{amsmath} environments independent
+% if desired, so that they may be overwritten individually:
 %    \begin{macrocode}
 \ifdefined\eql at provide@opt at amsmathends\eql at amsmath@fixends\fi
 %    \end{macrocode}
 %
-% \TODO describe
+% Provide \ctanpkg{amsmath} equation environments if desired:
 %    \begin{macrocode}
 \ifdefined\eql at provide@opt at amsmath
   \eqnlinesprovide{%
@@ -7999,12 +8454,12 @@
 \fi
 %    \end{macrocode}
 %
-% \TODO describe
+% Provide symbolic shortcut |\<...\>| if desired:
 %    \begin{macrocode}
 \ifdefined\eql at provide@opt at ang\eqnlinesprovide{ang}\fi
 %    \end{macrocode}
 %
-% \TODO describe
+% Provide equation reference |\eqref| if desired:
 %    \begin{macrocode}
 \ifdefined\eql at provide@opt at eqref\eqnlinesprovide{eqref}\fi
 %    \end{macrocode}

Modified: trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.ins	2025-03-28 21:33:02 UTC (rev 74777)
+++ trunk/Master/texmf-dist/source/latex/eqnlines/eqnlines.ins	2025-03-28 21:33:10 UTC (rev 74778)
@@ -20,7 +20,6 @@
 
 \endpreamble
 
-% the style and sample files
 \generate{\askforoverwritefalse
 \file{eqnlines.sty}{\from{eqnlines.dtx}{package}}
 \file{eqnlines-dev.sty}{\from{eqnlines.dtx}{package,dev}}

Modified: trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines-dev.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines-dev.sty	2025-03-28 21:33:02 UTC (rev 74777)
+++ trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines-dev.sty	2025-03-28 21:33:10 UTC (rev 74778)
@@ -21,7 +21,7 @@
 %% version 2008 or later.
 %% 
 \NeedsTeXFormat{LaTeX2e}[2020/10/01]
-\ProvidesPackage{eqnlines-dev}[2025/03/11 v0.6 Single- and multi-line equations (development)]
+\ProvidesPackage{eqnlines-dev}[2025/03/27 v0.6.1 Single- and multi-line equations (development)]
 \def\eql at dev#1{\PackageInfo{eqnlines-dev}{#1}}
 \def\eql at dev@start#1{\eql at dev{starting \string#1}}
 \def\eql at dev@enter#1{\eql at dev{entering \string#1}}
@@ -29,6 +29,15 @@
 \def\eql at dev@enterenv{\eql at dev{entering \@currenvir}}
 \def\eql at dev@leaveenv{\eql at dev{ leaving \@currenvir}}
 \def\eql at dev@in#1#2{\eql at dev{ \space within \string#1 #2}}
+\let\eql at false\@undefined
+\let\eql at true\@empty
+\ifdefined\dollardollar at begin
+  \def\eql at dollardollar@begin{\dollardollar at begin}
+  \def\eql at dollardollar@end{\dollardollar at end}
+\else
+  \def\eql at dollardollar@begin{$$}
+  \def\eql at dollardollar@end{$$}
+\fi
 \let\eql at ifnextchar@loose\kernel at ifnextchar
 \long\def\eql at ifnextchar@tight#1#2#3{%
   \let\reserved at d= #1%
@@ -110,28 +119,81 @@
   \@ifpackageloaded{amsmath}{}{\AddToHook{package/amsmath/before}{#1}}}
 \def\eql at amsmath@undefine#1{\eql at amsmath@before{\let#1\@undefined}}
 \def\eql at amsmath@let#1#2{\eql at amsmath@undefine#1\let#1#2}
-\let\eql at false\@undefined
-\let\eql at true\@empty
-\newskip\eql at regunset@
-\eql at regunset@-1sp\relax
-\def\eql at regsetdelayed#1#2{%
-  #1\eql at regunset@\relax
-  \AtBeginDocument{%
-    \ifdim#1=\eql at regunset@
-      #1\glueexpr#2\relax
-    \fi
-  }%
-}
+\let\eql at tagging@on\eql at false
+\IfFormatAtLeastTF{2025-06-01}{%
+  \csname tag_if_active:T\endcsname{\let\eql at tagging@on\eql at true}}{}
+\ifdefined\eql at tagging@on
+  \def\eql at tagging@mathsave{%
+    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
+  \def\eql at tagging@mathaddlast{%
+    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
+  \def\eql at tagging@tagbegin{%
+    \UseTaggingSocket{math/display/tag/begin}}
+  \def\eql at tagging@tagend{%
+    \UseTaggingSocket{math/display/tag/end}}
+  \def\eql at tagging@tagsave{%
+    \UseTaggingSocket{math/luamml/mtable/tag/save}}
+  \def\eql at tagging@tagaddbox{%
+    \setbox\z@\copy\eql at tagbox@%
+    \UseTaggingSocket{math/luamml/mtable/tag/set}}
+  \def\eql at tagging@tablesaveinner{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
+  \def\eql at tagging@tableaddinner{%
+    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
+  \def\eql at tagging@tablesavelines{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
+  \def\eql at tagging@tablesavealign{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
+  \def\eql at tagging@alignleft{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
+  \def\eql at tagging@aligncenter{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
+  \def\eql at tagging@alignright{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
+  \let\eql at single@doscan\eql at true
+  \let\eql at scan@body\eql at scan@body at rescan
+  \ExplSyntaxOn
+  \def\eql at tagging@start{%
+    \bool_if:NF\l__math_collected_bool{%
+      \toks@\expandafter{\eql at tagging@opt}%
+      \edef\eql at tmp{{\@currenvir}{[\the\toks@] \the\eql at scan@reg@}}%
+      \expandafter\__math_process:nn\eql at tmp
+      \@kernel at math@registered at begin
+      \bool_set_true:N\l__math_collected_bool
+    }%
+  }
+  \def\eql at tagging@end{}
+  \ExplSyntaxOff
+\else
+  \def\eql at tagging@mathsave{}
+  \def\eql at tagging@mathaddlast{}
+  \def\eql at tagging@tagbegin{}
+  \def\eql at tagging@tagend{}
+  \def\eql at tagging@tagsave{}
+  \def\eql at tagging@tagaddbox{}
+  \def\eql at tagging@tablesaveinner{}
+  \def\eql at tagging@tableaddinner{}
+  \def\eql at tagging@tablesavelines{}
+  \def\eql at tagging@tablesavealign{}
+  \def\eql at tagging@alignleft{}
+  \def\eql at tagging@aligncenter{}
+  \def\eql at tagging@alignright{}
+  \def\eql at tagging@start{}
+  \def\eql at tagging@end{}
+\fi
 \let\eql at tagsleft\eql at false
 \let\eql at flushleft\eql at false
 \newdimen\eql at flushleftmargin@
 \newdimen\eql at flushleftmarginmin@
 \newdimen\eql at flushleftmarginmax@
-\eql at regsetdelayed\eql at flushleftmargin@\leftmargini
+\def\eql at flushleftmargin@val{\leftmargini}
 \eql at flushleftmarginmin@\z@
 \eql at flushleftmarginmax@.5\maxdimen
 \newdimen\eql at tagmargin@
-\eql at tagmargin@\z@
+\let\eql at tagmargin@val\@undefined
+\newdimen\eql at tagmargin@ratio@
+\eql at tagmargin@ratio@\p@
+\def\eql at tagmargin@threshold{0.5}
 \newdimen\eql at indent@
 \def\eql at indent@val{2em}
 \newdimen\eql at paddingleft@
@@ -183,16 +245,33 @@
 \def\eql at skip@medtag at above{\z at skip}
 \def\eql at skip@medtag at below{\z at skip}
 \newdimen\eql at colsepmin@
-\newdimen\eql at colsepmax@
 \def\eql at colsepmin@val{1em}
 \def\eql at colsepmax@val{.5\maxdimen}
 \newdimen\eql at tagwidthmin@
 \eql at tagwidthmin@\z@
 \newdimen\eql at tagsepmin@
-\eql at regsetdelayed\eql at tagsepmin@{.5em}
+\def\eql at tagsepmin@val{.5\fontdimen6\textfont\tw@}
+\def\eql at equations@sqr at opt{equation,nonumber}
+\def\eql at equations@ang at opt{align,nonumber}
+\let\eql at align@margins\eql at true
+\newbox\eql at fieldbox@
+\newbox\eql at tagbox@
+\newdimen\eql at fieldwidth@
+\newdimen\eql at tagwidth@
+\newdimen\eql at totalwidth@
+\newdimen\eql at tagwidth@max@
+\newdimen\eql at line@height@
+\newdimen\eql at line@depth@
+\newdimen\eql at line@width@
+\newdimen\eql at line@avail@
+\newdimen\eql at line@pos@
 \newcount\eql at row@
 \newcount\eql at totalrows@
+\newcount\eql at tagrows@
+\newcount\eql at column@
+\newcount\eql at totalcolumns@
 \newdimen\eql at colsep@
+\newcount\eql at align@inter@
 \newdimen\eql at display@firstavail@
 \def\eql at display@firstavail at set#1{%
   \ifnum\eql at row@=\@ne
@@ -200,12 +279,6 @@
   \fi
 }
 \newcount\eql at raisetag@firstlast@
-\newbox\eql at fieldbox@
-\newbox\eql at tagbox@
-\newdimen\eql at fieldwidth@
-\newdimen\eql at tagwidth@
-\newdimen\eql at line@height@
-\newdimen\eql at line@depth@
 \ifdefined\measuring at true\else
   \expandafter\newif\csname ifmeasuring@\endcsname
 \fi
@@ -231,68 +304,6 @@
 \let\eql at hook@innerleft\@empty
 \let\eql at hook@innerright\@empty
 \let\eql at hook@innerlead\@empty
-\let\eql at tagging@on\eql at false
-\IfFormatAtLeastTF{2025-06-01}{%
-  \csname tag_if_active:T\endcsname{\let\eql at tagging@on\eql at true}}{}
-\ifdefined\eql at tagging@on
-  \def\eql at tagging@mathsave{%
-    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
-  \def\eql at tagging@mathaddlast{%
-    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
-  \def\eql at tagging@tagbegin{%
-    \UseTaggingSocket{math/display/tag/begin}}
-  \def\eql at tagging@tagend{%
-    \UseTaggingSocket{math/display/tag/end}}
-  \def\eql at tagging@tagsave{%
-    \UseTaggingSocket{math/luamml/mtable/tag/save}}
-  \def\eql at tagging@tagaddbox{%
-    \setbox\z@\copy\eql at tagbox@%
-    \UseTaggingSocket{math/luamml/mtable/tag/set}}
-  \def\eql at tagging@tablesaveinner{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
-  \def\eql at tagging@tableaddinner{%
-    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
-  \def\eql at tagging@tablesavelines{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
-  \def\eql at tagging@tablesavealign{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
-  \def\eql at tagging@alignleft{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
-  \def\eql at tagging@aligncenter{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
-  \def\eql at tagging@alignright{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
-  \let\eql at single@doscan\eql at true
-  \let\eql at scan@body\eql at scan@body at rescan
-  \ExplSyntaxOn
-  \def\eql at tagging@start{%
-    \bool_if:NF\l__math_collected_bool{%
-      \toks@\expandafter{\eql at tagging@opt}%
-      \edef\eql at tmp{{\@currenvir}{[\the\toks@] \the\eql at scan@reg@}}%
-      \expandafter\__math_process:nn\eql at tmp
-      \@kernel at math@registered at begin
-      \bool_set_true:N\l__math_collected_bool
-    }%
-  }
-  \def\eql at tagging@end{}
-  \ExplSyntaxOff
-\else
-  \def\eql at tagging@mathsave{}
-  \def\eql at tagging@mathaddlast{}
-  \def\eql at tagging@tagbegin{}
-  \def\eql at tagging@tagend{}
-  \def\eql at tagging@tagsave{}
-  \def\eql at tagging@tagaddbox{}
-  \def\eql at tagging@tablesaveinner{}
-  \def\eql at tagging@tableaddinner{}
-  \def\eql at tagging@tablesavelines{}
-  \def\eql at tagging@tablesavealign{}
-  \def\eql at tagging@alignleft{}
-  \def\eql at tagging@aligncenter{}
-  \def\eql at tagging@alignright{}
-  \def\eql at tagging@start{}
-  \def\eql at tagging@end{}
-\fi
 \let\eql at punct@col\@empty
 \let\eql at punct@line\relax
 \let\eql at punct@block\relax
@@ -304,11 +315,25 @@
 \def\eql at punct@line at set#1{\def\eql at punct@line{#1}\ignorespaces}
 \def\eql at punct@line at setrelax{\let\eql at punct@line\relax\ignorespaces}
 \def\eqnpunctmain{\eql at ifstar@tight\eql at punct@main at setrelax\eql at punct@main at set}
-\def\eql at punct@main at set#1{\eqnlinesset{punct={#1}}\ignorespaces}
-\def\eql at punct@main at setrelax{\eqnlinesset{punct*}\ignorespaces}
+\def\eql at punct@main at set#1{\def\eql at punct@main{#1}\ignorespaces}
+\def\eql at punct@main at setrelax{\let\eql at punct@main\relax\ignorespaces}
 \def\eqnpunct{\eql at ifstar@tight\eql at punct@next at setrelax\eql at punct@next at set}
-\def\eql at punct@next at set#1{\eqnaddopt{punct={#1}}\ignorespaces}
-\def\eql at punct@next at setrelax{\eqnaddopt{punct*}\ignorespaces}
+\def\eql at punct@next at set#1{%
+  \ifmmode
+    \def\eql at punct@col{#1}%
+    \def\eql at punct@line{#1}%
+    \def\eql at punct@block{#1}%
+  \else
+    \eqnaddopt{punct={#1}}%
+  \fi
+  \ignorespaces}
+\def\eql at punct@next at setrelax{%
+  \ifmmode
+    \let\eql at punct@block\relax
+  \else
+    \eqnaddopt{punct*}%
+  \fi
+  \ignorespaces}
 \def\eql at punct@apply at col{%
   \ifx\eql at punct@col\@empty\else
     \eql at punct@sep
@@ -769,15 +794,6 @@
     \global\let\eql at nexttag\@undefined
   \fi
 }
-\def\eql at compose@null{%
-  \ifdefined\eql at nexttag\else
-    \stepcounter{equation}%
-  \fi
-  \ifnum\eql at numbering@target@<\z@
-    \global\let\eql at nextlabel\@undefined
-    \global\let\eql at nexttag\@undefined
-  \fi
-}
 \def\eql at tagbox@make#1{%
   \setbox\eql at tagbox@\hbox{\eql at strut@tag\@lign#1}%
   \eql at tagwidth@\wd\eql at tagbox@
@@ -865,6 +881,10 @@
   \ifcsname eql at numbering@tab@#1\endcsname
     \expandafter\let\expandafter\eql at numbering@mode
       \csname eql at numbering@tab@#1\endcsname
+    \ifx\eql at numbering@mode\eql at numbering@tab at none
+      \let\eql at numbering@mode\eql at numbering@tab at all
+      \let\eql at numbering@active\eql at false
+    \fi
   \else
     \eql at error{numbering mode `#1' unknown: setting to `all'}%
     \let\eql at numbering@mode\eql at numbering@tab at all
@@ -877,9 +897,6 @@
 \def\eql at numbering@mode at sub{%
   \eql at numbering@target@\m at ne
   \let\eql at numbering@subeq at use\eql at true}
-\def\eql at numbering@mode at none{%
-  \eql at numbering@target@\m at ne
-  \let\eql at numbering@active\eql at false}
 \def\eql at numbering@mode at first{%
   \eql at numbering@target@\@ne}
 \def\eql at numbering@mode at last{%
@@ -1421,13 +1438,16 @@
   \advance\abovedisplayskip\eql at abovespace@
   \advance\belowdisplayskip\eql at belowspace@
   \advance\belowdisplayskip\eql at vspaceskip@
-  \abovedisplayshortskip\abovedisplayskip
-  \belowdisplayshortskip\belowdisplayskip
   \count@\prevgraf
   \advance\count@\eql at row@
   \advance\count at -\tw@
   \prevgraf\count@
   \global\eql at skip@mode at leave@\eql at skip@mode at leave@
+  \ifdefined\eql at tagging@on
+    \ifdefined\dollardollar at begin\else
+      \belowdisplayskip-\belowdisplayskip
+    \fi
+  \fi
 }
 \def\eql at display@leave{%
   \let\label\eql at label@org
@@ -1578,8 +1598,10 @@
     \eql at stack@save at reg\eql at line@width@
     \eql at stack@save at reg\eql at line@depth@
     \eql at stack@save at reg\eql at line@height@
+    \eql at stack@save at reg\eql at tagwidth@max@
     \eql at stack@save at reg\eql at numbering@target@
     \eql at stack@save at reg\eql at row@
+    \eql at stack@save at reg\eql at tagrows@
   }%
 }
 \def\eql at stack@save at boxed@{%
@@ -1794,6 +1816,33 @@
     @\ifcase\eql at shape@pos@ shoveleft\or shovecenter\or shoveright\fi
     @notag\endcsname
 }
+\def\eql at adjust@calc{%
+  \ifdefined\eql at flushleft
+    \eql at flushleftmargin@\glueexpr\eql at flushleftmargin@val\relax
+  \else
+    \eql at align@inter@\z@
+    \eql at adjust@tagmargin
+    \ifdefined\eql at paddingmax
+      \eql at marginleft@\z@
+      \eql at marginright@\z@
+    \else
+      \dimen@\displaywidth
+      \advance\dimen at -\eql at totalwidth@
+      \advance\dimen at -\eql at tagmargin@
+      \divide\dimen@\tw@
+      \eql at marginleft@\dimen@
+      \advance\eql at marginleft@-\glueexpr\eql at paddingleft@val\relax
+      \ifdim\eql at marginleft@<\z@
+        \eql at marginleft@\z@
+      \fi
+      \eql at marginright@\dimen@
+      \advance\eql at marginright@-\glueexpr\eql at paddingright@val\relax
+      \ifdim\eql at marginright@<\z@
+        \eql at marginright@\z@
+      \fi
+    \fi
+  \fi
+}
 \def\eql at adjust@center at tagsright@shovecenter at notag{%
   \dimen@\displaywidth
   \advance\dimen at -\eql at fieldwidth@
@@ -2017,6 +2066,35 @@
   \fi
   \eql at display@firstavail at set\z@
 }
+\def\eql at adjust@tagmargin{%
+  \ifdefined\eql at tagmargin@val
+    \eql at tagmargin@\glueexpr\eql at tagmargin@val\relax
+  \else
+    \eql at tagmargin@\eql at tagwidth@max@
+    \ifdim\eql at tagmargin@>\z@
+      \advance\eql at tagmargin@-\eql at tagsepmin@
+    \fi
+  \fi
+  \dimen@\eql at tagrows@\p@
+  \ifnum\eql at totalrows@=\@ne
+    \ifnum\eql at tagrows@=\@ne
+      \advance\dimen at 1sp\relax
+    \fi
+  \fi
+  \ifdim\dimen@>\eql at totalrows@\eql at tagmargin@ratio@\else
+    \eql at tagmargin@\z@
+  \fi
+  \@tempdima\displaywidth
+  \advance\@tempdima-\eql at totalwidth@
+  \advance\@tempdima-\eql at align@inter@\eql at colsepmin@
+  \@tempdimb\@tempdima
+  \advance\@tempdimb-\tw@\eql at tagmargin@
+  \ifdim\@tempdimb>\z@
+    \ifdim\eql at tagmargin@threshold\@tempdima<\@tempdimb
+      \eql at tagmargin@\z@
+    \fi
+  \fi
+}
 \def\eql at adjust@flushleft at shoveleft{%
   \eql at marginleft@\eql at flushleftmargin@
   \advance\eql at marginleft@\eql at shape@amount@
@@ -2202,7 +2280,7 @@
 \def\eql at single@start{%
   \eql at halign@catchprevdepth
   \eql at tagging@start
-  $$%$$
+  \eql at dollardollar@begin
   \eql at numbering@eval at mode
   \let\eql at numbering@subeq at use\eql at false
   \eql at stack@save at single
@@ -2225,7 +2303,7 @@
   \eql at hook@eqout
   \eql at single@end at sel
   \eql at stack@restore
-  $$%$$
+  \eql at dollardollar@end
   \eql at tagging@end
   \eql at halign@leave
 }
@@ -2257,12 +2335,9 @@
   \let\shoveleft\eql at adjust@shoveleft
   \let\shovecenter\eql at adjust@shovecenter
   \let\shoveright\eql at adjust@shoveright
-  \ifdefined\eql at flushleft\else
-    \eql at marginleft@\z@
-    \eql at marginright@\z@
-  \fi
   \eql at adjust@init
   \eql at shape@eval
+  \eql at halign@init{}%
   \eql at row@\@ne
   \setbox\eql at fieldbox@\hbox\bgroup
     \eql at restore@hfuzz
@@ -2279,11 +2354,20 @@
   \eql at fieldwidth@\wd\eql at fieldbox@
   \eql at line@height@\ht\eql at fieldbox@
   \eql at line@depth@\dp\eql at fieldbox@
-  \eql at halign@init{}%
+  \eql at totalwidth@\eql at fieldwidth@
+  \eql at totalrows@\@ne
+  \if at eqnsw
+    \eql at tagbox@make\eql at compose@print
+    \eql at tagrows@\@ne
+  \else
+    \eql at tagwidth@\z@
+    \eql at tagrows@\z@
+  \fi
+  \eql at tagwidth@max@\eql at tagwidth@
+  \eql at adjust@calc
   \halign{##\cr
     \noalign{\eql at halign@before}%
     \if at eqnsw
-      \eql at tagbox@make\eql at compose@print
       \eql at adjust@sel at tag
     \else
       \eql at adjust@sel at notag
@@ -2295,12 +2379,6 @@
   \eql at row@\tw@
   \eql at display@close
 }
-\newcount\eql at column@
-\newcount\eql at totalcolumns@
-\newdimen\eql at totalwidth@
-\newdimen\eql at line@width@
-\newdimen\eql at line@avail@
-\newdimen\eql at line@pos@
 \let\eql at fieldlength@tab\@empty
 \def\eql at fieldlength@save#1{%
   \begingroup
@@ -2335,6 +2413,16 @@
     \global\edef\eql at tagwidth@tab{\the\eql at tagwidth@\eql at tagwidth@tab}%
   \endgroup
 }
+\let\eql at colwidth@tab\@empty
+\def\eql at align@colwidth at get#1{%
+  \ifcase\expandafter#1\eql at colwidth@tab\else\z@\fi
+}
+\def\eql at align@colwidth at save{%
+  \begingroup
+    \let\or\relax
+    \global\edef\eql at colwidth@tab{\or\the\wd\thr@@\eql at colwidth@tab}%
+  \endgroup
+}
 \def\eql at measure@init#1{%
   \measuring at true
   \eql at row@\z@
@@ -2522,7 +2610,7 @@
 \def\eql at multi@main{%
   \eql at halign@catchprevdepth
   \eql at tagging@start
-  $$%$$
+  \eql at dollardollar@begin
   \eql at numbering@eval at mode
   \eql at stack@save at multi
   \ifdefined\eql at subequations@active
@@ -2564,7 +2652,7 @@
     \eql at numbering@subeq at close
   \fi
   \eql at stack@restore
-  $$%$$
+  \eql at dollardollar@end
   \eql at tagging@end
   \eql at halign@leave
 }
@@ -2606,12 +2694,20 @@
 \def\eql at lines@measure at tag{%
   \ifnum\eql at numbering@target@<\z@
     \if at eqnsw
-      \eql at compose@null
+      \eql at tagbox@make\eql at compose@measure
+      \ifdim\eql at tagwidth@>\eql at tagwidth@max@
+        \global\eql at tagwidth@max@\eql at tagwidth@
+      \fi
+      \global\advance\eql at tagrows@\@ne
+    \else
+      \eql at tagwidth@\z@
     \fi
   \fi
 }
 \def\eql at lines@measure{%
 \eql at dev@enter\eql at lines@measure
+  \eql at tagwidth@max@\z@
+  \eql at tagrows@\z@
   \eql at measure@savecounters
   \setbox\z@\vbox{%
     \eql at numbering@measure at init
@@ -2649,8 +2745,17 @@
     }%
     \global\advance\eql at row@-\tw@
     \eql at numbering@measure at eval
+    \ifnum\eql at numbering@target@>\z@
+      \eql at tagbox@make\eql at compose@measure
+      \global\eql at tagwidth@max@\eql at tagwidth@
+      \global\eql at tagrows@\@ne
+    \fi
   }%
   \eql at totalrows@\eql at row@
+  \ifdefined\eql at numbering@subeq at use
+    \eql at numbering@subeq at test
+  \fi
+  \eql at measure@restorecounters
   \setbox\z@\vbox{%
     \unvbox\z@
     \unpenalty
@@ -2657,10 +2762,6 @@
     \global\setbox\@ne\lastbox
   }%
   \eql at totalwidth@\wd\@ne
-  \ifdefined\eql at numbering@subeq at use
-    \eql at numbering@subeq at test
-  \fi
-  \eql at measure@restorecounters
 \eql at dev@leave\eql at lines@measure
 }
 \def\eql at lines@print at line@begin{%
@@ -2687,29 +2788,8 @@
 \def\eql at lines@print{%
 \eql at dev@enter\eql at lines@print
   \eql at display@init
-  \ifdefined\eql at flushleft
-  \else
-    \ifdefined\eql at paddingmax
-      \eql at marginleft@\z@
-      \eql at marginright@\z@
-    \else
-      \dimen@\displaywidth
-      \advance\dimen at -\eql at totalwidth@
-      \advance\dimen at -\eql at tagmargin@
-      \divide\dimen@\tw@
-      \eql at marginleft@\dimen@
-      \advance\eql at marginleft@-\glueexpr\eql at paddingleft@val\relax
-      \ifdim\eql at marginleft@<\z@
-        \eql at marginleft@\z@
-      \fi
-      \eql at marginright@\dimen@
-      \advance\eql at marginright@-\glueexpr\eql at paddingright@val\relax
-      \ifdim\eql at marginright@<\z@
-        \eql at marginright@\z@
-      \fi
-    \fi
-  \fi
   \eql at adjust@init
+  \eql at adjust@calc
   \eql at numbering@print at init
   \eql at print@init\eql at lines@print at line@begin
   \eql at let@cr\eql at lines@print at line@end
@@ -2754,36 +2834,151 @@
   }%
   \eql at display@close
 }
-\let\eql at align@margins\eql at true
-\newcount\eql at align@inter@
-\let\eql at colwidth@tab\@empty
-\def\eql at align@colwidth at get#1{%
-  \ifcase\expandafter#1\eql at colwidth@tab\else\z@\fi
-}
-\def\eql at align@colwidth at save{%
-  \begingroup
-    \let\or\relax
-    \global\edef\eql at colwidth@tab{\or\the\wd\thr@@\eql at colwidth@tab}%
-  \endgroup
-}
 \def\eql at align@add at amp#1{\if m#1&\omit\expandafter\eql at align@add at amp\fi}
-\def\eql at align@completerow#1{%
-  \begingroup
-  \count@#1%
+\def\eql at align@completerow{%
+  \count@\eql at totalcolumns@
   \advance\count at -\eql at column@
-\advance\count@\@ne
-  \edef\eql at tmp{\endgroup
+  \advance\count@\@ne
+  \edef\eql at tmp{%
     \expandafter\eql at align@add at amp\romannumeral\number\count@ 000q}%
   \eql at tmp
 }
-\def\eql at align@print at trailright{%
-   &\omit
-    \global\advance\eql at column@\@ne
-    \setbox\eql at fieldbox@\hbox{%
-      \kern-\wd\eql at fieldbox@\box\eql at fieldbox@
+\def\eql at align@measure at line@begin{%
+\eql at dev{starting line \the\eql at row@}%
+  \global\eql at column@\z@
+  \eql at numbering@measure at line@begin
+  \eql at hook@linein
+}
+\def\eql at align@measure at field{%
+  \eql at fieldlength@save\eql at column@
+  \kern\wd\eql at fieldbox@
+}
+\def\eql at align@measure at line@end{%
+  \eql at punct@apply at line
+  \eql at hook@lineout
+  &\omit
+  \ifnum\eql at column@>\eql at totalcolumns@
+    \global\eql at totalcolumns@\eql at column@
+  \fi
+  \eql at align@measure at tag
+}
+\def\eql at align@measure at tag{%
+  \ifnum\eql at numbering@target@<\z@
+    \if at eqnsw
+      \eql at tagbox@make\eql at compose@measure
+      \ifdim\eql at tagwidth@>\eql at tagwidth@max@
+        \global\eql at tagwidth@max@\eql at tagwidth@
+      \fi
+      \global\advance\eql at tagrows@\@ne
+    \else
+      \eql at tagwidth@\z@
+    \fi
+    \eql at tagwidth@save
+  \fi
+}
+\def\eql at align@measure{%
+\eql at dev@enter\eql at align@measure
+  \eql at totalcolumns@\z@
+  \eql at tagwidth@max@\z@
+  \let\eql at tagwidth@tab\@empty
+  \let\eql at fieldlength@tab\@empty
+  \eql at tagrows@\z@
+  \eql at measure@savecounters
+  \setbox\z@\vbox{%
+    \eql at numbering@measure at init
+    \eql at measure@init\eql at align@measure at line@begin
+    \eql at let@cr\eql at align@measure at line@end
+    \tabskip\z at skip
+    \halign{%
+      &%
+        \global\advance\eql at column@\@ne
+        \hfil
+        \global\setbox\eql at fieldbox@\hbox{%
+          \@lign
+          $\m at th\displaystyle
+            \eql at hook@colin
+            ##%
+            \eql at class@innerleft
+            \eql at hook@innerleft
+          $%
+        }%
+        \global\eql at fieldwidth@\wd\eql at fieldbox@
+        \eql at align@measure at field
+      &%
+        \global\advance\eql at column@\@ne
+        \setbox\eql at fieldbox@\hbox{%
+          \@lign
+          $\m at th\displaystyle
+            \eql at hook@innerright
+            \eql at class@innerright at sel
+            ##%
+            \eql at punct@apply at col
+            \eql at hook@colout
+          $%
+        }%
+        \eql at align@measure at field
+        \hfil
+      \crcr
+      \noalign{%
+        \eql at hook@blockbefore
+      }%
+      \eql at hook@blockin
+      \eql at scan@body
+      \ifvmode\else
+        \eql at punct@apply at block
+        \eql at hook@blockout
+        \eql at align@measure at line@end
+        \cr
+      \fi
+      \noalign{%
+        \eql at hook@blockafter
+      }%
+      \eql at align@completerow
+      \cr
     }%
-    \eql at align@print at field
+    \global\advance\eql at row@-\tw@
+    \eql at numbering@measure at eval
+    \ifnum\eql at numbering@target@>\z@
+      \eql at tagbox@make\eql at compose@measure
+      \global\eql at tagwidth@max@\eql at tagwidth@
+      \global\eql at tagrows@\@ne
+      \eql at tagwidth@savezero
+    \fi
+  }%
+  \eql at totalrows@\eql at row@
+  \ifdefined\eql at numbering@subeq at use
+    \eql at numbering@subeq at test
+  \fi
+  \eql at measure@restorecounters
+  \setbox\z@\vbox{%
+    \unvbox\z@
+    \unpenalty
+    \global\setbox\@ne\lastbox
+  }%
+  \eql at totalwidth@\wd\@ne
+  \let\eql at colwidth@tab\@empty
+  \loop
+    \setbox\@ne\hbox{%
+      \unhbox\@ne
+      \unskip
+      \global\setbox\thr@@\lastbox
+    }%
+  \ifhbox\thr@@
+    \eql at align@colwidth at save
+  \repeat
+\eql at dev@leave\eql at align@measure
 }
+\def\eql at align@print at line@begin{%
+\eql at dev{starting line \the\eql at row@}%
+  \global\eql at column@\z@
+  \global\eql at line@pos@\eql at marginleft@
+  \global\eql at line@width@\z@
+  \global\eql at line@avail@\eql at totalwidth@
+  \global\eql at line@height@\z@
+  \global\eql at line@depth@\z@
+  \eql at numbering@print at line@begin
+  \eql at hook@linein
+}
 \def\eql at align@print at field{%
   \dimen@\eql at align@colwidth at get\eql at column@\relax
   \ifdim\wd\eql at fieldbox@>\z@
@@ -2823,16 +3018,13 @@
     \kern\dimen@
   \fi
 }
-\def\eql at align@print at line@begin{%
-\eql at dev{starting line \the\eql at row@}%
-  \global\eql at column@\z@
-  \global\eql at line@pos@\eql at marginleft@
-  \global\eql at line@width@\z@
-  \global\eql at line@avail@\eql at totalwidth@
-  \global\eql at line@height@\z@
-  \global\eql at line@depth@\z@
-  \eql at numbering@print at line@begin
-  \eql at hook@linein
+\def\eql at align@print at trailright{%
+   &\omit
+    \global\advance\eql at column@\@ne
+    \setbox\eql at fieldbox@\hbox{%
+      \kern-\wd\eql at fieldbox@\box\eql at fieldbox@
+    }%
+    \eql at align@print at field
 }
 \def\eql at align@print at line@end{%
   \eql at punct@apply at line
@@ -2840,10 +3032,10 @@
   \ifodd\eql at column@
     \expandafter\eql at align@print at trailright
   \fi
-  \eql at align@completerow\eql at totalcolumns@
-  \eql at align@print at line
+  \eql at align@completerow
+  \eql at align@print at tag
 }
-\def\eql at align@print at line{%
+\def\eql at align@print at tag{%
   \dimen@\eql at totalwidth@
   \advance\dimen@\eql at colsep@
   \kern-\dimen@
@@ -2929,126 +3121,8 @@
   }%
   \eql at display@close
 }
-\def\eql at align@measure at line@begin{%
-\eql at dev{starting line \the\eql at row@}%
-  \global\eql at column@\z@
-  \eql at numbering@measure at line@begin
-  \eql at hook@linein
-}
-\def\eql at align@measure at field{%
-  \eql at fieldlength@save\eql at column@
-  \kern\wd\eql at fieldbox@
-}
-\def\eql at align@measure at line@end{%
-  \eql at punct@apply at line
-  \eql at hook@lineout
-  &\omit
-  \ifnum\eql at column@>\eql at totalcolumns@
-    \global\eql at totalcolumns@\eql at column@
-  \fi
-  \eql at align@measure at tag
-}
-\def\eql at align@measure at tag{%
-  \ifnum\eql at numbering@target@<\z@
-    \if at eqnsw
-      \eql at tagbox@make\eql at compose@measure
-    \else
-      \eql at tagwidth@\z@
-    \fi
-    \eql at tagwidth@save
-  \fi
-}
-\def\eql at align@measure{%
-\eql at dev@enter\eql at align@measure
-  \eql at totalcolumns@\z@
-  \let\eql at tagwidth@tab\@empty
-  \let\eql at fieldlength@tab\@empty
-  \eql at measure@savecounters
-  \setbox\z@\vbox{%
-    \eql at numbering@measure at init
-    \eql at measure@init\eql at align@measure at line@begin
-    \eql at let@cr\eql at align@measure at line@end
-    \tabskip\z at skip
-    \halign{%
-      &%
-        \global\advance\eql at column@\@ne
-        \hfil
-        \global\setbox\eql at fieldbox@\hbox{%
-          \@lign
-          $\m at th\displaystyle
-            \eql at hook@colin
-            ##%
-            \eql at class@innerleft
-            \eql at hook@innerleft
-          $%
-        }%
-        \global\eql at fieldwidth@\wd\eql at fieldbox@
-        \eql at align@measure at field
-      &%
-        \global\advance\eql at column@\@ne
-        \setbox\eql at fieldbox@\hbox{%
-          \@lign
-          $\m at th\displaystyle
-            \eql at hook@innerright
-            \eql at class@innerright at sel
-            ##%
-            \eql at punct@apply at col
-            \eql at hook@colout
-          $%
-        }%
-        \eql at align@measure at field
-        \hfil
-      \crcr
-      \noalign{%
-        \eql at hook@blockbefore
-      }%
-      \eql at hook@blockin
-      \eql at scan@body
-      \ifvmode\else
-        \eql at punct@apply at block
-        \eql at hook@blockout
-        \eql at align@measure at line@end
-        \cr
-      \fi
-      \noalign{%
-        \eql at hook@blockafter
-      }%
-      \eql at align@completerow\eql at totalcolumns@
-      \cr
-    }%
-    \global\advance\eql at row@-\tw@
-    \eql at numbering@measure at eval
-    \ifnum\eql at numbering@target@>\z@
-      \eql at tagbox@make\eql at compose@measure
-      \eql at tagwidth@savezero
-    \fi
-  }%
-  \eql at totalrows@\eql at row@
-  \ifdefined\eql at numbering@subeq at use
-    \eql at numbering@subeq at test
-  \fi
-  \eql at measure@restorecounters
-  \setbox\z@\vbox{%
-    \unvbox\z@
-    \unpenalty
-    \global\setbox\@ne\lastbox
-  }%
-  \eql at totalwidth@\wd\@ne
-  \let\eql at colwidth@tab\@empty
-  \loop
-    \setbox\@ne\hbox{%
-      \unhbox\@ne
-      \unskip
-      \global\setbox\thr@@\lastbox
-    }%
-  \ifhbox\thr@@
-    \eql at align@colwidth at save
-  \repeat
-\eql at dev@leave\eql at align@measure
-}
 \def\eql at align@adjust{%
   \eql at colsepmin@\glueexpr\eql at colsepmin@val\relax
-  \eql at colsepmax@\glueexpr\eql at colsepmax@val\relax
   \ifodd\eql at totalcolumns@
     \advance\eql at totalcolumns@\@ne
   \fi
@@ -3058,10 +3132,22 @@
   \eql at align@inter@\eql at totalcolumns@
   \divide\eql at align@inter@\tw@
   \advance\eql at align@inter@\m at ne
+  \ifdefined\eql at flushleft
+    \eql at flushleftmargin@\glueexpr\eql at flushleftmargin@val\relax
+  \else
+    \eql at adjust@tagmargin
+  \fi
   \eql at colsep@\displaywidth
   \advance\eql at colsep@-\eql at totalwidth@
   \ifdefined\eql at flushleft
     \advance\eql at colsep@-\eql at flushleftmargin@
+  \else
+    \advance\eql at colsep@-\eql at tagmargin@
+    \ifdefined\eql at align@margins\else
+      \ifdim\eql at tagmargin@>\z@
+        \advance\eql at colsep@-\eql at tagsepmin@
+      \fi
+    \fi
   \fi
   \count@\eql at align@inter@
   \ifdefined\eql at align@margins
@@ -3075,8 +3161,9 @@
   \ifdim\eql at colsep@<\eql at colsepmin@
     \eql at colsep@\eql at colsepmin@
   \else
-    \ifdim\eql at colsep@>\eql at colsepmax@
-      \eql at colsep@\eql at colsepmax@
+    \dimen@\glueexpr\eql at colsepmax@val\relax
+    \ifdim\eql at colsep@>\dimen@
+      \eql at colsep@\dimen@
     \fi
   \fi
   \ifdefined\eql at flushleft
@@ -3100,15 +3187,23 @@
       \advance\eql at marginleft@-\eql at totalwidth@
       \advance\eql at marginleft@-\eql at align@inter@\eql at colsep@
       \ifdim\eql at marginleft@<\eql at tagmargin@
-        \ifdim\ifdefined\eql at tagsleft\eql at marginleft@\else-\p@\fi<\z@
-          \eql at marginleft@\z@
-        \fi
+        \eql at marginleft@\z@
       \else
         \advance\eql at marginleft@-\eql at tagmargin@
         \divide\eql at marginleft@\tw@
       \fi
+      \ifdefined\eql at tagsleft
+        \advance\eql at marginleft@\eql at tagmargin@
+      \fi
     \else
-      \eql at marginleft@\z@
+      \ifdefined\eql at tagsleft
+        \eql at marginleft@\eql at tagmargin@
+        \ifdim\eql at tagmargin@>\z@
+          \advance\eql at marginleft@\eql at tagsepmin@
+        \fi
+      \else
+        \eql at marginleft@\z@
+      \fi
     \fi
   \fi
   \ifdefined\eql at tagsleft
@@ -3116,6 +3211,7 @@
   \else
     \let\eql at align@adjust at test\eql at align@adjust at test@tagright
   \fi
+  \eql at row@\eql at totalrows@
   \loop\ifnum\eql at row@>\z@
     \ifnum\eql at numbering@target@<\z@
       \eql at tagwidth@\eql at tagwidth@get\eql at row@\relax
@@ -3125,7 +3221,7 @@
       \fi
     \fi
     \ifdim\eql at tagwidth@>\z@
-      \eql at align@adjust at width
+      \eql at align@adjust at calc
       \eql at align@adjust at test
     \fi
     \advance\eql at row@\m at ne
@@ -3133,7 +3229,7 @@
   \advance\eql at totalwidth@\eql at align@inter@\eql at colsep@
   \advance\eql at totalwidth@\eql at marginleft@
 }
-\def\eql at align@adjust at width{%
+\def\eql at align@adjust at calc{%
   \eql at line@pos@\z@
   \eql at column@\z@
   \eql at line@avail@\eql at totalwidth@
@@ -3142,13 +3238,13 @@
   \@tempcntb\z@
   \edef\@tempb{\eql at fieldlength@get\eql at row@}%
   \@for\@tempa:=\@tempb\do
-    \eql at align@adjust at width@col
+    \eql at align@adjust at calc@col
   \advance\@tempcnta\m at ne
   \divide\@tempcnta\tw@
   \advance\@tempcntb\m at ne
   \divide\@tempcntb\tw@
 }
-\def\eql at align@adjust at width@col{%
+\def\eql at align@adjust at calc@col{%
   \advance\eql at column@\@ne
   \@tempdima\@tempa\relax
   \dimen@\eql at align@colwidth at get\eql at column@\relax
@@ -3171,99 +3267,93 @@
   \fi
   \advance\eql at line@pos@\dimen@
 }
-
 \def\eql at align@adjust at test@tagright{%
-  \@tempdima\eql at line@width@
-  \advance\@tempdima\eql at tagwidth@
+  \@tempdima\displaywidth
+  \advance\@tempdima-\eql at line@width@
+  \advance\@tempdima-\eql at tagwidth@
   \dimen@\eql at marginleft@
-  \advance\dimen@\@tempdima
   \advance\dimen@\@tempcntb\eql at colsep@
-  \ifdim\dimen@>\displaywidth
-    \eql at align@adjust at modify@tagright
+  \ifdim\dimen@>\@tempdima
+    \dimen@\@tempcntb\eql at colsepmin@
+    \ifdefined\eql at flushleft
+      \advance\dimen@\eql at flushleftmarginmin@
+    \fi
+    \ifdim\dimen@>\@tempdima\else
+      \eql at align@adjust at modify@tagright
+    \fi
   \fi
 }
 \def\eql at align@adjust at modify@tagright{%
-  \dimen@\eql at colsepmin@
-  \multiply\dimen@\@tempcntb
-  \advance\dimen@\@tempdima
-  \ifdefined\eql at flushleft
-    \advance\dimen@\eql at flushleftmarginmin@
-  \fi
-  \ifdim\dimen@>\displaywidth\else
-    \ifnum\@tempcntb>\z@
-      \dimen@\displaywidth
-      \advance\dimen at -\@tempdima
-      \count@\@tempcntb
-      \ifdefined\eql at flushleft
-        \advance\dimen at -\eql at marginleft@
-      \else
-        \ifdefined\eql at align@margins
-          \advance\count@\@ne
-        \fi
+  \ifnum\@tempcntb>\z@
+    \dimen@\@tempdima
+    \count@\@tempcntb
+    \ifdefined\eql at flushleft
+      \advance\dimen at -\eql at marginleft@
+    \else
+      \ifdefined\eql at align@margins
+        \advance\count@\@ne
       \fi
-      \divide\dimen@\count@
-      \ifdim\dimen@<\eql at colsep@
-        \ifdim\dimen@<\eql at colsepmin@
-          \dimen@\eql at colsepmin@
-        \fi
-        \eql at colsep@\dimen@
+    \fi
+    \divide\dimen@\count@
+    \ifdim\dimen@<\eql at colsep@
+      \ifdim\dimen@<\eql at colsepmin@
+        \dimen@\eql at colsepmin@
       \fi
+      \eql at colsep@\dimen@
     \fi
-    \dimen@\displaywidth
-    \advance\dimen at -\@tempdima
-    \advance\dimen at -\@tempcntb\eql at colsep@
-    \ifdim\dimen@<\eql at marginleft@
-      \eql at marginleft@\dimen@
-    \fi
   \fi
+  \dimen@\@tempdima
+  \advance\dimen at -\@tempcntb\eql at colsep@
+  \ifdim\dimen@<\eql at marginleft@
+    \eql at marginleft@\dimen@
+  \fi
 }
 \def\eql at align@adjust at test@tagleft{%
   \count@\eql at align@inter@
   \advance\count at -\@tempcnta
-  \@tempdima-\eql at line@avail@
-  \advance\@tempdima\eql at tagwidth@
+  \@tempdima\eql at tagwidth@
+  \advance\@tempdima-\eql at line@avail@
   \dimen@\eql at marginleft@
   \advance\dimen@\@tempcnta\eql at colsep@
   \ifdim\dimen@<\@tempdima
-    \eql at align@adjust at modify@tagleft
+    \ifdefined\eql at flushleft
+      \dimen@\eql at flushleftmarginmax@
+    \else
+      \dimen@\displaywidth
+    \fi
+    \ifdim\dimen@>\eql at tagwidth@
+      \dimen@\count@\eql at colsepmin@
+      \advance\dimen@\eql at totalwidth@
+      \advance\dimen@\@tempdima
+      \ifdim\dimen@>\displaywidth\else
+        \eql at align@adjust at modify@tagleft
+      \fi
+    \fi
   \fi
 }
 \def\eql at align@adjust at modify@tagleft{%
-  \ifdefined\eql at flushleft
-    \dimen@\eql at flushleftmarginmax@
-  \else
+  \ifnum\count@>\z@
     \dimen@\displaywidth
-  \fi
-  \ifdim\dimen@>\eql at tagwidth@
-    \dimen@\eql at colsepmin@
-    \multiply\dimen@\count@
-    \advance\dimen@\eql at totalwidth@
-    \advance\dimen@\@tempdima
-    \ifdim\dimen@>\displaywidth\else
-      \ifnum\count@>0
-        \dimen@\displaywidth
-        \advance\dimen at -\eql at totalwidth@
-        \advance\dimen at -\@tempdima
-        \ifdefined\eql at align@margins
-          \advance\count@\@ne
-        \fi
-        \divide\dimen@\count@
-        \ifdim\dimen@<\eql at colsep@
-          \ifdim\dimen@<\eql at colsepmin@
-            \dimen@\eql at colsepmin@
-          \fi
-          \advance\dimen at -\eql at colsep@
-          \advance\eql at marginleft@-\eql at align@inter@\dimen@
-          \advance\eql at colsep@\dimen@
-        \fi
+    \advance\dimen at -\eql at totalwidth@
+    \advance\dimen at -\@tempdima
+    \ifdefined\eql at align@margins
+      \advance\count@\@ne
+    \fi
+    \divide\dimen@\count@
+    \ifdim\dimen@<\eql at colsep@
+      \ifdim\dimen@<\eql at colsepmin@
+        \dimen@\eql at colsepmin@
       \fi
-      \dimen at -\@tempcnta\eql at colsep@
-      \advance\dimen@\@tempdima
-      \ifdim\dimen@>\eql at marginleft@
-        \eql at marginleft@\dimen@
-      \fi
+      \advance\dimen at -\eql at colsep@
+      \advance\eql at marginleft@-\eql at align@inter@\dimen@
+      \advance\eql at colsep@\dimen@
     \fi
   \fi
+  \dimen at -\@tempcnta\eql at colsep@
+  \advance\dimen@\@tempdima
+  \ifdim\dimen@>\eql at marginleft@
+    \eql at marginleft@\dimen@
+  \fi
 }
 \newtoks\eql at scan@reg@
 \def\eql at scan@body at dump{\the\eql at scan@reg@}
@@ -3270,7 +3360,7 @@
 \def\eql at scan@body at rescan{%
   \expandafter\scantokens\expandafter{\the\eql at scan@reg@}}
 \let\eql at scan@body\eql at scan@body at dump
-\def\eql at scan@addto#1{\eql at scan@reg@\expandafter{\the\eql at scan@reg@#1}}
+\long\def\eql at scan@addto#1{\eql at scan@reg@\expandafter{\the\eql at scan@reg@#1}}
 \def\eql at scan@env#1{%
 \eql at dev@enter\eql at scan@env
   \def\eql at scan@end{#1\expandafter\end\expandafter{\@currenvir}}%
@@ -3280,9 +3370,6 @@
   \expandafter\let\eql at scan@iterate\eql at scan@env at iterate
   \eql at scan@iterate
 }
-\def\eql at scan@env at count#1\begin#2{%
-  \ifx\end#2\else b\expandafter\eql at scan@env at count\fi
-}
 \def\eql at scan@env at iterate#1\end#2{%
   \edef\eql at scan@stack{%
     \eql at scan@env at count#1\begin\end\expandafter\@gobble\eql at scan@stack}%
@@ -3297,6 +3384,9 @@
     \expandafter\eql at scan@iterate
   \fi
 }
+\long\def\eql at scan@env at count#1\begin#2{%
+  \ifx\end#2\else b\expandafter\eql at scan@env at count\fi
+}
 \def\eql at scan@env at cancel{%
   \@namedef{end\@currenvir}{\ignorespacesafterend}%
 }
@@ -3308,9 +3398,6 @@
   \let\[\eql at scan@sqr at iterate%\]
   \[%\]
 }
-\def\eql at scan@sqr at count#1\[#2{%\]
-  \ifx\]#2\else b\expandafter\eql at scan@sqr at count\fi
-}
 \def\eql at scan@sqr at iterate#1\]{%
   \edef\eql at scan@stack{%
     \eql at scan@sqr at count#1\[\]\expandafter\@gobble\eql at scan@stack}%
@@ -3324,6 +3411,9 @@
     \expandafter\[%\]
   \fi
 }
+\long\def\eql at scan@sqr at count#1\[#2{%\]
+  \ifx\]#2\else b\expandafter\eql at scan@sqr at count\fi
+}
 \def\eql at scan@sqrang at cancel{\expandafter\ignorespaces\@gobble}
 \def\eql at scan@ang#1{%
 \eql at dev@enter\eql at scan@ang
@@ -3333,9 +3423,6 @@
   \let\<\eql at scan@ang at iterate%\>
   \<%\>
 }
-\def\eql at scan@ang at count#1\<#2{%\>
-  \ifx\>#2\else b\expandafter\eql at scan@ang at count\fi
-}
 \def\eql at scan@ang at iterate#1\>{%
   \edef\eql at scan@stack{%
     \eql at scan@ang at count#1\<\>\expandafter\@gobble\eql at scan@stack}%
@@ -3349,6 +3436,9 @@
     \expandafter\<%\>
   \fi
 }
+\long\def\eql at scan@ang at count#1\<#2{%\>
+  \ifx\>#2\else b\expandafter\eql at scan@ang at count\fi
+}
 \def\eql at equations@testall{\eql at equations@testtilde}
 \def\eql at equations@testtilde#1{%
   \eql at ifnextgobble@tight~%
@@ -3385,6 +3475,7 @@
   \let\eql at punct@block\eql at punct@main
   \let\eql at punct@main\relax
   \eql at indent@\glueexpr\eql at indent@val\relax
+  \eql at tagsepmin@\glueexpr\eql at tagsepmin@val\relax
 }
 \newenvironment{equations}{%
 \eql at dev@enterenv
@@ -3409,7 +3500,6 @@
   \fi
 }
 \newenvironment{equations at sqr}{}{}
-\def\eql at equations@sqr at opt{equation,nonumber}
 \protected\def\eql at equations@sqr at open{%
   \ifmmode
     \eql at error@mathmode{\string\[...\string\]}%
@@ -3422,8 +3512,21 @@
       \expandafter\eql at equations@sqr at start
   \fi
 }
+\def\eql at equations@sqr at start{%
+  \eql at equations@processopt
+  \ifdefined\eql at equations@main
+    \expandafter\eql at scan@sqr\expandafter\eql at equations@main
+  \else
+    \expandafter\eql at single@start
+  \fi
+}
+\protected\def\eql at equations@sqr at close{%
+  \eql at equations@end
+\eql at dev@leave{\[...\string\]}%
+  \end{equations at sqr}%
+  \ignorespaces
+}
 \newenvironment{equations at ang}{}{}
-\def\eql at equations@ang at opt{align,nonumber}
 \protected\def\eql at equations@ang at open{%
   \ifmmode
     \eql at error@mathmode{\string\<...\string\>}%
@@ -3436,14 +3539,6 @@
       \expandafter\eql at equations@ang at start
   \fi
 }
-\def\eql at equations@sqr at start{%
-  \eql at equations@processopt
-  \ifdefined\eql at equations@main
-    \expandafter\eql at scan@sqr\expandafter\eql at equations@main
-  \else
-    \expandafter\eql at single@start
-  \fi
-}
 \def\eql at equations@ang at start{%
   \eql at equations@processopt
   \ifdefined\eql at equations@main
@@ -3452,12 +3547,6 @@
     \expandafter\eql at single@start
   \fi
 }
-\protected\def\eql at equations@sqr at close{%
-  \eql at equations@end
-\eql at dev@leave{\[...\string\]}%
-  \end{equations at sqr}%
-  \ignorespaces
-}
 \protected\def\eql at equations@ang at close{%
   \eql at equations@end
 \eql at dev@leave{\<...\string\>}%
@@ -3557,8 +3646,13 @@
 \newcommand{\eqnaddopt}[1]{%
   \expandafter\def\expandafter\eql at nextopt\expandafter{\eql at nextopt,#1}}
 \def\eql at defaults@classic{%
+  \def\eql at tagsepmin@val{.5\fontdimen6\textfont\tw@}%
   \def\eql at colsepmax@val{.5\maxdimen}%
   \def\eql at spread{\jot}%
+  \let\eql at tagmargin@val\@undefined
+  \eql at tagmargin@ratio@\p@
+  \def\eql at tagmargin@threshold{0.5}%
+  \def\eql at flushleftmargin@val{\leftmargini}%
   \let\eql at display@height\@undefined
   \let\eql at display@depth\@undefined
   \eql at skip@mode at short@\tw@
@@ -3583,8 +3677,13 @@
   \def\eql at skip@tag at below{\z at skip}%
 }
 \def\eql at defaults@eqnlines{%
+  \def\eql at tagsepmin@val{.5em}%
   \def\eql at colsepmax@val{2em}%
   \def\eql at spread{0.2\normalbaselineskip}%
+  \let\eql at tagmargin@val\@undefined
+  \eql at tagmargin@ratio at .334\p@
+  \def\eql at tagmargin@threshold{0.5}%
+  \def\eql at flushleftmargin@val{\leftmargini}%
   \def\eql at display@height{\ht\eql at strutbox@}%
   \def\eql at display@depth{\dp\eql at strutbox@}%
   \eql at skip@mode at short@\@ne
@@ -3595,11 +3694,11 @@
     \@plus0.25\normalbaselineskip\@minus0.4\normalbaselineskip}%
   \let\eql at skip@long at below\eql at skip@long at above
   \def\eql at skip@short at above{0.0\normalbaselineskip
-    \@plus0.2\normalbaselineskip}%
+    \@plus0.25\normalbaselineskip}%
   \def\eql at skip@short at below{0.0\normalbaselineskip
     \@plus0.25\normalbaselineskip}%
-  \def\eql at skip@med at above{0.375\normalbaselineskip
-    \@plus0.225\normalbaselineskip\@minus0.2\normalbaselineskip}%
+  \def\eql at skip@med at above{0.4\normalbaselineskip
+    \@plus0.2\normalbaselineskip\@minus0.2\normalbaselineskip}%
   \let\eql at skip@med at below\eql at skip@med at above
   \def\eql at skip@cont at above{\z at skip}%
   \def\eql at skip@cont at below{\eql at skip@long at below}%
@@ -3812,10 +3911,17 @@
 \eql at define@key\eql at keycat{tag}{\eql at blocktag@set{#1}}
 \eql at define@key\eql at keycat{tag*}{\eql at blocktag@setstar{#1}}
 \def\eql at keycat{equations,setup}
-\eql at define@key\eql at keycat{tagmargin}{\eql at tagmargin@\glueexpr#1\relax}
-\eql at define@key\eql at keycat{tagmargin*}{\settowidth\eql at tagmargin@{#1}}
-\eql at define@key\eql at keycat{mintagsep}{\eql at tagsepmin@\glueexpr#1\relax}
-\eql at define@key\eql at keycat{mintagwidth}{\eql at tagwidthmin@\glueexpr#1\relax}
+\eql at define@key\eql at keycat{tagmargin}{\def\eql at tagmargin@val{#1}}
+\eql at define@key\eql at keycat{tagmargin*}{%
+  \settowidth\dimen@{#1}\edef\eql at tagmargin@val{\the\dimen@}}
+\eql at define@key\eql at keycat{tagmargincalc}[]{\let\eql at tagmargin@val\@undefined}
+\eql at define@key\eql at keycat{tagmarginratio}{%
+  \eql at tagmargin@ratio@\dimexpr#1pt\relax}
+\eql at define@key\eql at keycat{tagmarginthreshold}{%
+  \def\eql at tagmargin@threshold{#1}}
+\eql at define@key\eql at keycat{mintagsep}{\def\eql at tagsepmin@val{#1}}
+\eql at define@key\eql at keycat{mintagwidth}{%
+  \settowidth\dimen@{#1}\edef\eql at tagsepmin@val{\the\dimen@}}
 \eql at define@key\eql at keycat{mintagwidth*}{\settowidth\eql at tagwidthmin@{#1}}
 \eql at define@key{setup}{taglayout}{\eql at tag@setbox{#1}}
 \eql at define@key{setup}{taglayout*}{\eql at tag@setbox@{#1}}
@@ -3845,8 +3951,9 @@
   {{left,l}{\let\eql at flushleft\eql at true}}}}
 \eql at define@key\eql at keycat{center}[]{\let\eql at flushleft\eql at false}
 \eql at define@key\eql at keycat{flushleft,left}[]{\let\eql at flushleft\eql at true}
-\eql at define@key\eql at keycat{leftmargin}{%
-  \eql at flushleftmargin@\glueexpr#1\relax}
+\eql at define@key\eql at keycat{leftmargin}{\def\eql at flushleftmargin@val{#1}}
+\eql at define@key\eql at keycat{leftmargin*}{%
+  \settowidth\dimen@{#1}\edef\eql at flushleftmargin@val{\the\dimen@}}
 \eql at define@key\eql at keycat{minleftmargin}{%
   \eql at flushleftmarginmin@\glueexpr#1\relax}
 \eql at define@key\eql at keycat{maxleftmargin}{%
@@ -4213,6 +4320,8 @@
 \eql at dev@start\eqnlinesset
   \eql at setkeys{setup}{#1}}
 \let\eql at error@packageoption\@gobble
+\DeclareOption{leqno}{\eqnlinesset{tagsleft}}
+\DeclareOption{fleqn}{\eqnlinesset{left}}
 \DeclareOption*{\expandafter\eqnlinesset\expandafter{\CurrentOption}}
 \ProcessOptions
 \def\eql at error@packageoption#1{%

Modified: trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines.sty	2025-03-28 21:33:02 UTC (rev 74777)
+++ trunk/Master/texmf-dist/tex/latex/eqnlines/eqnlines.sty	2025-03-28 21:33:10 UTC (rev 74778)
@@ -21,7 +21,16 @@
 %% version 2008 or later.
 %% 
 \NeedsTeXFormat{LaTeX2e}[2020/10/01]
-\ProvidesPackage{eqnlines}[2025/03/11 v0.6 Single- and multi-line equations]
+\ProvidesPackage{eqnlines}[2025/03/27 v0.6.1 Single- and multi-line equations]
+\let\eql at false\@undefined
+\let\eql at true\@empty
+\ifdefined\dollardollar at begin
+  \def\eql at dollardollar@begin{\dollardollar at begin}
+  \def\eql at dollardollar@end{\dollardollar at end}
+\else
+  \def\eql at dollardollar@begin{$$}
+  \def\eql at dollardollar@end{$$}
+\fi
 \let\eql at ifnextchar@loose\kernel at ifnextchar
 \long\def\eql at ifnextchar@tight#1#2#3{%
   \let\reserved at d= #1%
@@ -103,28 +112,81 @@
   \@ifpackageloaded{amsmath}{}{\AddToHook{package/amsmath/before}{#1}}}
 \def\eql at amsmath@undefine#1{\eql at amsmath@before{\let#1\@undefined}}
 \def\eql at amsmath@let#1#2{\eql at amsmath@undefine#1\let#1#2}
-\let\eql at false\@undefined
-\let\eql at true\@empty
-\newskip\eql at regunset@
-\eql at regunset@-1sp\relax
-\def\eql at regsetdelayed#1#2{%
-  #1\eql at regunset@\relax
-  \AtBeginDocument{%
-    \ifdim#1=\eql at regunset@
-      #1\glueexpr#2\relax
-    \fi
-  }%
-}
+\let\eql at tagging@on\eql at false
+\IfFormatAtLeastTF{2025-06-01}{%
+  \csname tag_if_active:T\endcsname{\let\eql at tagging@on\eql at true}}{}
+\ifdefined\eql at tagging@on
+  \def\eql at tagging@mathsave{%
+    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
+  \def\eql at tagging@mathaddlast{%
+    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
+  \def\eql at tagging@tagbegin{%
+    \UseTaggingSocket{math/display/tag/begin}}
+  \def\eql at tagging@tagend{%
+    \UseTaggingSocket{math/display/tag/end}}
+  \def\eql at tagging@tagsave{%
+    \UseTaggingSocket{math/luamml/mtable/tag/save}}
+  \def\eql at tagging@tagaddbox{%
+    \setbox\z@\copy\eql at tagbox@%
+    \UseTaggingSocket{math/luamml/mtable/tag/set}}
+  \def\eql at tagging@tablesaveinner{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
+  \def\eql at tagging@tableaddinner{%
+    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
+  \def\eql at tagging@tablesavelines{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
+  \def\eql at tagging@tablesavealign{%
+    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
+  \def\eql at tagging@alignleft{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
+  \def\eql at tagging@aligncenter{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
+  \def\eql at tagging@alignright{%
+    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
+  \let\eql at single@doscan\eql at true
+  \let\eql at scan@body\eql at scan@body at rescan
+  \ExplSyntaxOn
+  \def\eql at tagging@start{%
+    \bool_if:NF\l__math_collected_bool{%
+      \toks@\expandafter{\eql at tagging@opt}%
+      \edef\eql at tmp{{\@currenvir}{[\the\toks@] \the\eql at scan@reg@}}%
+      \expandafter\__math_process:nn\eql at tmp
+      \@kernel at math@registered at begin
+      \bool_set_true:N\l__math_collected_bool
+    }%
+  }
+  \def\eql at tagging@end{}
+  \ExplSyntaxOff
+\else
+  \def\eql at tagging@mathsave{}
+  \def\eql at tagging@mathaddlast{}
+  \def\eql at tagging@tagbegin{}
+  \def\eql at tagging@tagend{}
+  \def\eql at tagging@tagsave{}
+  \def\eql at tagging@tagaddbox{}
+  \def\eql at tagging@tablesaveinner{}
+  \def\eql at tagging@tableaddinner{}
+  \def\eql at tagging@tablesavelines{}
+  \def\eql at tagging@tablesavealign{}
+  \def\eql at tagging@alignleft{}
+  \def\eql at tagging@aligncenter{}
+  \def\eql at tagging@alignright{}
+  \def\eql at tagging@start{}
+  \def\eql at tagging@end{}
+\fi
 \let\eql at tagsleft\eql at false
 \let\eql at flushleft\eql at false
 \newdimen\eql at flushleftmargin@
 \newdimen\eql at flushleftmarginmin@
 \newdimen\eql at flushleftmarginmax@
-\eql at regsetdelayed\eql at flushleftmargin@\leftmargini
+\def\eql at flushleftmargin@val{\leftmargini}
 \eql at flushleftmarginmin@\z@
 \eql at flushleftmarginmax@.5\maxdimen
 \newdimen\eql at tagmargin@
-\eql at tagmargin@\z@
+\let\eql at tagmargin@val\@undefined
+\newdimen\eql at tagmargin@ratio@
+\eql at tagmargin@ratio@\p@
+\def\eql at tagmargin@threshold{0.5}
 \newdimen\eql at indent@
 \def\eql at indent@val{2em}
 \newdimen\eql at paddingleft@
@@ -176,16 +238,33 @@
 \def\eql at skip@medtag at above{\z at skip}
 \def\eql at skip@medtag at below{\z at skip}
 \newdimen\eql at colsepmin@
-\newdimen\eql at colsepmax@
 \def\eql at colsepmin@val{1em}
 \def\eql at colsepmax@val{.5\maxdimen}
 \newdimen\eql at tagwidthmin@
 \eql at tagwidthmin@\z@
 \newdimen\eql at tagsepmin@
-\eql at regsetdelayed\eql at tagsepmin@{.5em}
+\def\eql at tagsepmin@val{.5\fontdimen6\textfont\tw@}
+\def\eql at equations@sqr at opt{equation,nonumber}
+\def\eql at equations@ang at opt{align,nonumber}
+\let\eql at align@margins\eql at true
+\newbox\eql at fieldbox@
+\newbox\eql at tagbox@
+\newdimen\eql at fieldwidth@
+\newdimen\eql at tagwidth@
+\newdimen\eql at totalwidth@
+\newdimen\eql at tagwidth@max@
+\newdimen\eql at line@height@
+\newdimen\eql at line@depth@
+\newdimen\eql at line@width@
+\newdimen\eql at line@avail@
+\newdimen\eql at line@pos@
 \newcount\eql at row@
 \newcount\eql at totalrows@
+\newcount\eql at tagrows@
+\newcount\eql at column@
+\newcount\eql at totalcolumns@
 \newdimen\eql at colsep@
+\newcount\eql at align@inter@
 \newdimen\eql at display@firstavail@
 \def\eql at display@firstavail at set#1{%
   \ifnum\eql at row@=\@ne
@@ -193,12 +272,6 @@
   \fi
 }
 \newcount\eql at raisetag@firstlast@
-\newbox\eql at fieldbox@
-\newbox\eql at tagbox@
-\newdimen\eql at fieldwidth@
-\newdimen\eql at tagwidth@
-\newdimen\eql at line@height@
-\newdimen\eql at line@depth@
 \ifdefined\measuring at true\else
   \expandafter\newif\csname ifmeasuring@\endcsname
 \fi
@@ -224,68 +297,6 @@
 \let\eql at hook@innerleft\@empty
 \let\eql at hook@innerright\@empty
 \let\eql at hook@innerlead\@empty
-\let\eql at tagging@on\eql at false
-\IfFormatAtLeastTF{2025-06-01}{%
-  \csname tag_if_active:T\endcsname{\let\eql at tagging@on\eql at true}}{}
-\ifdefined\eql at tagging@on
-  \def\eql at tagging@mathsave{%
-    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
-  \def\eql at tagging@mathaddlast{%
-    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
-  \def\eql at tagging@tagbegin{%
-    \UseTaggingSocket{math/display/tag/begin}}
-  \def\eql at tagging@tagend{%
-    \UseTaggingSocket{math/display/tag/end}}
-  \def\eql at tagging@tagsave{%
-    \UseTaggingSocket{math/luamml/mtable/tag/save}}
-  \def\eql at tagging@tagaddbox{%
-    \setbox\z@\copy\eql at tagbox@%
-    \UseTaggingSocket{math/luamml/mtable/tag/set}}
-  \def\eql at tagging@tablesaveinner{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
-  \def\eql at tagging@tableaddinner{%
-    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
-  \def\eql at tagging@tablesavelines{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
-  \def\eql at tagging@tablesavealign{%
-    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
-  \def\eql at tagging@alignleft{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
-  \def\eql at tagging@aligncenter{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
-  \def\eql at tagging@alignright{%
-    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
-  \let\eql at single@doscan\eql at true
-  \let\eql at scan@body\eql at scan@body at rescan
-  \ExplSyntaxOn
-  \def\eql at tagging@start{%
-    \bool_if:NF\l__math_collected_bool{%
-      \toks@\expandafter{\eql at tagging@opt}%
-      \edef\eql at tmp{{\@currenvir}{[\the\toks@] \the\eql at scan@reg@}}%
-      \expandafter\__math_process:nn\eql at tmp
-      \@kernel at math@registered at begin
-      \bool_set_true:N\l__math_collected_bool
-    }%
-  }
-  \def\eql at tagging@end{}
-  \ExplSyntaxOff
-\else
-  \def\eql at tagging@mathsave{}
-  \def\eql at tagging@mathaddlast{}
-  \def\eql at tagging@tagbegin{}
-  \def\eql at tagging@tagend{}
-  \def\eql at tagging@tagsave{}
-  \def\eql at tagging@tagaddbox{}
-  \def\eql at tagging@tablesaveinner{}
-  \def\eql at tagging@tableaddinner{}
-  \def\eql at tagging@tablesavelines{}
-  \def\eql at tagging@tablesavealign{}
-  \def\eql at tagging@alignleft{}
-  \def\eql at tagging@aligncenter{}
-  \def\eql at tagging@alignright{}
-  \def\eql at tagging@start{}
-  \def\eql at tagging@end{}
-\fi
 \let\eql at punct@col\@empty
 \let\eql at punct@line\relax
 \let\eql at punct@block\relax
@@ -297,11 +308,25 @@
 \def\eql at punct@line at set#1{\def\eql at punct@line{#1}\ignorespaces}
 \def\eql at punct@line at setrelax{\let\eql at punct@line\relax\ignorespaces}
 \def\eqnpunctmain{\eql at ifstar@tight\eql at punct@main at setrelax\eql at punct@main at set}
-\def\eql at punct@main at set#1{\eqnlinesset{punct={#1}}\ignorespaces}
-\def\eql at punct@main at setrelax{\eqnlinesset{punct*}\ignorespaces}
+\def\eql at punct@main at set#1{\def\eql at punct@main{#1}\ignorespaces}
+\def\eql at punct@main at setrelax{\let\eql at punct@main\relax\ignorespaces}
 \def\eqnpunct{\eql at ifstar@tight\eql at punct@next at setrelax\eql at punct@next at set}
-\def\eql at punct@next at set#1{\eqnaddopt{punct={#1}}\ignorespaces}
-\def\eql at punct@next at setrelax{\eqnaddopt{punct*}\ignorespaces}
+\def\eql at punct@next at set#1{%
+  \ifmmode
+    \def\eql at punct@col{#1}%
+    \def\eql at punct@line{#1}%
+    \def\eql at punct@block{#1}%
+  \else
+    \eqnaddopt{punct={#1}}%
+  \fi
+  \ignorespaces}
+\def\eql at punct@next at setrelax{%
+  \ifmmode
+    \let\eql at punct@block\relax
+  \else
+    \eqnaddopt{punct*}%
+  \fi
+  \ignorespaces}
 \def\eql at punct@apply at col{%
   \ifx\eql at punct@col\@empty\else
     \eql at punct@sep
@@ -758,15 +783,6 @@
     \global\let\eql at nexttag\@undefined
   \fi
 }
-\def\eql at compose@null{%
-  \ifdefined\eql at nexttag\else
-    \stepcounter{equation}%
-  \fi
-  \ifnum\eql at numbering@target@<\z@
-    \global\let\eql at nextlabel\@undefined
-    \global\let\eql at nexttag\@undefined
-  \fi
-}
 \def\eql at tagbox@make#1{%
   \setbox\eql at tagbox@\hbox{\eql at strut@tag\@lign#1}%
   \eql at tagwidth@\wd\eql at tagbox@
@@ -854,6 +870,10 @@
   \ifcsname eql at numbering@tab@#1\endcsname
     \expandafter\let\expandafter\eql at numbering@mode
       \csname eql at numbering@tab@#1\endcsname
+    \ifx\eql at numbering@mode\eql at numbering@tab at none
+      \let\eql at numbering@mode\eql at numbering@tab at all
+      \let\eql at numbering@active\eql at false
+    \fi
   \else
     \eql at error{numbering mode `#1' unknown: setting to `all'}%
     \let\eql at numbering@mode\eql at numbering@tab at all
@@ -866,9 +886,6 @@
 \def\eql at numbering@mode at sub{%
   \eql at numbering@target@\m at ne
   \let\eql at numbering@subeq at use\eql at true}
-\def\eql at numbering@mode at none{%
-  \eql at numbering@target@\m at ne
-  \let\eql at numbering@active\eql at false}
 \def\eql at numbering@mode at first{%
   \eql at numbering@target@\@ne}
 \def\eql at numbering@mode at last{%
@@ -1408,13 +1425,16 @@
   \advance\abovedisplayskip\eql at abovespace@
   \advance\belowdisplayskip\eql at belowspace@
   \advance\belowdisplayskip\eql at vspaceskip@
-  \abovedisplayshortskip\abovedisplayskip
-  \belowdisplayshortskip\belowdisplayskip
   \count@\prevgraf
   \advance\count@\eql at row@
   \advance\count at -\tw@
   \prevgraf\count@
   \global\eql at skip@mode at leave@\eql at skip@mode at leave@
+  \ifdefined\eql at tagging@on
+    \ifdefined\dollardollar at begin\else
+      \belowdisplayskip-\belowdisplayskip
+    \fi
+  \fi
 }
 \def\eql at display@leave{%
   \let\label\eql at label@org
@@ -1565,8 +1585,10 @@
     \eql at stack@save at reg\eql at line@width@
     \eql at stack@save at reg\eql at line@depth@
     \eql at stack@save at reg\eql at line@height@
+    \eql at stack@save at reg\eql at tagwidth@max@
     \eql at stack@save at reg\eql at numbering@target@
     \eql at stack@save at reg\eql at row@
+    \eql at stack@save at reg\eql at tagrows@
   }%
 }
 \def\eql at stack@save at boxed@{%
@@ -1781,6 +1803,33 @@
     @\ifcase\eql at shape@pos@ shoveleft\or shovecenter\or shoveright\fi
     @notag\endcsname
 }
+\def\eql at adjust@calc{%
+  \ifdefined\eql at flushleft
+    \eql at flushleftmargin@\glueexpr\eql at flushleftmargin@val\relax
+  \else
+    \eql at align@inter@\z@
+    \eql at adjust@tagmargin
+    \ifdefined\eql at paddingmax
+      \eql at marginleft@\z@
+      \eql at marginright@\z@
+    \else
+      \dimen@\displaywidth
+      \advance\dimen at -\eql at totalwidth@
+      \advance\dimen at -\eql at tagmargin@
+      \divide\dimen@\tw@
+      \eql at marginleft@\dimen@
+      \advance\eql at marginleft@-\glueexpr\eql at paddingleft@val\relax
+      \ifdim\eql at marginleft@<\z@
+        \eql at marginleft@\z@
+      \fi
+      \eql at marginright@\dimen@
+      \advance\eql at marginright@-\glueexpr\eql at paddingright@val\relax
+      \ifdim\eql at marginright@<\z@
+        \eql at marginright@\z@
+      \fi
+    \fi
+  \fi
+}
 \def\eql at adjust@center at tagsright@shovecenter at notag{%
   \dimen@\displaywidth
   \advance\dimen at -\eql at fieldwidth@
@@ -2004,6 +2053,35 @@
   \fi
   \eql at display@firstavail at set\z@
 }
+\def\eql at adjust@tagmargin{%
+  \ifdefined\eql at tagmargin@val
+    \eql at tagmargin@\glueexpr\eql at tagmargin@val\relax
+  \else
+    \eql at tagmargin@\eql at tagwidth@max@
+    \ifdim\eql at tagmargin@>\z@
+      \advance\eql at tagmargin@-\eql at tagsepmin@
+    \fi
+  \fi
+  \dimen@\eql at tagrows@\p@
+  \ifnum\eql at totalrows@=\@ne
+    \ifnum\eql at tagrows@=\@ne
+      \advance\dimen at 1sp\relax
+    \fi
+  \fi
+  \ifdim\dimen@>\eql at totalrows@\eql at tagmargin@ratio@\else
+    \eql at tagmargin@\z@
+  \fi
+  \@tempdima\displaywidth
+  \advance\@tempdima-\eql at totalwidth@
+  \advance\@tempdima-\eql at align@inter@\eql at colsepmin@
+  \@tempdimb\@tempdima
+  \advance\@tempdimb-\tw@\eql at tagmargin@
+  \ifdim\@tempdimb>\z@
+    \ifdim\eql at tagmargin@threshold\@tempdima<\@tempdimb
+      \eql at tagmargin@\z@
+    \fi
+  \fi
+}
 \def\eql at adjust@flushleft at shoveleft{%
   \eql at marginleft@\eql at flushleftmargin@
   \advance\eql at marginleft@\eql at shape@amount@
@@ -2189,7 +2267,7 @@
 \def\eql at single@start{%
   \eql at halign@catchprevdepth
   \eql at tagging@start
-  $$%$$
+  \eql at dollardollar@begin
   \eql at numbering@eval at mode
   \let\eql at numbering@subeq at use\eql at false
   \eql at stack@save at single
@@ -2212,7 +2290,7 @@
   \eql at hook@eqout
   \eql at single@end at sel
   \eql at stack@restore
-  $$%$$
+  \eql at dollardollar@end
   \eql at tagging@end
   \eql at halign@leave
 }
@@ -2244,12 +2322,9 @@
   \let\shoveleft\eql at adjust@shoveleft
   \let\shovecenter\eql at adjust@shovecenter
   \let\shoveright\eql at adjust@shoveright
-  \ifdefined\eql at flushleft\else
-    \eql at marginleft@\z@
-    \eql at marginright@\z@
-  \fi
   \eql at adjust@init
   \eql at shape@eval
+  \eql at halign@init{}%
   \eql at row@\@ne
   \setbox\eql at fieldbox@\hbox\bgroup
     \eql at restore@hfuzz
@@ -2266,11 +2341,20 @@
   \eql at fieldwidth@\wd\eql at fieldbox@
   \eql at line@height@\ht\eql at fieldbox@
   \eql at line@depth@\dp\eql at fieldbox@
-  \eql at halign@init{}%
+  \eql at totalwidth@\eql at fieldwidth@
+  \eql at totalrows@\@ne
+  \if at eqnsw
+    \eql at tagbox@make\eql at compose@print
+    \eql at tagrows@\@ne
+  \else
+    \eql at tagwidth@\z@
+    \eql at tagrows@\z@
+  \fi
+  \eql at tagwidth@max@\eql at tagwidth@
+  \eql at adjust@calc
   \halign{##\cr
     \noalign{\eql at halign@before}%
     \if at eqnsw
-      \eql at tagbox@make\eql at compose@print
       \eql at adjust@sel at tag
     \else
       \eql at adjust@sel at notag
@@ -2282,12 +2366,6 @@
   \eql at row@\tw@
   \eql at display@close
 }
-\newcount\eql at column@
-\newcount\eql at totalcolumns@
-\newdimen\eql at totalwidth@
-\newdimen\eql at line@width@
-\newdimen\eql at line@avail@
-\newdimen\eql at line@pos@
 \let\eql at fieldlength@tab\@empty
 \def\eql at fieldlength@save#1{%
   \begingroup
@@ -2322,6 +2400,16 @@
     \global\edef\eql at tagwidth@tab{\the\eql at tagwidth@\eql at tagwidth@tab}%
   \endgroup
 }
+\let\eql at colwidth@tab\@empty
+\def\eql at align@colwidth at get#1{%
+  \ifcase\expandafter#1\eql at colwidth@tab\else\z@\fi
+}
+\def\eql at align@colwidth at save{%
+  \begingroup
+    \let\or\relax
+    \global\edef\eql at colwidth@tab{\or\the\wd\thr@@\eql at colwidth@tab}%
+  \endgroup
+}
 \def\eql at measure@init#1{%
   \measuring at true
   \eql at row@\z@
@@ -2509,7 +2597,7 @@
 \def\eql at multi@main{%
   \eql at halign@catchprevdepth
   \eql at tagging@start
-  $$%$$
+  \eql at dollardollar@begin
   \eql at numbering@eval at mode
   \eql at stack@save at multi
   \ifdefined\eql at subequations@active
@@ -2551,7 +2639,7 @@
     \eql at numbering@subeq at close
   \fi
   \eql at stack@restore
-  $$%$$
+  \eql at dollardollar@end
   \eql at tagging@end
   \eql at halign@leave
 }
@@ -2592,11 +2680,19 @@
 \def\eql at lines@measure at tag{%
   \ifnum\eql at numbering@target@<\z@
     \if at eqnsw
-      \eql at compose@null
+      \eql at tagbox@make\eql at compose@measure
+      \ifdim\eql at tagwidth@>\eql at tagwidth@max@
+        \global\eql at tagwidth@max@\eql at tagwidth@
+      \fi
+      \global\advance\eql at tagrows@\@ne
+    \else
+      \eql at tagwidth@\z@
     \fi
   \fi
 }
 \def\eql at lines@measure{%
+  \eql at tagwidth@max@\z@
+  \eql at tagrows@\z@
   \eql at measure@savecounters
   \setbox\z@\vbox{%
     \eql at numbering@measure at init
@@ -2634,8 +2730,17 @@
     }%
     \global\advance\eql at row@-\tw@
     \eql at numbering@measure at eval
+    \ifnum\eql at numbering@target@>\z@
+      \eql at tagbox@make\eql at compose@measure
+      \global\eql at tagwidth@max@\eql at tagwidth@
+      \global\eql at tagrows@\@ne
+    \fi
   }%
   \eql at totalrows@\eql at row@
+  \ifdefined\eql at numbering@subeq at use
+    \eql at numbering@subeq at test
+  \fi
+  \eql at measure@restorecounters
   \setbox\z@\vbox{%
     \unvbox\z@
     \unpenalty
@@ -2642,10 +2747,6 @@
     \global\setbox\@ne\lastbox
   }%
   \eql at totalwidth@\wd\@ne
-  \ifdefined\eql at numbering@subeq at use
-    \eql at numbering@subeq at test
-  \fi
-  \eql at measure@restorecounters
 }
 \def\eql at lines@print at line@begin{%
   \eql at numbering@print at line@begin
@@ -2669,29 +2770,8 @@
 }
 \def\eql at lines@print{%
   \eql at display@init
-  \ifdefined\eql at flushleft
-  \else
-    \ifdefined\eql at paddingmax
-      \eql at marginleft@\z@
-      \eql at marginright@\z@
-    \else
-      \dimen@\displaywidth
-      \advance\dimen at -\eql at totalwidth@
-      \advance\dimen at -\eql at tagmargin@
-      \divide\dimen@\tw@
-      \eql at marginleft@\dimen@
-      \advance\eql at marginleft@-\glueexpr\eql at paddingleft@val\relax
-      \ifdim\eql at marginleft@<\z@
-        \eql at marginleft@\z@
-      \fi
-      \eql at marginright@\dimen@
-      \advance\eql at marginright@-\glueexpr\eql at paddingright@val\relax
-      \ifdim\eql at marginright@<\z@
-        \eql at marginright@\z@
-      \fi
-    \fi
-  \fi
   \eql at adjust@init
+  \eql at adjust@calc
   \eql at numbering@print at init
   \eql at print@init\eql at lines@print at line@begin
   \eql at let@cr\eql at lines@print at line@end
@@ -2735,36 +2815,147 @@
   }%
   \eql at display@close
 }
-\let\eql at align@margins\eql at true
-\newcount\eql at align@inter@
-\let\eql at colwidth@tab\@empty
-\def\eql at align@colwidth at get#1{%
-  \ifcase\expandafter#1\eql at colwidth@tab\else\z@\fi
-}
-\def\eql at align@colwidth at save{%
-  \begingroup
-    \let\or\relax
-    \global\edef\eql at colwidth@tab{\or\the\wd\thr@@\eql at colwidth@tab}%
-  \endgroup
-}
 \def\eql at align@add at amp#1{\if m#1&\omit\expandafter\eql at align@add at amp\fi}
-\def\eql at align@completerow#1{%
-  \begingroup
-  \count@#1%
+\def\eql at align@completerow{%
+  \count@\eql at totalcolumns@
   \advance\count at -\eql at column@
-\advance\count@\@ne
-  \edef\eql at tmp{\endgroup
+  \advance\count@\@ne
+  \edef\eql at tmp{%
     \expandafter\eql at align@add at amp\romannumeral\number\count@ 000q}%
   \eql at tmp
 }
-\def\eql at align@print at trailright{%
-   &\omit
-    \global\advance\eql at column@\@ne
-    \setbox\eql at fieldbox@\hbox{%
-      \kern-\wd\eql at fieldbox@\box\eql at fieldbox@
+\def\eql at align@measure at line@begin{%
+  \global\eql at column@\z@
+  \eql at numbering@measure at line@begin
+  \eql at hook@linein
+}
+\def\eql at align@measure at field{%
+  \eql at fieldlength@save\eql at column@
+  \kern\wd\eql at fieldbox@
+}
+\def\eql at align@measure at line@end{%
+  \eql at punct@apply at line
+  \eql at hook@lineout
+  &\omit
+  \ifnum\eql at column@>\eql at totalcolumns@
+    \global\eql at totalcolumns@\eql at column@
+  \fi
+  \eql at align@measure at tag
+}
+\def\eql at align@measure at tag{%
+  \ifnum\eql at numbering@target@<\z@
+    \if at eqnsw
+      \eql at tagbox@make\eql at compose@measure
+      \ifdim\eql at tagwidth@>\eql at tagwidth@max@
+        \global\eql at tagwidth@max@\eql at tagwidth@
+      \fi
+      \global\advance\eql at tagrows@\@ne
+    \else
+      \eql at tagwidth@\z@
+    \fi
+    \eql at tagwidth@save
+  \fi
+}
+\def\eql at align@measure{%
+  \eql at totalcolumns@\z@
+  \eql at tagwidth@max@\z@
+  \let\eql at tagwidth@tab\@empty
+  \let\eql at fieldlength@tab\@empty
+  \eql at tagrows@\z@
+  \eql at measure@savecounters
+  \setbox\z@\vbox{%
+    \eql at numbering@measure at init
+    \eql at measure@init\eql at align@measure at line@begin
+    \eql at let@cr\eql at align@measure at line@end
+    \tabskip\z at skip
+    \halign{%
+      &%
+        \global\advance\eql at column@\@ne
+        \hfil
+        \global\setbox\eql at fieldbox@\hbox{%
+          \@lign
+          $\m at th\displaystyle
+            \eql at hook@colin
+            ##%
+            \eql at class@innerleft
+            \eql at hook@innerleft
+          $%
+        }%
+        \global\eql at fieldwidth@\wd\eql at fieldbox@
+        \eql at align@measure at field
+      &%
+        \global\advance\eql at column@\@ne
+        \setbox\eql at fieldbox@\hbox{%
+          \@lign
+          $\m at th\displaystyle
+            \eql at hook@innerright
+            \eql at class@innerright at sel
+            ##%
+            \eql at punct@apply at col
+            \eql at hook@colout
+          $%
+        }%
+        \eql at align@measure at field
+        \hfil
+      \crcr
+      \noalign{%
+        \eql at hook@blockbefore
+      }%
+      \eql at hook@blockin
+      \eql at scan@body
+      \ifvmode\else
+        \eql at punct@apply at block
+        \eql at hook@blockout
+        \eql at align@measure at line@end
+        \cr
+      \fi
+      \noalign{%
+        \eql at hook@blockafter
+      }%
+      \eql at align@completerow
+      \cr
     }%
-    \eql at align@print at field
+    \global\advance\eql at row@-\tw@
+    \eql at numbering@measure at eval
+    \ifnum\eql at numbering@target@>\z@
+      \eql at tagbox@make\eql at compose@measure
+      \global\eql at tagwidth@max@\eql at tagwidth@
+      \global\eql at tagrows@\@ne
+      \eql at tagwidth@savezero
+    \fi
+  }%
+  \eql at totalrows@\eql at row@
+  \ifdefined\eql at numbering@subeq at use
+    \eql at numbering@subeq at test
+  \fi
+  \eql at measure@restorecounters
+  \setbox\z@\vbox{%
+    \unvbox\z@
+    \unpenalty
+    \global\setbox\@ne\lastbox
+  }%
+  \eql at totalwidth@\wd\@ne
+  \let\eql at colwidth@tab\@empty
+  \loop
+    \setbox\@ne\hbox{%
+      \unhbox\@ne
+      \unskip
+      \global\setbox\thr@@\lastbox
+    }%
+  \ifhbox\thr@@
+    \eql at align@colwidth at save
+  \repeat
 }
+\def\eql at align@print at line@begin{%
+  \global\eql at column@\z@
+  \global\eql at line@pos@\eql at marginleft@
+  \global\eql at line@width@\z@
+  \global\eql at line@avail@\eql at totalwidth@
+  \global\eql at line@height@\z@
+  \global\eql at line@depth@\z@
+  \eql at numbering@print at line@begin
+  \eql at hook@linein
+}
 \def\eql at align@print at field{%
   \dimen@\eql at align@colwidth at get\eql at column@\relax
   \ifdim\wd\eql at fieldbox@>\z@
@@ -2804,15 +2995,13 @@
     \kern\dimen@
   \fi
 }
-\def\eql at align@print at line@begin{%
-  \global\eql at column@\z@
-  \global\eql at line@pos@\eql at marginleft@
-  \global\eql at line@width@\z@
-  \global\eql at line@avail@\eql at totalwidth@
-  \global\eql at line@height@\z@
-  \global\eql at line@depth@\z@
-  \eql at numbering@print at line@begin
-  \eql at hook@linein
+\def\eql at align@print at trailright{%
+   &\omit
+    \global\advance\eql at column@\@ne
+    \setbox\eql at fieldbox@\hbox{%
+      \kern-\wd\eql at fieldbox@\box\eql at fieldbox@
+    }%
+    \eql at align@print at field
 }
 \def\eql at align@print at line@end{%
   \eql at punct@apply at line
@@ -2820,10 +3009,10 @@
   \ifodd\eql at column@
     \expandafter\eql at align@print at trailright
   \fi
-  \eql at align@completerow\eql at totalcolumns@
-  \eql at align@print at line
+  \eql at align@completerow
+  \eql at align@print at tag
 }
-\def\eql at align@print at line{%
+\def\eql at align@print at tag{%
   \dimen@\eql at totalwidth@
   \advance\dimen@\eql at colsep@
   \kern-\dimen@
@@ -2907,123 +3096,8 @@
   }%
   \eql at display@close
 }
-\def\eql at align@measure at line@begin{%
-  \global\eql at column@\z@
-  \eql at numbering@measure at line@begin
-  \eql at hook@linein
-}
-\def\eql at align@measure at field{%
-  \eql at fieldlength@save\eql at column@
-  \kern\wd\eql at fieldbox@
-}
-\def\eql at align@measure at line@end{%
-  \eql at punct@apply at line
-  \eql at hook@lineout
-  &\omit
-  \ifnum\eql at column@>\eql at totalcolumns@
-    \global\eql at totalcolumns@\eql at column@
-  \fi
-  \eql at align@measure at tag
-}
-\def\eql at align@measure at tag{%
-  \ifnum\eql at numbering@target@<\z@
-    \if at eqnsw
-      \eql at tagbox@make\eql at compose@measure
-    \else
-      \eql at tagwidth@\z@
-    \fi
-    \eql at tagwidth@save
-  \fi
-}
-\def\eql at align@measure{%
-  \eql at totalcolumns@\z@
-  \let\eql at tagwidth@tab\@empty
-  \let\eql at fieldlength@tab\@empty
-  \eql at measure@savecounters
-  \setbox\z@\vbox{%
-    \eql at numbering@measure at init
-    \eql at measure@init\eql at align@measure at line@begin
-    \eql at let@cr\eql at align@measure at line@end
-    \tabskip\z at skip
-    \halign{%
-      &%
-        \global\advance\eql at column@\@ne
-        \hfil
-        \global\setbox\eql at fieldbox@\hbox{%
-          \@lign
-          $\m at th\displaystyle
-            \eql at hook@colin
-            ##%
-            \eql at class@innerleft
-            \eql at hook@innerleft
-          $%
-        }%
-        \global\eql at fieldwidth@\wd\eql at fieldbox@
-        \eql at align@measure at field
-      &%
-        \global\advance\eql at column@\@ne
-        \setbox\eql at fieldbox@\hbox{%
-          \@lign
-          $\m at th\displaystyle
-            \eql at hook@innerright
-            \eql at class@innerright at sel
-            ##%
-            \eql at punct@apply at col
-            \eql at hook@colout
-          $%
-        }%
-        \eql at align@measure at field
-        \hfil
-      \crcr
-      \noalign{%
-        \eql at hook@blockbefore
-      }%
-      \eql at hook@blockin
-      \eql at scan@body
-      \ifvmode\else
-        \eql at punct@apply at block
-        \eql at hook@blockout
-        \eql at align@measure at line@end
-        \cr
-      \fi
-      \noalign{%
-        \eql at hook@blockafter
-      }%
-      \eql at align@completerow\eql at totalcolumns@
-      \cr
-    }%
-    \global\advance\eql at row@-\tw@
-    \eql at numbering@measure at eval
-    \ifnum\eql at numbering@target@>\z@
-      \eql at tagbox@make\eql at compose@measure
-      \eql at tagwidth@savezero
-    \fi
-  }%
-  \eql at totalrows@\eql at row@
-  \ifdefined\eql at numbering@subeq at use
-    \eql at numbering@subeq at test
-  \fi
-  \eql at measure@restorecounters
-  \setbox\z@\vbox{%
-    \unvbox\z@
-    \unpenalty
-    \global\setbox\@ne\lastbox
-  }%
-  \eql at totalwidth@\wd\@ne
-  \let\eql at colwidth@tab\@empty
-  \loop
-    \setbox\@ne\hbox{%
-      \unhbox\@ne
-      \unskip
-      \global\setbox\thr@@\lastbox
-    }%
-  \ifhbox\thr@@
-    \eql at align@colwidth at save
-  \repeat
-}
 \def\eql at align@adjust{%
   \eql at colsepmin@\glueexpr\eql at colsepmin@val\relax
-  \eql at colsepmax@\glueexpr\eql at colsepmax@val\relax
   \ifodd\eql at totalcolumns@
     \advance\eql at totalcolumns@\@ne
   \fi
@@ -3033,10 +3107,22 @@
   \eql at align@inter@\eql at totalcolumns@
   \divide\eql at align@inter@\tw@
   \advance\eql at align@inter@\m at ne
+  \ifdefined\eql at flushleft
+    \eql at flushleftmargin@\glueexpr\eql at flushleftmargin@val\relax
+  \else
+    \eql at adjust@tagmargin
+  \fi
   \eql at colsep@\displaywidth
   \advance\eql at colsep@-\eql at totalwidth@
   \ifdefined\eql at flushleft
     \advance\eql at colsep@-\eql at flushleftmargin@
+  \else
+    \advance\eql at colsep@-\eql at tagmargin@
+    \ifdefined\eql at align@margins\else
+      \ifdim\eql at tagmargin@>\z@
+        \advance\eql at colsep@-\eql at tagsepmin@
+      \fi
+    \fi
   \fi
   \count@\eql at align@inter@
   \ifdefined\eql at align@margins
@@ -3050,8 +3136,9 @@
   \ifdim\eql at colsep@<\eql at colsepmin@
     \eql at colsep@\eql at colsepmin@
   \else
-    \ifdim\eql at colsep@>\eql at colsepmax@
-      \eql at colsep@\eql at colsepmax@
+    \dimen@\glueexpr\eql at colsepmax@val\relax
+    \ifdim\eql at colsep@>\dimen@
+      \eql at colsep@\dimen@
     \fi
   \fi
   \ifdefined\eql at flushleft
@@ -3075,15 +3162,23 @@
       \advance\eql at marginleft@-\eql at totalwidth@
       \advance\eql at marginleft@-\eql at align@inter@\eql at colsep@
       \ifdim\eql at marginleft@<\eql at tagmargin@
-        \ifdim\ifdefined\eql at tagsleft\eql at marginleft@\else-\p@\fi<\z@
-          \eql at marginleft@\z@
-        \fi
+        \eql at marginleft@\z@
       \else
         \advance\eql at marginleft@-\eql at tagmargin@
         \divide\eql at marginleft@\tw@
       \fi
+      \ifdefined\eql at tagsleft
+        \advance\eql at marginleft@\eql at tagmargin@
+      \fi
     \else
-      \eql at marginleft@\z@
+      \ifdefined\eql at tagsleft
+        \eql at marginleft@\eql at tagmargin@
+        \ifdim\eql at tagmargin@>\z@
+          \advance\eql at marginleft@\eql at tagsepmin@
+        \fi
+      \else
+        \eql at marginleft@\z@
+      \fi
     \fi
   \fi
   \ifdefined\eql at tagsleft
@@ -3091,6 +3186,7 @@
   \else
     \let\eql at align@adjust at test\eql at align@adjust at test@tagright
   \fi
+  \eql at row@\eql at totalrows@
   \loop\ifnum\eql at row@>\z@
     \ifnum\eql at numbering@target@<\z@
       \eql at tagwidth@\eql at tagwidth@get\eql at row@\relax
@@ -3100,7 +3196,7 @@
       \fi
     \fi
     \ifdim\eql at tagwidth@>\z@
-      \eql at align@adjust at width
+      \eql at align@adjust at calc
       \eql at align@adjust at test
     \fi
     \advance\eql at row@\m at ne
@@ -3108,7 +3204,7 @@
   \advance\eql at totalwidth@\eql at align@inter@\eql at colsep@
   \advance\eql at totalwidth@\eql at marginleft@
 }
-\def\eql at align@adjust at width{%
+\def\eql at align@adjust at calc{%
   \eql at line@pos@\z@
   \eql at column@\z@
   \eql at line@avail@\eql at totalwidth@
@@ -3117,13 +3213,13 @@
   \@tempcntb\z@
   \edef\@tempb{\eql at fieldlength@get\eql at row@}%
   \@for\@tempa:=\@tempb\do
-    \eql at align@adjust at width@col
+    \eql at align@adjust at calc@col
   \advance\@tempcnta\m at ne
   \divide\@tempcnta\tw@
   \advance\@tempcntb\m at ne
   \divide\@tempcntb\tw@
 }
-\def\eql at align@adjust at width@col{%
+\def\eql at align@adjust at calc@col{%
   \advance\eql at column@\@ne
   \@tempdima\@tempa\relax
   \dimen@\eql at align@colwidth at get\eql at column@\relax
@@ -3146,99 +3242,93 @@
   \fi
   \advance\eql at line@pos@\dimen@
 }
-
 \def\eql at align@adjust at test@tagright{%
-  \@tempdima\eql at line@width@
-  \advance\@tempdima\eql at tagwidth@
+  \@tempdima\displaywidth
+  \advance\@tempdima-\eql at line@width@
+  \advance\@tempdima-\eql at tagwidth@
   \dimen@\eql at marginleft@
-  \advance\dimen@\@tempdima
   \advance\dimen@\@tempcntb\eql at colsep@
-  \ifdim\dimen@>\displaywidth
-    \eql at align@adjust at modify@tagright
+  \ifdim\dimen@>\@tempdima
+    \dimen@\@tempcntb\eql at colsepmin@
+    \ifdefined\eql at flushleft
+      \advance\dimen@\eql at flushleftmarginmin@
+    \fi
+    \ifdim\dimen@>\@tempdima\else
+      \eql at align@adjust at modify@tagright
+    \fi
   \fi
 }
 \def\eql at align@adjust at modify@tagright{%
-  \dimen@\eql at colsepmin@
-  \multiply\dimen@\@tempcntb
-  \advance\dimen@\@tempdima
-  \ifdefined\eql at flushleft
-    \advance\dimen@\eql at flushleftmarginmin@
-  \fi
-  \ifdim\dimen@>\displaywidth\else
-    \ifnum\@tempcntb>\z@
-      \dimen@\displaywidth
-      \advance\dimen at -\@tempdima
-      \count@\@tempcntb
-      \ifdefined\eql at flushleft
-        \advance\dimen at -\eql at marginleft@
-      \else
-        \ifdefined\eql at align@margins
-          \advance\count@\@ne
-        \fi
+  \ifnum\@tempcntb>\z@
+    \dimen@\@tempdima
+    \count@\@tempcntb
+    \ifdefined\eql at flushleft
+      \advance\dimen at -\eql at marginleft@
+    \else
+      \ifdefined\eql at align@margins
+        \advance\count@\@ne
       \fi
-      \divide\dimen@\count@
-      \ifdim\dimen@<\eql at colsep@
-        \ifdim\dimen@<\eql at colsepmin@
-          \dimen@\eql at colsepmin@
-        \fi
-        \eql at colsep@\dimen@
+    \fi
+    \divide\dimen@\count@
+    \ifdim\dimen@<\eql at colsep@
+      \ifdim\dimen@<\eql at colsepmin@
+        \dimen@\eql at colsepmin@
       \fi
+      \eql at colsep@\dimen@
     \fi
-    \dimen@\displaywidth
-    \advance\dimen at -\@tempdima
-    \advance\dimen at -\@tempcntb\eql at colsep@
-    \ifdim\dimen@<\eql at marginleft@
-      \eql at marginleft@\dimen@
-    \fi
   \fi
+  \dimen@\@tempdima
+  \advance\dimen at -\@tempcntb\eql at colsep@
+  \ifdim\dimen@<\eql at marginleft@
+    \eql at marginleft@\dimen@
+  \fi
 }
 \def\eql at align@adjust at test@tagleft{%
   \count@\eql at align@inter@
   \advance\count at -\@tempcnta
-  \@tempdima-\eql at line@avail@
-  \advance\@tempdima\eql at tagwidth@
+  \@tempdima\eql at tagwidth@
+  \advance\@tempdima-\eql at line@avail@
   \dimen@\eql at marginleft@
   \advance\dimen@\@tempcnta\eql at colsep@
   \ifdim\dimen@<\@tempdima
-    \eql at align@adjust at modify@tagleft
+    \ifdefined\eql at flushleft
+      \dimen@\eql at flushleftmarginmax@
+    \else
+      \dimen@\displaywidth
+    \fi
+    \ifdim\dimen@>\eql at tagwidth@
+      \dimen@\count@\eql at colsepmin@
+      \advance\dimen@\eql at totalwidth@
+      \advance\dimen@\@tempdima
+      \ifdim\dimen@>\displaywidth\else
+        \eql at align@adjust at modify@tagleft
+      \fi
+    \fi
   \fi
 }
 \def\eql at align@adjust at modify@tagleft{%
-  \ifdefined\eql at flushleft
-    \dimen@\eql at flushleftmarginmax@
-  \else
+  \ifnum\count@>\z@
     \dimen@\displaywidth
-  \fi
-  \ifdim\dimen@>\eql at tagwidth@
-    \dimen@\eql at colsepmin@
-    \multiply\dimen@\count@
-    \advance\dimen@\eql at totalwidth@
-    \advance\dimen@\@tempdima
-    \ifdim\dimen@>\displaywidth\else
-      \ifnum\count@>0
-        \dimen@\displaywidth
-        \advance\dimen at -\eql at totalwidth@
-        \advance\dimen at -\@tempdima
-        \ifdefined\eql at align@margins
-          \advance\count@\@ne
-        \fi
-        \divide\dimen@\count@
-        \ifdim\dimen@<\eql at colsep@
-          \ifdim\dimen@<\eql at colsepmin@
-            \dimen@\eql at colsepmin@
-          \fi
-          \advance\dimen at -\eql at colsep@
-          \advance\eql at marginleft@-\eql at align@inter@\dimen@
-          \advance\eql at colsep@\dimen@
-        \fi
+    \advance\dimen at -\eql at totalwidth@
+    \advance\dimen at -\@tempdima
+    \ifdefined\eql at align@margins
+      \advance\count@\@ne
+    \fi
+    \divide\dimen@\count@
+    \ifdim\dimen@<\eql at colsep@
+      \ifdim\dimen@<\eql at colsepmin@
+        \dimen@\eql at colsepmin@
       \fi
-      \dimen at -\@tempcnta\eql at colsep@
-      \advance\dimen@\@tempdima
-      \ifdim\dimen@>\eql at marginleft@
-        \eql at marginleft@\dimen@
-      \fi
+      \advance\dimen at -\eql at colsep@
+      \advance\eql at marginleft@-\eql at align@inter@\dimen@
+      \advance\eql at colsep@\dimen@
     \fi
   \fi
+  \dimen at -\@tempcnta\eql at colsep@
+  \advance\dimen@\@tempdima
+  \ifdim\dimen@>\eql at marginleft@
+    \eql at marginleft@\dimen@
+  \fi
 }
 \newtoks\eql at scan@reg@
 \def\eql at scan@body at dump{\the\eql at scan@reg@}
@@ -3245,7 +3335,7 @@
 \def\eql at scan@body at rescan{%
   \expandafter\scantokens\expandafter{\the\eql at scan@reg@}}
 \let\eql at scan@body\eql at scan@body at dump
-\def\eql at scan@addto#1{\eql at scan@reg@\expandafter{\the\eql at scan@reg@#1}}
+\long\def\eql at scan@addto#1{\eql at scan@reg@\expandafter{\the\eql at scan@reg@#1}}
 \def\eql at scan@env#1{%
   \def\eql at scan@end{#1\expandafter\end\expandafter{\@currenvir}}%
   \eql at scan@reg@{}\def\eql at scan@stack{b}%
@@ -3254,9 +3344,6 @@
   \expandafter\let\eql at scan@iterate\eql at scan@env at iterate
   \eql at scan@iterate
 }
-\def\eql at scan@env at count#1\begin#2{%
-  \ifx\end#2\else b\expandafter\eql at scan@env at count\fi
-}
 \def\eql at scan@env at iterate#1\end#2{%
   \edef\eql at scan@stack{%
     \eql at scan@env at count#1\begin\end\expandafter\@gobble\eql at scan@stack}%
@@ -3270,6 +3357,9 @@
     \expandafter\eql at scan@iterate
   \fi
 }
+\long\def\eql at scan@env at count#1\begin#2{%
+  \ifx\end#2\else b\expandafter\eql at scan@env at count\fi
+}
 \def\eql at scan@env at cancel{%
   \@namedef{end\@currenvir}{\ignorespacesafterend}%
 }
@@ -3280,9 +3370,6 @@
   \let\[\eql at scan@sqr at iterate%\]
   \[%\]
 }
-\def\eql at scan@sqr at count#1\[#2{%\]
-  \ifx\]#2\else b\expandafter\eql at scan@sqr at count\fi
-}
 \def\eql at scan@sqr at iterate#1\]{%
   \edef\eql at scan@stack{%
     \eql at scan@sqr at count#1\[\]\expandafter\@gobble\eql at scan@stack}%
@@ -3295,6 +3382,9 @@
     \expandafter\[%\]
   \fi
 }
+\long\def\eql at scan@sqr at count#1\[#2{%\]
+  \ifx\]#2\else b\expandafter\eql at scan@sqr at count\fi
+}
 \def\eql at scan@sqrang at cancel{\expandafter\ignorespaces\@gobble}
 \def\eql at scan@ang#1{%
   \def\eql at scan@end{#1\>}%
@@ -3303,9 +3393,6 @@
   \let\<\eql at scan@ang at iterate%\>
   \<%\>
 }
-\def\eql at scan@ang at count#1\<#2{%\>
-  \ifx\>#2\else b\expandafter\eql at scan@ang at count\fi
-}
 \def\eql at scan@ang at iterate#1\>{%
   \edef\eql at scan@stack{%
     \eql at scan@ang at count#1\<\>\expandafter\@gobble\eql at scan@stack}%
@@ -3318,6 +3405,9 @@
     \expandafter\<%\>
   \fi
 }
+\long\def\eql at scan@ang at count#1\<#2{%\>
+  \ifx\>#2\else b\expandafter\eql at scan@ang at count\fi
+}
 \def\eql at equations@testall{\eql at equations@testtilde}
 \def\eql at equations@testtilde#1{%
   \eql at ifnextgobble@tight~%
@@ -3354,6 +3444,7 @@
   \let\eql at punct@block\eql at punct@main
   \let\eql at punct@main\relax
   \eql at indent@\glueexpr\eql at indent@val\relax
+  \eql at tagsepmin@\glueexpr\eql at tagsepmin@val\relax
 }
 \newenvironment{equations}{%
   \ifmmode
@@ -3376,7 +3467,6 @@
   \fi
 }
 \newenvironment{equations at sqr}{}{}
-\def\eql at equations@sqr at opt{equation,nonumber}
 \protected\def\eql at equations@sqr at open{%
   \ifmmode
     \eql at error@mathmode{\string\[...\string\]}%
@@ -3388,8 +3478,20 @@
       \expandafter\eql at equations@sqr at start
   \fi
 }
+\def\eql at equations@sqr at start{%
+  \eql at equations@processopt
+  \ifdefined\eql at equations@main
+    \expandafter\eql at scan@sqr\expandafter\eql at equations@main
+  \else
+    \expandafter\eql at single@start
+  \fi
+}
+\protected\def\eql at equations@sqr at close{%
+  \eql at equations@end
+  \end{equations at sqr}%
+  \ignorespaces
+}
 \newenvironment{equations at ang}{}{}
-\def\eql at equations@ang at opt{align,nonumber}
 \protected\def\eql at equations@ang at open{%
   \ifmmode
     \eql at error@mathmode{\string\<...\string\>}%
@@ -3401,14 +3503,6 @@
       \expandafter\eql at equations@ang at start
   \fi
 }
-\def\eql at equations@sqr at start{%
-  \eql at equations@processopt
-  \ifdefined\eql at equations@main
-    \expandafter\eql at scan@sqr\expandafter\eql at equations@main
-  \else
-    \expandafter\eql at single@start
-  \fi
-}
 \def\eql at equations@ang at start{%
   \eql at equations@processopt
   \ifdefined\eql at equations@main
@@ -3417,11 +3511,6 @@
     \expandafter\eql at single@start
   \fi
 }
-\protected\def\eql at equations@sqr at close{%
-  \eql at equations@end
-  \end{equations at sqr}%
-  \ignorespaces
-}
 \protected\def\eql at equations@ang at close{%
   \eql at equations@end
   \end{equations at ang}%
@@ -3519,8 +3608,13 @@
 \newcommand{\eqnaddopt}[1]{%
   \expandafter\def\expandafter\eql at nextopt\expandafter{\eql at nextopt,#1}}
 \def\eql at defaults@classic{%
+  \def\eql at tagsepmin@val{.5\fontdimen6\textfont\tw@}%
   \def\eql at colsepmax@val{.5\maxdimen}%
   \def\eql at spread{\jot}%
+  \let\eql at tagmargin@val\@undefined
+  \eql at tagmargin@ratio@\p@
+  \def\eql at tagmargin@threshold{0.5}%
+  \def\eql at flushleftmargin@val{\leftmargini}%
   \let\eql at display@height\@undefined
   \let\eql at display@depth\@undefined
   \eql at skip@mode at short@\tw@
@@ -3545,8 +3639,13 @@
   \def\eql at skip@tag at below{\z at skip}%
 }
 \def\eql at defaults@eqnlines{%
+  \def\eql at tagsepmin@val{.5em}%
   \def\eql at colsepmax@val{2em}%
   \def\eql at spread{0.2\normalbaselineskip}%
+  \let\eql at tagmargin@val\@undefined
+  \eql at tagmargin@ratio at .334\p@
+  \def\eql at tagmargin@threshold{0.5}%
+  \def\eql at flushleftmargin@val{\leftmargini}%
   \def\eql at display@height{\ht\eql at strutbox@}%
   \def\eql at display@depth{\dp\eql at strutbox@}%
   \eql at skip@mode at short@\@ne
@@ -3557,11 +3656,11 @@
     \@plus0.25\normalbaselineskip\@minus0.4\normalbaselineskip}%
   \let\eql at skip@long at below\eql at skip@long at above
   \def\eql at skip@short at above{0.0\normalbaselineskip
-    \@plus0.2\normalbaselineskip}%
+    \@plus0.25\normalbaselineskip}%
   \def\eql at skip@short at below{0.0\normalbaselineskip
     \@plus0.25\normalbaselineskip}%
-  \def\eql at skip@med at above{0.375\normalbaselineskip
-    \@plus0.225\normalbaselineskip\@minus0.2\normalbaselineskip}%
+  \def\eql at skip@med at above{0.4\normalbaselineskip
+    \@plus0.2\normalbaselineskip\@minus0.2\normalbaselineskip}%
   \let\eql at skip@med at below\eql at skip@med at above
   \def\eql at skip@cont at above{\z at skip}%
   \def\eql at skip@cont at below{\eql at skip@long at below}%
@@ -3774,10 +3873,17 @@
 \eql at define@key\eql at keycat{tag}{\eql at blocktag@set{#1}}
 \eql at define@key\eql at keycat{tag*}{\eql at blocktag@setstar{#1}}
 \def\eql at keycat{equations,setup}
-\eql at define@key\eql at keycat{tagmargin}{\eql at tagmargin@\glueexpr#1\relax}
-\eql at define@key\eql at keycat{tagmargin*}{\settowidth\eql at tagmargin@{#1}}
-\eql at define@key\eql at keycat{mintagsep}{\eql at tagsepmin@\glueexpr#1\relax}
-\eql at define@key\eql at keycat{mintagwidth}{\eql at tagwidthmin@\glueexpr#1\relax}
+\eql at define@key\eql at keycat{tagmargin}{\def\eql at tagmargin@val{#1}}
+\eql at define@key\eql at keycat{tagmargin*}{%
+  \settowidth\dimen@{#1}\edef\eql at tagmargin@val{\the\dimen@}}
+\eql at define@key\eql at keycat{tagmargincalc}[]{\let\eql at tagmargin@val\@undefined}
+\eql at define@key\eql at keycat{tagmarginratio}{%
+  \eql at tagmargin@ratio@\dimexpr#1pt\relax}
+\eql at define@key\eql at keycat{tagmarginthreshold}{%
+  \def\eql at tagmargin@threshold{#1}}
+\eql at define@key\eql at keycat{mintagsep}{\def\eql at tagsepmin@val{#1}}
+\eql at define@key\eql at keycat{mintagwidth}{%
+  \settowidth\dimen@{#1}\edef\eql at tagsepmin@val{\the\dimen@}}
 \eql at define@key\eql at keycat{mintagwidth*}{\settowidth\eql at tagwidthmin@{#1}}
 \eql at define@key{setup}{taglayout}{\eql at tag@setbox{#1}}
 \eql at define@key{setup}{taglayout*}{\eql at tag@setbox@{#1}}
@@ -3807,8 +3913,9 @@
   {{left,l}{\let\eql at flushleft\eql at true}}}}
 \eql at define@key\eql at keycat{center}[]{\let\eql at flushleft\eql at false}
 \eql at define@key\eql at keycat{flushleft,left}[]{\let\eql at flushleft\eql at true}
-\eql at define@key\eql at keycat{leftmargin}{%
-  \eql at flushleftmargin@\glueexpr#1\relax}
+\eql at define@key\eql at keycat{leftmargin}{\def\eql at flushleftmargin@val{#1}}
+\eql at define@key\eql at keycat{leftmargin*}{%
+  \settowidth\dimen@{#1}\edef\eql at flushleftmargin@val{\the\dimen@}}
 \eql at define@key\eql at keycat{minleftmargin}{%
   \eql at flushleftmarginmin@\glueexpr#1\relax}
 \eql at define@key\eql at keycat{maxleftmargin}{%
@@ -4173,6 +4280,8 @@
 \newcommand{\eqnlinesset}[1]{%
   \eql at setkeys{setup}{#1}}
 \let\eql at error@packageoption\@gobble
+\DeclareOption{leqno}{\eqnlinesset{tagsleft}}
+\DeclareOption{fleqn}{\eqnlinesset{left}}
 \DeclareOption*{\expandafter\eqnlinesset\expandafter{\CurrentOption}}
 \ProcessOptions
 \def\eql at error@packageoption#1{%



More information about the tex-live-commits mailing list.