%
% \iffalse meta-comment
%
% eqnlines.dtx Copyright (C) 2024-2025 Niklas Beisert
%
% Based on the latex package amsmath:
% Copyright (C) 1995, 2000, 2013 American Mathematical Society.
% Copyright (C) 2016-2024 LaTeX Project and American Mathematical Society.
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Niklas Beisert.
%
% This work consists of the files eqnlines.dtx and eqnlines.ins
% and the derived files eqnlines.sty.
%
%<package|sample>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<package&!dev>\ProvidesPackage{eqnlines}[2025/02/25 v0.5 Single- and multi-line equations]
%<package&dev>\ProvidesPackage{eqnlines-dev}[2025/02/25 v0.5 Single- and multi-line equations (development)]
%<*driver>
\def\thedate#1{2025/02/25}\def\theversion#1{v0.5}
\ProvidesFile{eqnlines.dtx}[\thedate{} \theversion{} eqnlines reference manual file]
\PassOptionsToClass{10pt,a4paper}{article}
\documentclass{ltxdoc}

\usepackage[margin=35mm]{geometry}
\usepackage[hyperindex=false]{hyperref}
\usepackage{hyperxmp}
\usepackage[usenames]{color}
\usepackage{amssymb}

\AddToHook{begindocument/before}{\hypersetup{colorlinks=false}}
\hypersetup{urlbordercolor={.5 1 1}}
\hypersetup{linkbordercolor={1 .7 .7}}
\AddToHook{begindocument/before}{\hypersetup{pdfstartview=FitH}}
\hypersetup{pdfsource={}}
\hypersetup{pdflang={en-UK}}
\hypersetup{pdfurl={https://ctan.org/pkg/eqnlines}}
\hypersetup{pdfcopyright={Copyright 2024-2025 Niklas Beisert.
  This work may be distributed and/or modified under the
  conditions of the LaTeX Project Public License, either version 1.3
  of this license or (at your option) any later version.}}
\hypersetup{pdflicenseurl={https://www.latex-project.org/lppl.txt}}
\hypersetup{pdfcontactaddress={ETH Zurich, ITP, HIT K,
  Wolfgang-Pauli-Strasse 27}}
\hypersetup{pdfcontactpostcode={8093}}
\hypersetup{pdfcontactcity={Zurich}}
\hypersetup{pdfcontactcountry={Switzerland}}
\hypersetup{pdfcontactemail={nbeisert@itp.phys.ethz.ch}}
\hypersetup{pdfcontacturl={https://people.phys.ethz.ch/\xmptilde nbeisert/}}

\newcommand{\TODO}{\textbf{\textcolor{red}{TODO:}} }

\newcommand{\markpkg}[1]{\textsf{#1}}
\newcommand{\secref}[1]{\hyperref[#1]{section \ref*{#1}}}
\newcommand{\ctanref}[2]{\href{https://ctan.org/#1}{#2}}
\newcommand{\ctanpkg}[1]{\ctanref{pkg/#1}{\markpkg{#1}}}

\RenewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = ,
  idxgroup = LaTeX commands\actualchar\LaTeX{} commands ,
  printtype =
  ]{Macro}{macro}
\RenewDocElement[macrolike = false ,
  toplevel = false,
  idxtype = env. ,
  idxgroup = Package environments,
  printtype = \textit{env.}
  ]{Env}{environment}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = ,
  idxgroup = Package commands,
  printtype =
  ]{InterfaceMacro}{imacro}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = ,
  idxgroup = Package commands (obsolete),
  printtype =
  ]{ObsoleteInterfaceMacro}{omacro}
\NewDocElement[macrolike = false ,
  toplevel = false,
  idxtype = key ,
  idxgroup = Package keys ,
  printtype = \textit{key}
  ]{Key}{key}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = counter ,
  idxgroup = TeX counters\actualchar \protect\TeX{} counters ,
  printtype = \textit{counter}
  ]{TeXCounter}{tcounter}
\NewDocElement[macrolike = false ,
  toplevel = false,
  idxtype = counter ,
  idxgroup = LaTeX counters\actualchar \LaTeX{} counters ,
  printtype = \textit{counter}
  ]{LaTeXCounter}{lcounter}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = skip ,
  idxgroup = LaTeX length\actualchar \LaTeX{} length (skip) ,
  printtype = \textit{skip}
  ]{LaTeXSkip}{lskip}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = dimen ,
  idxgroup = LaTeX length\actualchar \LaTeX{} length (dimen) ,
  printtype = \textit{dimen}
  ]{LaTeXDimen}{ldimen}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = box ,
  idxgroup = LaTeX box\actualchar \LaTeX{} box ,
  printtype = \textit{box}
  ]{LaTeXBox}{lbox}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = bool ,
  idxgroup = eqnlines bool\actualchar eqnlines bool ,
  printtype = \textit{bool}
  ]{eqnlinesBool}{ebool}
\NewDocElement[macrolike = true ,
  toplevel = false,
  idxtype = bool ,
  idxgroup = LaTeX conditional\actualchar \LaTeX{} conditional ,
  printtype = \textit{bool}
  ]{LaTeXConditional}{lcond}

\parskip1ex
\parindent0pt
\let\olditemize\itemize
\def\itemize{\olditemize\parskip0pt}

\begin{document}

\title{The \markpkg{eqnlines} Package}
\hypersetup{pdftitle={The eqnlines Package}}
\author{Niklas Beisert\\[2ex]
  Institut f\"ur Theoretische Physik\\
  Eidgen\"ossische Technische Hochschule Z\"urich\\
  Wolfgang-Pauli-Strasse 27, 8093 Z\"urich, Switzerland\\[1ex]
  \href{mailto:nbeisert@itp.phys.ethz.ch}
  {\texttt{nbeisert@itp.phys.ethz.ch}}}
\hypersetup{pdfauthor={Niklas Beisert}}
\hypersetup{pdfsubject={Manual for the LaTeX2e Package eqnlines}}
\date{\thedate{}, \theversion{}}
\maketitle

\begin{center}
-- preview version --
\end{center}

\begin{abstract}\noindent
\markpkg{eqnlines} is a \LaTeXe{} package providing
a framework for typesetting single- and multi-line equations
which extends the established equation environments
of \LaTeX{} and the \markpkg{amsmath} package
with many options for convenient adjustment of the intended layout.
In particular, the package adds flexible schemes for numbering,
horizontal alignment and semi-automatic punctuation, and it improves
upon the horizontal and vertical spacing options. The extensions can
be used and adjusted through optional arguments and modifiers to the
equation environments as well as global settings.
\end{abstract}

\MakeShortVerb\|

\begingroup
\parskip0ex
\tableofcontents
\endgroup


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}

Typesetting mathematical equations is an undisputed strength of \TeX{}.
\LaTeX{} improved the overall management of display equations,
for instance by providing optional numbering.
It also added elementary functionality for multi-lined equations
with alignment. Some of its deficiencies were addressed by
the multi-line equation environments of the package \ctanpkg{amsmath}
which have become an established standard for these purposes.

The package \markpkg{eqnlines} builds upon and extends
the functionality of the \LaTeX{} and \ctanpkg{amsmath}
equation environments with some new features
as well as convenient options to adjust the layout where needed.
The main additions are as follows:
%
\begin{itemize}
\item
Equation numbers can be assigned to individual lines
(as for |align| and |gather|)
or once for the multi-line equation block
(as for |multline|).
In the former case,
a sub-numbering scheme can be applied (as through |subequations|).
In the latter case, the position can be assigned to a specific line
(first/middle/last/chosen).
Moreover, equation numbers can be turned on and off by commands,
and they can be triggered by setting a label.
\item
The vertical spacing above and below single- and multi-line equations
of \LaTeX{} and \ctanpkg{amsmath} can be somewhat variable,
hard to control and even resistive in certain situations.
The package implements clearer structures controlling the vertical spacing,
including proper dependency on the text line above
and ways to adjust the spacing.
\item
The framework introduces a scheme which semi-automatically inserts punctuation,
e.g.\ `.' or `,', at the end of the following (or every) equation environment.
Punctuation can also be inserted at every alignment column or equation line
including the possibility to prepend a certain spacing.
\item
Next to |\[|\,\ldots|\]| as an alias for the single-line |equation| environment,
the package uses |\<|\,\ldots|\>| as an alias multi-line equations.
\item
The horizontal alignment and indentation of equation lines
can be adjusted via a scheme or on a line-by-line basis.
\item
The alignment marker can be placed
before or after the equation signs while maintaining proper spacing
to symbols before and after it.
This simplifies the construction of continuing equations
in an aligned context.
\item
Equation lines are subject to shrinking of white space
if the available space does not suffice
(analogously to single-line equations).
\item
Most settings can be controlled via optional arguments and modifiers to the
equation environment or via global settings.
This includes switching between different types of equation environments,
enabling or disabling numbering, adjusting vertical spacing, etc.
This feature simplifies the adjustment and fine-tuning of equations
towards the intended layout.
\item
Last but not least, the underlying \ctanpkg{amsmath} code,
originating from the \TeX{} era and early \LaTeX{} years,
has been redesigned with emphasis
on clarity, readability, adjustability and maintainability
(but at the cost of moderately higher resource consumption
and moderately lower efficiency).
Nevertheless, it remains \LaTeXe{} code.
\end{itemize}
%

The package represents a stand-alone implementation
of an equations environment
which is largely compatible with the established \LaTeX{} and \ctanpkg{amsmath}
environments |equation|, |multline|, |gather|, |align|
and their variants.
Hence, the package can be used instead of \ctanpkg{amsmath}
with no or minor modifications to the \LaTeX{} sources for
single- and multi-line equations.
It can also be used alongside \ctanpkg{amsmath}
including the \ctanpkg{mathtools} extensions
to make use of the additional maths typesetting features
provided by these packages.
In the latter case,
the equation environments of \LaTeX{} and \ctanpkg{amsmath}
are either replaced or left in place while the \markpkg{eqnlines}
environments can be accessed using the alternate name |equations|.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Usage}
\label{sec:usage}

% \TODO notice regarding v0.5
\textbf{Notice regarding package version v0.5:}
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:
Currently, the documentation is basic and minimal
without extensive coverage of all features and settings,
and it lacks desirable illustrations and examples.

It is likely that some features of the package do not work to full extent,
and that the package will not cooperate well with other packages.
Therefore, please report any malfunctions that you may notice.

Therefore, it is likely that internal macros and mechanisms will change,
It is also conceivable that the public interface
will change in minor but relevant ways
in order to accommodate for important adjustments or additional features.
It is intended that such changes would only require minor adaption
of document sources that use an early version of this package.

\medskip

To use the \markpkg{eqnlines} package add the command
%
\begin{center}
|\usepackage{eqnlines}|
\end{center}
%
to the preamble of the \LaTeX{} document.
To use unrelated features of the \ctanpkg{amsmath} package
or of the \ctanpkg{mathtools} extension,
it makes sense to load these packages \emph{before} \markpkg{eqnlines}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Equations Environment}
\label{sec:equations}

\DescribeEnv{equations}
The package supplies a main maths environment called |equations|
which accepts a comma-separated list of optional parameters
`|[|\textit{opts}|]|':
%
\begin{center}
\begin{tabular}{l}
|\begin{equations}[|\textit{opts}|]|\texttt{\textvisiblespace}
\\
\ldots
\\
|\end{equations}|
\end{tabular}
\end{center}
%
Furthermore, the environment accepts some modifiers
(like the star modifier `|*|' for many other \LaTeX\ macros)
which will be explained further below.

We note that the equations environment should be started with a white space
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}|.

\DescribeKey{single}
\DescribeKey{lines}
\DescribeKey{columns}
The environment has three principal modes of operation
which are selected by setting an optional argument as follows:
%
\begin{center}
\begin{tabular}{llll}
purpose & single-line equation & stacked equation(s) & aligned equations \\
\hline
name & |single| & |lines| & |columns| \\
alt.\ names & |equation|, |eq|, |1|
            & |gather|, |ga|, |ln|, |~|
            & |align|, |al|, |col|, |@| \\
symbolic   & |\[|\textvisiblespace\,\ldots|\]|
           & |\<~|\textvisiblespace\,\ldots|\>|
           & |\<|\textvisiblespace\,\ldots|\>| \\
\ctanpkg{amsmath} env. & |equation| & |gather|, |multline| & |align| \\
\hline
columns & --- & single & multiple, aligned \\
alignment & adjustable & adjustable & alternating right/left \\
parsing & single, direct & two passes & two passes \\
numbering & on/off & off/single/multiple & off/single/multiple \\
\end{tabular}
\end{center}
%
The aligned mode more or less encompasses all three modes,
and the stacked mode with only a single line
is more or less just a single equation.
However, the more complex forms also come along with some restrictions,
hence, it makes sense to use the appropriate mode
for the intended equation content.
For instance, a single equation simply reads the equation input once,
while the multi-line equation environments parse the environment body twice
which can potentially disrupt some other functionality
that is included in the body.
Furthermore, the horizontal adjustment options are very restricted
in aligned mode, and therefore the aligned form can automatically reduce
to the stacked form (with right alignment) if only a single column is provided
(no `|&|'s).

\DescribeInterfaceMacro{\[...\string\]}
\DescribeInterfaceMacro{\<...\string\>}
\DescribeKey{\string~}
The package offers several alternative names for the same mode as well as
a symbolic short form |\<|\ldots|\>| extending the \LaTeX{}
display equation form |\[|\ldots|\]| to multi-line equations.
Here, the tilde `|~|' in |\<~|\textvisiblespace\,\ldots|\>|
is a modifier character
which acts as a short form for the optional argument |lines|
selecting the lines mode.
\DescribeKey{sqropt}
\DescribeKey{angopt}
Both short forms can be customised
by setting default arguments via the global options
|sqropt={|\textit{opts}|}| and |angopt={|\textit{opts}|}|.
Both default arguments are preset to |nonumber|
which disables equation numbering, see \secref{sec:numbering}.

\DescribeEnv{equation}
\DescribeEnv{multline}
\DescribeEnv{gather}
\DescribeEnv{align}
The package also supplies or overwrites the \ctanpkg{amsmath}
environments |equation|, |multline|, |gather|, |align| and |flalign|
including their starred variants
but neither the |alignat| alternative forms nor |split|.
It is possible to define further equation environments \textit{env}
with a predefined set of options \textit{opts} using:
%
\begin{center}
|\|[|re|]|newenvironment{|\textit{env}|}|%
|{\eqnaddopt{|\textit{opts}|}\equations}{\endequations}|
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Numbering}
\label{sec:numbering}

\DescribeKey{numberline}
The package extends the established interface of \LaTeX{}
and the \ctanpkg{amsmath} package for labelling equations
with numbers or with manually assigned tags.
For multi-line equations, there are two distinct modes of operations:
individual labelling of the equation lines or
one overall number/tag for the whole block of equations.
The modes are selected by an optional argument
|numberline=|\textit{mode} as follows:
%
\begin{center}
\begin{tabular}{llll}
name     & alt. & description & preset \\
\hline
|none|   & |n| & & preset off\\
|all|    & |a| & individual lines & preset on\\
|sub|    & |s| & & subequations (a,\,b,\,c,\,\ldots) \\
\hline
|first|  & |f| & & first line\\
|last|   & |l| & & last line \\
|middle| & |m| & single number & middle line \\
|out|    & |o| & & last/first line for right/left tags \\
|in|     & |i| & & first/last line for right/left tags  \\
|here|   & |h| & & line indicated by |\numberhere| \\
\end{tabular}
\end{center}
%
\DescribeInterfaceMacro{\nonumber}
\DescribeInterfaceMacro{\donumber}
Numbering can be turned on and off
(for individual lines or for the block as a whole depending on the mode)
by means of:
%
\begin{center}
|\nonumber|
\qquad and \qquad
|\donumber|
\end{center}
%
\DescribeKey{*}
\DescribeKey{!}
Alternatively, the numbering can be disabled or enabled for the block using
modifiers (which must be placed \emph{before} further optional arguments):
%
\begin{center}
|\[*|\textvisiblespace\,\ldots|\]|
\qquad and \qquad
|\[!|\textvisiblespace\,\ldots|\]|
\end{center}
%
This allows to define a default behaviour and specify exceptions
where they may occur.
The star modifier following directly the environment declaration
replaces the starred form of environments (|equation*|, etc.).

\DescribeInterfaceMacro{\numberhere}
\DescribeInterfaceMacro{\numbernext}
The placement of a single number for an equation block can be adjusted by:
%
\begin{center}
|\numberhere|
\qquad and \qquad
|\numbernext|
\end{center}
%
The former macro overrides the position to the present line.
The latter macro defers the number to the next line,
e.g.\ if an equation is broken into several lines
and the last one should receive the number tag.

\DescribeInterfaceMacro{\label}
\DescribeInterfaceMacro{\tag}
Equation numbers can receive \LaTeX{} labels as usual
and they can be turned into manually assigned tags
using the established macros:
%
\begin{center}
|\label{|\textit{label}|}|
\qquad and \qquad
|\tag|[|*|]|{|\textit{tag}|}|
\end{center}
%
Note that a label and a tag will always apply to the
next number that will be printed, and only a single label
and/or tag may be specified for it. For example, if the present line
has no numbering, but the following line does,
|\label| or |\tag| will apply to the following line.
The macros |\label| and |\tag|
can also be instructed to automatically enable numbering
for the present line or block (|\donumber|).
By default, numbers are triggered for |\tag|, but not for |\label|
reflecting the behaviour set forth by \ctanpkg{amsmath}.
By enabling triggering for |\label|, numbers will be produced
only if they have a chance of being referenced.

\DescribeKey{label}
\DescribeKey{tag}
\DescribeKey{@}
The equations environment provides an alternative means
to specify labels and tags within the optional arguments |[|\textit{opts}|]|
or via the modifier |@{|\textit{label}|}|
(which may \emph{follow} further optional arguments):
%
\begin{center}
|label={|\textit{label}|}|,
\qquad
|tag|[|*|]|={|\textit{tag}|}|,
\qquad\qquad
|\[@{|\textit{label}|}|\,\ldots|\]|
\end{center}
%
In particular, in subequations mode (|sub|),
the optional argument |label| can be used to assign
a label to the parent number addressing the whole equation block.

\DescribeInterfaceMacro{\raisetag}

\DescribeKey{taglayout}
\DescribeKey{tagform}
The typesetting of equation numbers and tags passes through
two methods defined by \ctanpkg{amsmath},
one which defines the layout
and another one which adds a decoration (brackets).
These two methods can be adjusted via the options:
%
\begin{center}
|taglayout|[|*|]|={|\textit{code}|}|
\quad and\quad
|tagform={|\textit{l}|{|\textit{code}|}|\textit{r}|}|
\quad or\quad
|tagform*={|\textit{code}|}|
\end{center}
%
Here, \textit{code} is some macro code
that references the argument `|#1|' containing the
number or tag, and \textit{l} and \textit{r}
can be opening and closing brackets for the tag presentation.

\DescribeInterfaceMacro{\eqref}
The macro |\eqref| is the standard method for referring
to equation numbers via their label.
This method also uses the layout defined above.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Horizontal Adjustment}
\label{sec:adjustment}

\DescribeKey{margin}
\DescribeKey{mincolsep}
\DescribeKey{maxcolsep}
The horizontal alignment of columns is fixed for aligned multi-line equations:
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
is treated on equal footing to the space between the columns
(option |margins=on|),
but it can be eliminated so that the outer columns
are pushed right to the margin (option |margins=off|).
In addition, a minimum and maximum width can be specified
for the column separation (|mincolsep=|\textit{dimen}
and |maxcolsep=|\textit{dimen}).
By default, no maximum column separation is set (|maxcolsep*|),
and all horizontal space is used, otherwise a value
of |2em| ($\equiv$|\qquad|) is suggested with the minimum separation
set to |1em| ($\equiv$|\quad|) by default.

For stacks of equations including single equations,
there is just a single alignment column
whose horizontal alignment can be adjusted via a shape scheme or
by manually adjusting individual lines.
A shape scheme determines the horizontal alignment for each line
and it is specified by the optional argument
|shape=|\textit{mode} as follows:
%
\begin{center}
\begin{tabular}{llll}
name & alt. & shape & alignment \\
\hline
|default| & |def| & uniform & default\\
\hline
|left| & |l| & & left\\
|center| & |c| & uniform & central \\
|right| & |r| & & right \\
\hline
|first| & |indent|, |rc|  & first/rest & first line indented \\
|hanging| & |outdent|, |lc| & first/rest & first line hanging \\
|steps| & |lcr| & first/intermediate/last & left/centre\ldots centre/right\\
\end{tabular}
\end{center}
%
Note that the steps shape comes to use in the \ctanpkg{amsmath}
environment |multline|. The alignment preset
can be adjusted for individual lines by the macros:
%
\begin{center}
|\shoveleft|[|*|$\vert$|!|$\vert$|[|\textit{dimen}|]|],
\qquad
|\shovecenter|,
\qquad
|\shoveright|
\end{center}
%
In contradistinction to \ctanpkg{amsmath},
these macros do not require to specify the cell contents as their argument
(but there is no harm in doing so).
\DescribeKey{indent}
The macro |\shoveleft| also accepts the modifiers
`|*|' or `|!|' for indentation or hanging indentation by
the standard indentation amount (|indent|=|2em|)
or an optional argument |[|\textit{indent}|]|
specifying a variable amount of indentation.

\DescribeKey{padding}
\DescribeKey{padleft}
\DescribeKey{padright}
\DescribeKey{padmax}
Note that (hanging) indentation requires to add some padding around
the equations block via the optional argument
|padding|$\vert$|padleft|$\vert$|padright|[|={|\textit{dimen}|}|]
or |padmax| to extend padding to the whole line.
Note that |indent*={|\textit{dimen}|}| sets the default indentation amount
and the left padding at the same time.

\DescribeKey{layout}
\DescribeKey{center}
\DescribeKey{left}
Finally, the overall layout can be adjusted between central and left alignment
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
|tagmargin={|\textit{dimen}|}|
which allocates some space to the tag
such that equation content is centred in the remaining horizontal space.

\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).
Depending on the situation, the left margin may be
reduced or extended to |minleftmargin| or |maxleftmargin|, respectively.

\DescribeKey{marginbadness}
\DescribeKey{maxbadness}
Finally, we note that within single and stacked equations,
very long equations that do not fit the available horizontal space
are subject to shrinking attempts. In other words,
\TeX{} will attempt to shrink the glue contained in the equation line
to make it fit. This shrinking can be controlled by the two parameters
|marginbadness| and |maxbadness| accepting integer values.
The former is used for trying to shrink onto certain horizontal margins
which are otherwise reserved for tags;
the latter is used for using the maximal horizontal space which also
raises or lowers the equation tag if needed.
Small values prevent shrinking and higher values allow for more compression.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Punctuation}
\label{sec:puctuation}

Extending proper punctuation across equations is a delicate matter,
and maintaining it while redacting the text
certainly takes more attention to detail
than many author are willing to afford.
A contributing factor is that punctuation marks are harder
to spot alongside equation context and somewhat out of place anyway.

\DescribeInterfaceMacro{\eqnpunctmain}
\DescribeInterfaceMacro{\eqnpunct}
\DescribeKey{punct}
The package supplies a semi-automatic scheme by which
equations are terminated by a specific punctuation mark.
Punctuation marks are set by:
%
\begin{center}
\begin{tabular}{ll}
|\eqnpunctmain{|\textit{punct}|}| &
|\eqnlinesset{punct={|\textit{punct}|}}|
\\
|\eqnpunct{|\textit{punct}|}| &
|\eqnaddopt{punct={|\textit{punct}|}}|
\\
|\[[punct={|\textit{punct}|}]|\,\ldots|\]|
\end{tabular}
\end{center}
%
The former two forms set and enable a default punctuation mark;
the middle two forms set the punctuation mark for the
next equation environment in line;
the final form applies to the equation environment only.
For example, one might declare `|\eqnpunctmain.|' to terminate
all equations with a period `|.|'.
The default behaviour can be adjusted to a comma `|,|'
for an individual equation
by declaring `|\eqnpunct,|' before the equation
(i.e.\ at the end of the textual phrase to which the punctuation mark belongs)
or by using the optional argument |[punct={,}]|.
Likewise, |\eqnpunct{}| and |[punct={}]| eliminate a preset punctuation.

\DescribeKey{punctsep}
For convenience, one may also specify a desired space
(or any other sequence) preceding the punctuation
by |[punctsep={|\textit{sep}|}]|,
e.g.\ \textit{sep}=|\,| or \textit{sep}=|\|\texttt{\textvisiblespace}.

\DescribeInterfaceMacro{\eqnpunctcol}
\DescribeInterfaceMacro{\eqnpunctline}
\DescribeKey{punctcol}
\DescribeKey{punctline}
For multi-line equations, there are two further levels of default punctuation
for terminating columns and lines
which are specified via the macros |\eqnpunctcol| and |\eqnpunctline|
or the optional arguments |punctcol| and |punctline|.
A punctuation item may also be handed on to the next lower level
of punctuation via the starred forms |punct*| and |punctline*|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Math Classes at Alignment}
\label{sec:classes}

Alignment in multi-line equations breaks
equations into components before and after the alignment position.
Unfortunately, this also interrupts \TeX's math spacing mechanism
which is based on the math classes assigned to the characters,
and there appears to be no direct way of determining the
math class to the previous letter.
Therefore, one has to make some assumptions
on the letters that will surround the alignment marker `|&|'
in order to obtain the appropriate spacing also across the alignment.

The \ctanpkg{amsmath} environment |align| assumes that
the left column ends with an ordinary character.
This leads to the correct spacing when an equation $a=b+c$
is broken before the equals relation as |a&=b+c|,
and also if an equation sequence continues on the next line as |\\&=d-e|.
However, it is difficult to achieve the right spacing
if the right-hand side is to be broken into several lines:
For instance, |\\&|\textvisiblespace|+f|
aligns the subordinate binary operation with the equals sign
(which may be undesirable).
Instead placing a phantom equals sign is an effort
that somewhat disrupts the readability of the code.

\DescribeKey{class}
\DescribeKey{ampeq}
\DescribeKey{eqamp}
The package implements a more flexible assignment of math classes
at the alignment. The above default behaviour is invoked by
the optional argument |class=ampeq| (or |ampeq| for short).
The optional argument |class=eqamp| (or |eqamp| for short)
imposes math classes at the alignment
such that an equation sign should be placed just before the alignment.
Concretely, it inserts |\mathrel{}| classes just before and after
the alignment marker. Furthermore, in case of an empty left alignment cell,
the leading math class is changed to |\mathord{}|
so that a following binary operator is not interpreted as a unary one.

\DescribeKey{classout}
\DescribeKey{classin}
\DescribeKey{classlead}
Math classes just before and after alignment can be adjusted freely
by the optional arguments:
%
\begin{center}
|classout={|\textit{class}|}|,
\qquad
|classin={|\textit{class}|}|,
\qquad
|classlead={|\textit{class}|}|.
\end{center}
%
The parameter |classlead| determines the math class just after the alignment
if the cell before alignment is empty.

For example, the following two expressions produce identical output:
%
\begin{center}
\begin{tabular}{l}
|\<[ampeq] a &= b+c \\ &= d-e \\ &\mathrel{}\phantom{=} +f \>|
\\
|\<[eqamp] a =& b+c \\ =& d-e \\ & +f \>|
\end{tabular}{l}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Vertical Spacing}
\label{sec:vspace}

Display equations in \TeX{} are considered to be part
of the surrounding text.
Hence, the vertical spacing depends on the surrounding text,
in particular on the width and depth of the last line of text.
Due to this influence it can be difficult to control
the spacing accurately.
The package adds several options to control the vertical spacing,
and it also implements a uniform behaviour for all types of equations.

The spacing of equations to the surrounding text
is a combination of several aspects:

First, \TeX{} inserts some interline spacing according to its rules.
The amount depends on the depth/height of the surrounding text
and the height/depth of the math content.
The former typically takes rather uniform values,
whereas the latter can range wildly with the context
(plain equations vs.\ fractions and matrices).
As equations are normally surrounded by a relatively large amount of glue,
it makes sense to reduce the dependency on the height/depth of math content.
Therefore, the package makes equation environments
appear to the surrounding text
as a line with a fixed height and depth,
and thus interline glue merely fills some potential gaps of the
surrounding text.
\DescribeKey{displayheight}
\DescribeKey{displaydepth}
The apparent height and depth are defined by
|displayheight| and |displaydepth|
which default to the dimensions of a strut.

Second, the spacing of display equations depends on the width
of the previous line of text.
If the math content fits well into the available horizontal space,
the display equation is called short
and less glue is needed above the equation.
The package implements this basic \TeX{} feature
for all single- and multi-line equation environments.
\TeX{} also reduces the amount of glue below short equations
(potentially to make their spacing appear more uniform).
\DescribeKey{shortmode}
The package allows to adjust the spacing for short equations
via the global option |shortmode={|\textit{mode}|}|
where \textit{mode} takes the values:
%
\begin{center}
\begin{tabular}{lll}
name & reduced glue \\
\hline
|off| & disabled \\
|above| & above short equations \\
|belowone| & also below short single-line equations \\
|belowall| & also below all short single-line equations \\
\end{tabular}
\end{center}
%
\DescribeKey{short}
\DescribeKey{long}
Short and long amounts of glue can also be enforced for
individual equation environments
via the optional arguments |short| and |long|
taking the values |above|, |below| or |both|.

Third, the package provides several means to adjust the
glue around equations:

\DescribeKey{noskip}
\DescribeKey{medskip}
Next to |short| and |long| the spacing above and below
equation environments can be reduced
to some other fixed smaller amount via |medskip|
or removed altogether via |noskip|.
These keys also take the values |above|, |below| or |both|.

\DescribeKey{...skip}
\DescribeInterfaceMacro{\vspace}
\DescribeKey{...space}
Variable amounts of skip can be set via
|aboveskip| and |belowskip| or |skip| for both simultaneously.
In addition, the package extends the |\vspace| mechanism
of \LaTeX{} to equation bodies where it adds vertical space
below the next equation line or below the equation environment.
Additional glue can be added above or below equation environments
by means of the options |abovespace| and |belowspace|.

The package also maintains several global vertical space settings:
%
\DescribeKey{...skip}
\begin{center}
\begin{tabular}{llll}
above & below & both & description \\
\hline
|aboveskip| & |belowskip| & |skip| & standard amount of glue \\
|aboveshortskip| & |belowshortskip| & -- & reduced glue for short equations \\
|abovemedskip| & |belowmedskip| & |medskip| & medium amount of glue \\
|abovetagskip| & |belowtagskip| & |tagskip|
  & glue for outer raised/lowered tags \\
|abovetopskip| & -- & -- & glue at top of vertical list \\
|aboveparskip| & -- & -- & glue when starting a paragraph \\
|abovecontskip| & -- & -- & glue when started from empty paragraph \\
\end{tabular}
\end{center}

\DescribeKey{spread}
\DescribeKey{strut}
\DescribeKey{struttag}
Likewise, the spacing between the lines
of a multi-line equation environment can be adjusted
via |spread={|\textit{dimen}|}|
which defaults to |\jot|$\equiv$|3pt|.
In addition, all equation lines and tags
are supplied with struts to ensure a minimum height and depth.
The latter behaviour is controlled by the boolean switches
|strut| and |struttag|.

\DescribeKey{displaybreak}
\DescribeInterfaceMacro{\displaybreak}
\DescribeKey{allowdisplaybreaks}
Finally, the breaking of multi-line equations across pages
can be controlled as follows:
The setting |allowdisplaybreaks|
taking values |0| (never) through |4| (permissive)
controls the permittivity of page breaks within multi-line equations.
The optional argument |displaybreak|
taking values |0| (do not) through |4| (enforce)
suggests a break just \emph{above} the equation environment.
The command |\displatybreak| with values |0| through |4|
suggests a break below the current line or below the equation environment.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Further Environments}
\label{sec:further}

The package supplies some additional environments:

\DescribeEnv{equationsbox}
\DescribeKey{margin}
\DescribeKey{marginleft}
\DescribeKey{marginright}
The package provides a boxed equation environment |equationsbox|
which can be used within arbitrary math content.
It works analogously to |equations| including optional arguments
and modifiers, but it offers a reduced range of functionality
such as (evidently) no numbering.
Additional arguments are given by
|margin|, |marginleft|, |marginright|
which specify additional margin space
around the equations box.

\DescribeEnv{subequations}
\DescribeKey{subeqtemplate}
The environment |subequations| group equations contained in the body
with a common primary equation number and an extra level
of numbering (typically: a,\,b,\,c,\,\ldots).
The numbering layout can be controlled via |subeqtemplate|.
For instance, the default behaviour of adding lowercase latin letters
to the parent equation number (|\theparentequation|)
is achieved by:
%
\begin{center}
|subeqtemplate={\theparentequation\alph{equation}}|
\end{center}


\DescribeEnv{intertext}
\DescribeInterfaceMacro{\intertext}
The environment |intertext| (or equivalently the macro |\intertext|)
injects a (short) line of text
into a multi-line equation while preserving the equation alignment
across the text.
The intertext environment must replace the
end of line marker `|\\|' between two lines of the equation
(to avoid blank lines).
The environment accepts several of the vertical spacing adjustments
as an optional argument.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Feature Selection and Package Options}
\label{sec:features}

\DescribeInterfaceMacro{\eqnlinesset}
Features and options of general nature can be selected by the commands:
%
\begin{center}
\begin{tabular}{rl}
&|\usepackage[|\textit{opts}|]{eqnlines}|
\\
or&|\PassOptionsToPackage{|\textit{opts}|}{eqnlines}|
\\
or&|\eqnlinesset{|\textit{opts}|}|
\end{tabular}
\end{center}
%
|\PassOptionsToPackage| must be used before |\usepackage|;
|\eqnlinesset| must be used afterwards.
\textit{opts} is a comma-separated list of options.

The following few settings can only be specified when loading the package,
not via |\eqnlinesset|:
%
\begin{center}
\begin{tabular}{lll}
option & type & description \\
\hline
|equation| & bool & provide/overwrite |equation| and |\[|\ldots|\]| \\
|amsmath| & bool & provide/overwrite \ctanpkg{amsmath}
                   environments and macros \\
|ang| & bool & provide |\<|\ldots|\>| \\
\end{tabular}
\end{center}
%

If the above settings are disabled, the package will only supply
the general purpose environment |equations| and its boxed cousin |equationsbox|.
In that case, the specific equation environments and other features
can be activated by the command:
%
\begin{center}
|\eqnlinesprovide{|\textit{features}|}|
\end{center}
%
\textit{features} is a comma-separated list of features:
%
\begin{center}
\begin{tabular}{ll}
feature & description \\
\hline
\textit{env} & provide/overwrite environment \textit{env}:\\
& |equation|, |gather|, |multline|, |align|, |flalign| \\
& |multlined|, |gathered|, |aligned|, |subequations| \\
\textit{env}|=|\textit{name} &
   provide environment \textit{env} as \textit{name} \\
|sqr| & provide |\[|\ldots|\]| \\
|ang| & provide |\<|\ldots|\>| \\
\textit{cmd} & provide/overwrite macro |\|\textit{cmd}:\\
& |eqref|, |notag|, |thetag|, |allowdisplaybreaks|, |numberwithin| \\
\end{tabular}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\TODO
%\subsection{List of Options}
%\label{sec:options}

%list:
%EBSIGP (equations, box, subequations, intertext, global, package)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Information}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Copyright}
\label{sec:copyright}

Copyright \copyright{} 2024--2025 Niklas Beisert

Based on the latex package amsmath:
Copyright \copyright{}
1995, 2000, 2013 American Mathematical Society;
2016--2024 LaTeX Project and American Mathematical Society.

This work may be distributed and/or modified under the
conditions of the \LaTeX{} Project Public License, either version 1.3
of this license or (at your option) any later version.
The latest version of this license is in
  \url{https://www.latex-project.org/lppl.txt}
and version 1.3c or later is part of all distributions of \LaTeX{}
version 2008 or later.

This work has the LPPL maintenance status `maintained'.

The Current Maintainer of this work is Niklas Beisert.

This work consists of the files |README.txt|, |eqnlines.ins| and |eqnlines.dtx|
as well as the derived files |eqnlines.sty| and |eqnlines.pdf|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Credits}
\label{sec:credits}

This package is based on the \LaTeX{} package \ctanpkg{amsmath}
(initially named \markpkg{amstex})
which in turn is based on the \TeX{} macro system \ctanpkg{amstex}
written by Michael Spivak.
The initial work of porting \ctanpkg{amstex} to \LaTeX{}
was done in 1988--1989 by Frank Mittelbach and Rainer Sch\"opf.
In 1994 David M.\ Jones added the support for flush-left layout
and did extensive improvements to the align family of environments
and to the equation number handling in general.
Michael Downes at the AMS served as coordinator
for the efforts of Mittelbach, Sch\"opf, and Jones,
and has contributed various bug fixes and additional refinements over time.
Since 2016, the package has been maintained by the LaTeX Project
with contributions by the above and David Carlisle.

This package has been forked from \ctanpkg{amsmath}
in accordance with the LPPL, particularly paragraph 6.
The original package \ctanpkg{amsmath} is available
at CTAN within \ctanpkg{latex-amsmath}.
It uses the basic mechanisms for processing
numbered multi-line equations as developed in \ctanpkg{amsmath}
(environments |equation|, |align|, |gather|, |multline|, |gathered|, |aligned|
and related), as well as code implementing these mechanisms.
It differs from \ctanpkg{amsmath} in the following aspects:
%
\begin{itemize}
\item
The implementations of |split| and methods unrelated to multi-line equations
and equation numbering have been dropped.
\item
Code has been restructured, macros have been renamed and extended.
\item
Numbering and horizontal adjustment schemes have been unified and extended.
\item
Options for math classes surrounding the alignment have been added.
\item
A punctuation scheme has been added.
\item
Vertical spacing has been redesigned.
\item
Optional parameters have been added to environments.
\item
Various configuration options and layout settings have been added.
\item
Cooperation with \ctanpkg{hyperref}, \ctanpkg{showkeys}
and \ctanpkg{amsmath} has been included into the package.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Files and Installation}

The package consists of the files:
%
\begin{center}
\begin{tabular}{ll}
    |README.txt|       & readme file \\
    |eqnlines.ins|     & installation file \\
    |eqnlines.dtx|     & source file \\
    |eqnlines.sty|     & package file \\
    |eqnlines-dev.sty| & package file (development version) \\
    |eqnlines.pdf|     & manual
\end{tabular}
\end{center}
%
The distribution consists of the files
|README.txt|, |eqnlines.ins| and |eqnlines.dtx|.
%
\begin{itemize}
\item
Run (pdf)\LaTeX{} on |eqnlines.dtx|
to compile the manual |eqnlines.pdf| (this file).
\item
Run \LaTeX{} on |eqnlines.ins| to create the package |eqnlines.sty|
and the developers version |eqnlines-dev.sty|.
Copy the file |eqnlines.sty| to an appropriate directory of your \LaTeX{}
distribution, e.g.\ \textit{texmf-root}|/tex/latex/eqnlines|.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Related CTAN Packages}

The package is related to other packages available at CTAN:
%
\begin{itemize}
\item
This package uses the package \ctanpkg{keyval}
to process the options for the package, environments and macros.
Compatibility with the \ctanpkg{keyval} package
has been tested with v1.15 (2022/05/29).
\item
This package reproduces the math environments functionality
of the package \ctanpkg{amsmath}.
The present code is based on \ctanpkg{amsmath} v2.17t (2024/11/05).
Compatibility with the \ctanpkg{amsmath} package is maintained
whether \markpkg{eqnlines} is loaded before or after \ctanpkg{amsmath}.
By default, \markpkg{eqnlines} will rename
the math environments of \ctanpkg{amsmath} with a prefix |ams...|
and overwrite them with its own implementations.
Alternatively, \markpkg{eqnlines} may assign individual names
to the maths environments and preserve the ones of \ctanpkg{amsmath}.
The other features provided by \ctanpkg{amsmath}
can be used.
\item
The package \ctanpkg{mathtools}
is a popular extension of the \ctanpkg{amsmath} package.
This package incorporates some of the features and improvements
provided by the \ctanpkg{mathtools} package.
Compatibility with the \ctanpkg{mathtools} package
has been tested with v1.31 (2024/10/04),
and it is maintained whether \markpkg{eqnlines}
is loaded before or after \ctanpkg{mathtools}.
Some features like adding a box and emphasising
equations via \ctanpkg{empheq} does not (yet) work.
\item
This package cooperates with the package \ctanpkg{hyperref}
to create anchors and references within the electronic document.
Compatibility with the \ctanpkg{hyperref} package
has been tested with v7.01l (2024/11/05).
\item
This package supports the display of labels and references
through the package \ctanpkg{showkeys}.
Compatibility with the \ctanpkg{showkeys} package
has been tested with v3.21 (2024/05/23).
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Feature Suggestions}

The following is a list of features for consideration
towards future versions of this package.
Their potential use may range between useful and niche;
and their difficulty between easy and impossible:
%
\begin{itemize}
\item
a proper manual
\item
complete code documentation
\item
sample document
\item
pdf tagging
\unskip\footnote{See \url{https://latex3.github.io/tagging-project/}}
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Revision History}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.5:} 2025/02/25

\begin{itemize}
\item
preview version published on CTAN
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix

\settowidth\MacroIndent{\rmfamily\scriptsize 0000\ }

\DocInput{eqnlines.dtx}

\end{document}
%</driver>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \appendix
% \raggedright
%\iffalse
%<*package>
%\fi
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
%
% The appendix documents the various components
% of the present package.
%
% The code for the package is based on the \ctanpkg{amsmath} package,
% see \secref{sec:copyright} and \secref{sec:credits}.
% It was forked at version v2.17t dated 2024/11/05.
% Most of the code was substantially redesigned
% (macros renamed, reshuffled, enhanced),
% but many of the underlying mechanisms were preserved.
% The documentation thus contains excerpts
% from the \ctanpkg{amsmath} package documentation
% explaining some details of the implementation.
%
% Please note that the documentation is completed
% only for few sections in the present version.
% Various open issues are remarked.
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{General Support}
%
% In the following we describe general purpose supporting routines.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Development Messages}
%
% The package offers a version \markpkg{eqnlines-dev}
% for development and debugging purposes.
% It outputs extra information on the current location
% within the code in order to track progress.
% The extra lines for the development version
% are indicated as `\textlangle dev\textrangle'
% in the implementation documentation:
%    \begin{macrocode}
%<dev>\def\eql@dev#1{\PackageInfo{eqnlines-dev}{#1}}
%<dev>\def\eql@dev@start#1{\eql@dev{starting \string#1}}
%<dev>\def\eql@dev@enter#1{\eql@dev{entering \string#1}}
%<dev>\def\eql@dev@leave#1{\eql@dev{ leaving \string#1}}
%<dev>\def\eql@dev@enterenv{\eql@dev{entering \@currenvir}}
%<dev>\def\eql@dev@leaveenv{\eql@dev{ leaving \@currenvir}}
%<dev>\def\eql@dev@in#1#2{\eql@dev{ \space within \string#1 #2}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Look-Ahead in Alignment}
%
% Scanning for optional arguments |[|\ldots|]| or modifiers such as `|*|'
% using the \LaTeX{} |\@ifnextchar| mechanism
% has two challenges within aligned equations:
% a square bracket or star may well be part of
% the intended mathematical expression
% and the look-ahead could trip upon an alignment character `|&|'
% which inadvertently triggers to enter the next alignment column.
%
%   \macro{\eql@ifnextchar@loose}
%   \macro{\eql@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|
% in |\kernel@ifnextchar| which skips over spaces as |\eql@ifnextchar@loose|.
% We replicate the \ctanpkg{amsgen} version |\new@ifnextchar|
% that does not skip over spaces as |\eql@ifnextchar@loose|.
% The space before |#1| allows to look-ahead for spaces as well:
%    \begin{macrocode}
\let\eql@ifnextchar@loose\kernel@ifnextchar
\long\def\eql@ifnextchar@tight#1#2#3{%
  \let\reserved@d= #1%
  \def\reserved@a{#2}%
  \def\reserved@b{#3}%
  \futurelet\@let@token\eql@ifnch@tight
}
\def\eql@ifnch@tight{%
  \ifx\@let@token\reserved@d
    \let\reserved@b\reserved@a
  \fi
  \reserved@b
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\begingroup
  \makeatother
  \let\tmp=@%
  \makeatletter
  \global\let\eql@atxii\tmp
\endgroup
%    \end{macrocode}
%
%   \macro{\eql@ifnextgobble@...}
%   \macro{\eql@ifstar@...}
%   \macro{\eql@testopt@...}
%   \macro{\eql@teststaropt@...}
% We introduce a collection of look-ahead macros
% which do or do not skip over spaces.
% The macros |\eql@ifstar@...| and |\eql@testopt@...|
% replicate the \LaTeX{} counterparts |\@ifstar| and |\@testopt|.
% The macros |\eql@ifnextgobble@...| work like |\@ifnextchar|,
% but also gobble the specific character if found;
% one might define |\eql@ifstar@...| as |\eql@ifnextgobble@...*|.
% The macros |\eql@teststaropt@...| tests for combinations
% of `|*|' and optional arguments |[|\ldots|]|:
%    \begin{macrocode}
\long\def\eql@ifnextgobble@loose#1#2{\eql@ifnextchar@loose#1{\@firstoftwo{#2}}}
\long\def\eql@ifnextgobble@tight#1#2{\eql@ifnextchar@tight#1{\@firstoftwo{#2}}}
\long\def\eql@ifstar@loose#1{\eql@ifnextchar@loose*{\@firstoftwo{#1}}}
\long\def\eql@ifstar@tight#1{\eql@ifnextchar@tight*{\@firstoftwo{#1}}}
\long\def\eql@ifat@loose#1#2{\eql@ifnextgobble@loose{@}{#1}{%
  \eql@ifnextgobble@loose\eql@atxii{#1}{#2}}}
\long\def\eql@ifat@tight#1#2{\eql@ifnextgobble@tight{@}{#1}{%
  \eql@ifnextgobble@tight\eql@atxii{#1}{#2}}}
\long\def\eql@testopt@loose#1#2{\eql@ifnextchar@loose[{#1}{#1[{#2}]}}%]
\long\def\eql@testopt@tight#1#2{\eql@ifnextchar@tight[{#1}{#1[{#2}]}}%]
\long\def\eql@teststaropt@loose#1#2#3{%
  \eql@ifstar@loose{\eql@testopt@loose{#1}{#3}}{\eql@testopt@loose{#2}{#3}}}
\long\def\eql@teststaropt@tight#1#2#3{%
  \eql@ifstar@tight{\eql@testopt@tight{#1}{#3}}{\eql@testopt@tight{#2}{#3}}}
%    \end{macrocode}
%
%   \macro{\eql@spbgroup}
%   \macro{\eql@spegroup}
%   \macro{\eql@srbgroup}
%   \macro{\eql@sregroup}
% The second challenge is addressed by enclosing the look-ahead
% in spurious groups
% \unskip\footnote{See
% \url{https://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/3040},\\
% \url{https://www.latex-project.org/cgi-bin/ltxbugs2html?pr=amslatex/1834} and\\
% \url{https://tex.stackexchange.com/questions/9897/showcase-of-brace-tricks-egroup-iffalse-fi-etc}.
% }
% which protect against triggering `|&|'.
% The macros |\eql@spbgroup| and |\eql@spegroup| open and close a
% spurious group.
% For some reason, the look-ahead mechanism requires further protections
% by inserting |\relax| at the beginning
% and by resetting |\@let@token| at the end.
% These adjustments are included
% in the macros |\eql@srbgroup| and |\ers@spegroup|:
%    \begin{macrocode}
\def\eql@spbgroup{\iffalse{\fi\ifnum0=`}\fi}
\def\eql@spegroup{\ifnum0=`{\fi\iffalse}\fi}
\def\eql@srbgroup{\relax\iffalse{\fi\ifnum0=`}\fi}
\def\eql@sregroup{\let\@let@token\relax\ifnum0=`{\fi\iffalse}\fi}
%    \end{macrocode}
%
%   \macro{\eql@ampprotect}
%   \macro{\eql@ampprotecttwo}
% The macros |\eql@ampprotect| and |\eql@ampprotecttwo|
% inject the opening and closing of spurious groups
% into the look-ahead mechanism:
%    \begin{macrocode}
\long\def\eql@ampprotect#1#2{\eql@srbgroup#1{\eql@sregroup#2}}
\long\def\eql@ampprotecttwo#1#2#3{%
  \eql@srbgroup#1{\eql@sregroup#2}{\eql@sregroup#3}}
%    \end{macrocode}
%
%   \macro{...@ampsafe}
% We introduce a collection of `|&|'-safe look-ahead macros:
%    \begin{macrocode}
\def\eql@ifnextchar@loose@ampsafe#1{%
  \eql@ampprotecttwo{\eql@ifnextchar@loose#1}}
\def\eql@ifnextchar@tight@ampsafe#1{%
  \eql@ampprotecttwo{\eql@ifnextchar@tight#1}}
\def\eql@ifstar@loose@ampsafe{\eql@ampprotecttwo\eql@ifstar@loose}
\def\eql@ifstar@tight@ampsafe{\eql@ampprotecttwo\eql@ifstar@tight}
\def\eql@testopt@loose@ampsafe{\eql@ampprotect\eql@testopt@loose}
\def\eql@testopt@tight@ampsafe{\eql@ampprotect\eql@testopt@tight}
\def\eql@teststaropt@loose@ampsafe{\eql@ampprotecttwo\eql@teststaropt@loose}
\long\def\eql@teststaropt@tight@ampsafe{%
  \eql@ampprotecttwo\eql@teststaropt@tight}
%    \end{macrocode}
%
%   \macro{\eql@amproof}
%   \macro{\eql@amprevert}
% We may want to replace \LaTeX's definitions |\@ifnextchar|,
% |\@ifstar| and |\@testopt| to respect `|&|' characters
% within aligned equations.
% This might make unrelated definitions with optional arguments
% and starred variants more robust in this context.
% The macro |\eql@amproof| overwrites the original definitions,
% and |\eql@amprevert| reverts the changes:
%    \begin{macrocode}
\let\eql@ifnextchar@org\@ifnextchar
\let\eql@ifstar@org\@ifstar
\let\eql@testopt@org\@testopt
\def\eql@amprevert{%
  \let\@ifnextchar\eql@ifnextchar@org
  \let\@testopt\eql@testopt@org
  \let\@ifstar\eql@ifstar@org
}
\def\eql@ampproof{%
  \let\@ifnextchar\eql@ifnextchar@loose@ampsafe
  \let\@testopt\eql@testopt@loose@ampsafe
  \let\@ifstar\eql@ifstar@loose@ampsafe
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Error Messages}
%
%   \macro{\eql@error}
%   \macro{\eql@warning}
% Main error and warning message function for the package:
%    \begin{macrocode}
\def\eql@error#1{\PackageError{eqnlines}{#1}{}}
\def\eql@warning{\PackageWarning{eqnlines}}
%    \end{macrocode}
%
%   \macro{\eql@error@nomathmode}
%   \macro{\eql@error@mathmode}
% Error messages concerning math mode:
%    \begin{macrocode}
\def\eql@error@nomathmode#1{\eql@error{#1 allowed only in math mode}}
\def\eql@error@mathmode#1{\eql@error{#1 allowed only in paragraph mode}}
%    \end{macrocode}
%
%   \macro{\eql@warn@label@unused}
%   \macro{\eql@warn@label@multiple}
%   \macro{\eql@warn@tag@unused}
%   \macro{\eql@warn@tag@multiple}
% Warning messages concerning unused and multiply declared labels and tags:
%    \begin{macrocode}
\def\eql@warn@label@unused{\eql@warning{Unused equation \string\label:
      label `\eql@nextlabel' will be lost}}
\def\eql@warn@label@multiple#1{\eql@warning{Multiple equation \string\label's:
      previous label '#1' will be lost}}
\def\eql@warn@tag@unused{\eql@warning{Unused equation \string\tag:
      tag declaration will be lost}}
\def\eql@warn@tag@multiple{\eql@warning{Multiple equation \string\tag's:
      previous tag declaration will be lost}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{amsmath Integration}
%
%   \macro{\eql@amsmath@after}
%   \macro{\eql@amsmath@futurebefore}
% We need to overwrite certain macros from \ctanpkg{amsmath}.
% The method |\eql@amsmath@after| executes argument |#1|
% after loading \ctanpkg{amsmath} is loaded.
% It also runs the code if \ctanpkg{amsmath} has already been loaded.
% Furthermore, loading \ctanpkg{amsmath} requires
% certain macros to be undefined. To this end
% |\eql@amsmath@futurebefore| will execute argument |#1|
% before any future loading of \ctanpkg{amsmath}:
%    \TODO might use |\@for| for undefine
%    \begin{macrocode}
\def\eql@amsmath@after#1{\AddToHook{package/amsmath/after}{#1}}
\def\eql@amsmath@futurebefore#1{%
  \@ifpackageloaded{amsmath}{}{\AddToHook{package/amsmath/before}{#1}}}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Parameters and Registers}
%
% In the following, we collect parameter and register definitions.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Supporting Definitions}
%
%   \ebool{\eql@false}
%   \ebool{\eql@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@false\@undefined
\let\eql@true\@empty
%    \end{macrocode}
%
%   \lskip{\eql@regunset@}
%   \macro{\eql@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@regsetdelayed| performs the delayed initialisation:
%    \begin{macrocode}
\newskip\eql@regunset@
\eql@regunset@-1sp\relax
\def\eql@regsetdelayed#1#2{%
  #1\eql@regunset@\relax
  \AtBeginDocument{%
    \ifdim#1=\eql@regunset@
      \setlength#1{#2}%
    \fi
  }%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Parameters}
%
% \TODO maybe sort parameters into sections
% \TODO or sort parameters in sections here
%
%   \ebool{\eql@tagsleft}
% The boolean parameter |\eql@tagsleft|
% specifies whether the tags are placed at the left or right margin:
%    \begin{macrocode}
\let\eql@tagsleft\eql@false
%    \end{macrocode}
%
%   \ebool{\eql@flushleft}
% The boolean parameter |\eql@flushleft|
% specifies whether the layout is flush left or centered:
%    \begin{macrocode}
\let\eql@flushleft\eql@false
%    \end{macrocode}
%
%   \ldimen{\eql@flushleftmargin@}
%   \ldimen{\eql@flushleftmarginmin@}
%   \ldimen{\eql@flushleftmarginmax@}
% The default width of the left margin in flush-left mode
% is specified by |\eql@flushleftmargin@|.
% It may be pushed down to |\eql@flushleftmarginmin@|
% and up to |\eql@flushleftmarginmax@|:
%    \begin{macrocode}
\newdimen\eql@flushleftmargin@
\newdimen\eql@flushleftmarginmin@
\newdimen\eql@flushleftmarginmax@
\eql@regsetdelayed\eql@flushleftmargin@\leftmargini
\eql@flushleftmarginmin@\z@
\eql@flushleftmarginmax@.5\maxdimen
%    \end{macrocode}
%
%   \ldimen{\eql@tagmargin@}
% The intended margin width for tags in centered layout
% is specified by |\eql@tagmargin@|:
%    \begin{macrocode}
\newdimen\eql@tagmargin@
\eql@tagmargin@\z@
%    \end{macrocode}
%
%   \ldimen{\eql@indent@}
% The currently selected indentation width is speficied by |\eql@indent@|.
% This dimension register is set to the macro |\eql@indent@val|
% when entering the equation environments:
%    \begin{macrocode}
\newdimen\eql@indent@
\def\eql@indent@val{2em}
%    \end{macrocode}
%
%   \ldimen{\eql@paddingleft@}
%   \ldimen{\eql@paddingright@}
% The padding of an equation (column) is specified by
% |\eql@paddingleft@| and |\eql@paddingright@|.
% These dimension registers are set to the macros
% |\eql@paddingleft@val| and |\eql@paddingright@val|, respectively,
% when entering the equation environments:
%    \begin{macrocode}
\newdimen\eql@paddingleft@
\newdimen\eql@paddingright@
\def\eql@paddingleft@val{0pt}
\def\eql@paddingright@val{0pt}
%    \end{macrocode}
%
%   \ebool{\eql@paddingmax}
% The boolean register |\eql@paddingmax| specifies
% whether the full line should be used for padding:
%    \begin{macrocode}
\let\eql@paddingmax\eql@false
%    \end{macrocode}
%
%   \macro{\eql@box@marginleft}
%   \macro{\eql@box@marginright}
% The macros |\eql@box@marginleft| and |\eql@box@marginright|
% specify the margin surrounding equation boxes:
%    \begin{macrocode}
\def\eql@box@marginleft{\z@skip}
\def\eql@box@marginright{\z@skip}
%    \end{macrocode}
%
%   \macro{\eql@box@colsep}
% The macro |\eql@box@colsep| specifies the intercolumn separation
% for equation boxes:
%    \begin{macrocode}
\def\eql@box@colsep{2em}
%    \end{macrocode}
%
%   \macro{\eql@spread}
% The extra spread of equation lines is specified by |\eql@spread|:
%    \begin{macrocode}
\def\eql@spread{\jot}
%    \end{macrocode}
%
%   \ldimen{\eql@tagfuzz@}
% The value |\eql@tagfuzz@| specifies the margin of error for
% comparing whether a tag fits a given equation line.
% We should not expect rounding errors in the fixed point arithmetic of \TeX,
% nevertheless:
% \TODO probably do not need this due to fixed point arithmetic.
%    \begin{macrocode}
\newdimen\eql@tagfuzz@
\eql@tagfuzz@16sp\relax
%    \end{macrocode}
%
%   \lskip{\eql@abovedisplayskip@}
%   \lskip{\eql@belowdisplayskip@}
% We need two registers |\eql@abovedisplayskip@| and
% |\eql@belowdisplayskip@| to feed values
% to the final adjustment section after the end of |\halign|
% where |\setlength| of \ctanpkg{calc} would fail:
%    \begin{macrocode}
\newskip\eql@abovedisplayskip@
\newskip\eql@belowdisplayskip@
%    \end{macrocode}
%
%   \lskip{\eql@abovedisplaytagskip@}
%   \lskip{\eql@belowdisplaytagskip@}
%    \begin{macrocode}
\newskip\eql@abovedisplaytagskip@
\newskip\eql@belowdisplaytagskip@
\eql@abovedisplaytagskip@\z@skip
\eql@belowdisplaytagskip@\z@skip
%    \end{macrocode}
%
%   \tcounter{\eql@displayshortmode@}
% The setting |\eql@displayshortmode@| specifies
% when a reduced amount of glue should be used around equations
% in case the text line above the equation fits in the space
% that is left available in the first equation line.
% Value |0| turns this feature off,
% value |1| reduces the glue above the equation,
% value |2| furthermore reduces the glue below a single equation line and
% value |3| also reduces the glue below multi-line equations:
%    \begin{macrocode}
\newcount\eql@displayshortmode@
\eql@displayshortmode@\tw@
%    \end{macrocode}
%
%   \lskip{\eql@abovedisplaycontskip@}
% The glue when an equation is at the top of a horizontal list
% is specified by |\eql@abovedisplaycontskip@|:
%    \begin{macrocode}
\newskip\eql@abovedisplaycontskip@
\eql@regsetdelayed\eql@abovedisplaycontskip@\abovedisplayshortskip
%    \end{macrocode}
%
%   \lskip{\eql@abovedisplaytopskip@}
%   \lskip{\eql@belowdisplaytopskip@}
% The glue when an equation is at the top of a vertical list
% is specified by |\eql@abovedisplaytopskip@|
% and |\eql@belowdisplaytopskip@|:
%    \begin{macrocode}
\newskip\eql@abovedisplaytopskip@
\newskip\eql@belowdisplaytopskip@
\eql@abovedisplaytopskip@\z@skip
\eql@regsetdelayed\eql@belowdisplaytopskip@\belowdisplayskip
%    \end{macrocode}
%
%   \lskip{\eql@abovedisplayparskip@}
% The glue when an equation starts a paragraph
% is specified by |\eql@abovedisplaytopskip@|:
%    \begin{macrocode}
\newskip\eql@abovedisplayparskip@
\eql@regsetdelayed\eql@abovedisplayparskip@\abovedisplayskip
%    \end{macrocode}
%
%   \macro{\eql@display@height}
%   \macro{\eql@display@depth}
% An equation will appear to the surrounding text
% with a fixed apparent height and depth specified
% by |\eql@display@height| and |\eql@display@depth|, respectively.
% By default it appears as a strut for equations:
%    \begin{macrocode}
\def\eql@display@height{\ht\eql@strutbox@}
\def\eql@display@depth{\dp\eql@strutbox@}
%    \end{macrocode}
%
%   \lskip{\eql@abovedisplaymedskip@}
%   \lskip{\eql@belowdisplaymedskip@}
% The surrounding glue for an equation with reduced spacing
% is given by |\eql@abovedisplaymedskip@| and |\eql@belowdisplaymedskip@|:
%    \begin{macrocode}
\newskip\eql@abovedisplaymedskip@
\newskip\eql@belowdisplaymedskip@
\eql@regsetdelayed\eql@abovedisplaymedskip@\belowdisplayshortskip
\eql@regsetdelayed\eql@belowdisplaymedskip@\eql@belowdisplaymedskip@
%    \end{macrocode}
%
%   \ldimen{\eql@colsepmin@}
%   \ldimen{\eql@colsepmax@}
%   \macro{\eql@colsepmin@val}
%   \macro{\eql@colsepmax@val}
% The minimum and maximum intercolumn separatation is specified
% by |\eql@colsepmin@| and |\eql@colsepmax@|.
% These dimension registers are set to the macros
% |\eql@colsepmin@val| and |\eql@colsepmax@val|, respectively,
% when entering the equation environments
% to allow font-dependent values including \ctanpkg{calc} evaluations:
%    \begin{macrocode}
\newdimen\eql@colsepmin@
\newdimen\eql@colsepmax@
\def\eql@colsepmin@val{1em}
\def\eql@colsepmax@val{.5\maxdimen}
%    \end{macrocode}
%
%   \ldimen{\eql@tagwidthmin@}
% The minimum tag width is specified by |\eql@tagwidthmin@|:
%    \begin{macrocode}
\newdimen\eql@tagwidthmin@
\eql@tagwidthmin@\z@
%    \end{macrocode}
%
%   \ldimen{\eql@tagsepmin@}
% The minimum separation between an equation and its tag
% is given by |\eql@tagsepmin@|.
% \TeX's built-in value is half a quad in
% font number 2 (|.5\fontdimen6\textfont\tw@|).
% As the tag is processed in text mode, we use |0.5em| instead.
% \TODO may set within environment
%    \begin{macrocode}
\newdimen\eql@tagsepmin@
\eql@regsetdelayed\eql@tagsepmin@{.5em}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Registers}
%
%   \tcounter{\eql@row@}
%   \tcounter{\eql@totalrows@}
% |\eql@row@| counts the present row (1-based)
% and |\eql@totalrows@| holds the total number of rows:
%    \begin{macrocode}
\newcount\eql@row@
\newcount\eql@totalrows@
%    \end{macrocode}
%
%   \ldimen{\eql@colsep@}
% The dimension of the intercolumn separation for align environments
% is stored in |\eql@colsep@|:
%    \begin{macrocode}
\newdimen\eql@colsep@
%    \end{macrocode}
%
%   \ldimen{\eql@display@firstavail@}
%   \macro{\eql@display@firstavail@set}
% The unused space on the first line of an alignment is stored in
% |\eql@display@firstavail@| for comparison against
% |\predisplaysize| and determining short skip mode of display equations.
% It it convenient to set it via |\eql@display@firstavail@set|
% provided that we are on the first line:
%    \begin{macrocode}
\newdimen\eql@display@firstavail@
\def\eql@display@firstavail@set#1{%
  \ifnum\eql@row@=\@ne
    \global\eql@display@firstavail@#1%
  \fi
}
%    \end{macrocode}
%
%   \tcounter{\eql@raisetag@firstlast@}
% The counter stores whether the tag one first/last line is
% raised/lowered as |1|/|2| (or |3| for both).
% This implies a different vskip corresponding to the
% mostly empty line:
%    \begin{macrocode}
\newcount\eql@raisetag@firstlast@
%    \end{macrocode}
%
%   \lbox{\eql@fieldbox@}
%   \lbox{\eql@tagbox@}
%   \ldimen{\eql@fieldwidth@}
%   \ldimen{\eql@tagwidth@}
% The box |\eql@fieldbox@| holds the present alignment component
% and |\eql@tagbox@| the tag for the present line.
% The corresponding dimensions |\eql@fieldwidth@| and |\eql@tagwidth@|
% hold their widths:
%    \begin{macrocode}
\newbox\eql@fieldbox@
\newbox\eql@tagbox@
\newdimen\eql@fieldwidth@
\newdimen\eql@tagwidth@
%    \end{macrocode}
%
%   \ldimen{\eql@line@height@}
%   \ldimen{\eql@line@depth@}
% The dimension registers |\eql@line@height@| and |\eql@line@depth@| keep
% track of the height and depth of the present line in an alignment:
%    \begin{macrocode}
\newdimen\eql@line@height@
\newdimen\eql@line@depth@
%    \end{macrocode}
%
%   \lcond{\ifmeasuring@}
% All display environments get typeset twice -- once during a
% ``measuring'' phase and then again during a ``production'' phase.
% We reuse the original \ctanpkg{amsmath} definition |\ifmeasuring@|
% to determine which case we're in,
% so we and other packages may take appropriate action.
% It does not hurt to define this conditional in any case.
% We should tell \ctanpkg{hyperref} about measuring processes
% as we're not \ctanpkg{amsmath} and not being catered for:
%    \begin{macrocode}
\newif\ifmeasuring@
\AddToHook{package/hyperref/after}{
  \ifdefined\Hy@ifnotmeasuring
    \renewcommand\Hy@ifnotmeasuring[1]{\ifmeasuring@\else#1\fi}
  \fi
}
%    \end{macrocode}
%
%   \lcond{\if@display}
% \ctanpkg{amsmath} defines the conditional |\||if@display|
% to test whether we're in a display equation
% including the inner math parts of equation blocks.
% We provide it in case \ctanpkg{amsmath} is absent,
% and initialise it:
%    \begin{macrocode}
\ifdefined\@displaytrue\else
\everydisplay\expandafter{\the\everydisplay\@displaytrue}
\fi
\newif\if@display
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Hooks}
%
%   \macro{\eql@hook@...}
% For what it's worth, we define a couple of entry points
% where one might hook into the equations typesetting framework.
% The \LaTeX{} hook framewould would be more versatile,
% but as the purpose of these hooks is rather unclear at the moment,
% we make this as efficient as it could get:
%   \TODO may add a few more hooks
%    \begin{macrocode}
\let\eql@hook@blockbefore\@empty
\let\eql@hook@blockafter\@empty
\let\eql@hook@blockin\@empty
\let\eql@hook@blockout\@empty
\let\eql@hook@linein\@empty
\let\eql@hook@lineout\@empty
\let\eql@hook@colin\@empty
\let\eql@hook@colout\@empty
\let\eql@hook@eqin\@empty
\let\eql@hook@eqout\@empty
\let\eql@hook@innerleft\@empty
\let\eql@hook@innerright\@empty
\let\eql@hook@innerlead\@empty
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Punctuation}
%
% The equations environments supply an automatic punctuation scheme
% which allows to define a default punctuation
% at the end of each column, line and equation block.
%
%   \macro{\eql@punct@col}
%   \macro{\eql@punct@line}
%   \macro{\eql@punct@block}
% These macros store the punctuation character for columns, lines and blocks.
% A value |\relax| indicates that the punctuation should be handed
% down to the next lower level:
%    \begin{macrocode}
\let\eql@punct@col\@empty
\let\eql@punct@line\relax
\let\eql@punct@block\relax
%    \end{macrocode}
%
%   \macro{\eql@punct@sep}
% This macro stores the separation to be applied
% before the punctuation (unless it is empty):
%    \begin{macrocode}
\let\eql@punct@sep\relax
%    \end{macrocode}
%
%   \imacro{\eqnpunctcol}
%   \imacro{\eqnpunctline}
%   \imacro{\eqnpunctmain}
%   \imacro{\eqnpunct}
% Set the punction for columns, lines and blocks.
% Note that the macro |\eqnpunct| sets the punctuation for the
% next equation block (only).
% Starred versions clear the punctuation for the respectively levels:
%    \begin{macrocode}
\def\eqnpunctcol{\eql@ifstar@tight\eql@punct@col@setrelax\eql@punct@col@set}
\def\eql@punct@col@set#1{\def\eql@punct@col{#1}\ignorespaces}
\def\eql@punct@col@setrelax{\let\eql@punct@col\@empty\ignorespaces}
\def\eqnpunctline{\eql@ifstar@tight\eql@punct@line@setrelax\eql@punct@line@set}
\def\eql@punct@line@set#1{\def\eql@punct@line{#1}\ignorespaces}
\def\eql@punct@line@setrelax{\let\eql@punct@line\relax\ignorespaces}
\def\eqnpunctmain{\eql@ifstar@tight\eql@punct@main@setrelax\eql@punct@main@set}
\def\eql@punct@main@set#1{\eqnlinesset{punct={#1}}\ignorespaces}
\def\eql@punct@main@setrelax{\eqnlinesset{punct*}\ignorespaces}
\def\eqnpunct{\eql@ifstar@tight\eql@punct@next@setrelax\eql@punct@next@set}
\def\eql@punct@next@set#1{\eqnaddopt{punct={#1}}\ignorespaces}
\def\eql@punct@next@setrelax{\eqnaddopt{punct*}\ignorespaces}
%    \end{macrocode}
%
%   \macro{\eql@punct@apply@col}
% Output the punctuation for the present column.
% If non-empty, prepend some separation.
% Clear the punctuation so that no further
% column punctuation is output within the current group:
%    \begin{macrocode}
\def\eql@punct@apply@col{%
  \ifx\eql@punct@col\@empty\else
    \eql@punct@sep
    \eql@punct@col
    \let\eql@punct@col\@empty
  \fi
}
%    \end{macrocode}
%
% Output the punctuation currently set for lines unless disabled.
% Alike |\eql@punct@apply@col| prevent further output
% of punctuations for lines and columns within the current group:
%   \macro{\eql@punct@apply@line}
%    \begin{macrocode}
\def\eql@punct@apply@line{%
  \ifx\eql@punct@line\relax
% \TODO hand down immediately?
  \else
    \ifx\eql@punct@line\@empty\else
      \eql@punct@sep
      \eql@punct@line
    \fi
    \let\eql@punct@line\relax
    \let\eql@punct@col\@empty
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@punct@apply@block}
% Outputs the punctuation for the current equation block unless disabled
% in analogy to |\eql@punct@apply@line|:
%    \begin{macrocode}
\def\eql@punct@apply@block{%
  \ifx\eql@punct@block\relax
% \TODO hand down immediately?
  \else
    \ifx\eql@punct@block\@empty\else
      \eql@punct@sep
      \eql@punct@block
    \fi
    \let\eql@punct@block\relax
    \let\eql@punct@line\relax
    \let\eql@punct@col\@empty
  \fi
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Math Classes at Alignment}
%
% The following describes the adjustment of math classes
% surrounding the alignment marker.
%
%   \macro{\eql@class@innerright@sel@}
% Select between |\eql@class@innerlead| and |\eql@class@innerright|
% depending on whether the left part of the aligned column is empty:
%    \begin{macrocode}
\def\eql@class@innerright@sel@{%
  \ifdim\eql@fieldwidth@=\z@
    \eql@class@innerlead
  \else
    \eql@class@innerright
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@class@innerleft@set}
%   \macro{\eql@class@innerright@set}
%   \macro{\eql@class@innerlead@set}
% Set the left, right and leading math classes.
% Setting the right math class disables the leading math class,
% so the leading math class must be specified after the right one:
%    \begin{macrocode}
\def\eql@class@innerleft@set#1{%
  \def\eql@class@innerleft{#1}%
}
\def\eql@class@innerright@set#1{%
  \def\eql@class@innerright{#1}%
  \let\eql@class@innerright@sel\eql@class@innerright
}
\def\eql@class@innerlead@set#1{%
  \def\eql@class@innerlead{#1}%
  \let\eql@class@innerright@sel\eql@class@innerright@sel@
}
%    \end{macrocode}
%
%   \macro{\eql@class@ampeq}
%   \macro{\eql@class@eqamp}
% We define two standard combinations of math classes
% intended to be used with `|&=|' (|ampeq|) or `|=&|' (|eqamp|).
% The default setting is `|&=|' (|ampeq|):
%    \begin{macrocode}
\def\eql@class@ampeq{%
  \eql@class@innerleft@set{}%
  \eql@class@innerright@set{{}}%
}
\def\eql@class@eqamp{%
  \eql@class@innerleft@set{\mathrel{}}%
  \eql@class@innerright@set{\mathrel{}}%
  \eql@class@innerlead@set{{}}%
}
\eql@class@ampeq
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Equations Box Environment}
%
% \TODO describe
%
% \TODO fixed width version (works only towards intercolumn stretch)?
%
%   \macro{\eql@box@cr}
%    \begin{macrocode}
\protected\def\eql@box@cr{%
  \eql@ampprotect\eql@testopt@tight\eql@box@cr@\z@
}
\def\eql@box@cr@[#1]{%
  \eql@punct@apply@line
  \eql@hook@lineout
  \eql@box@lastfield
  \cr
  \noalign{%
    \setlength\skip@{#1}%
    \vskip\skip@
  }%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@box@box\vcenter
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@lastfield@odd{%
  &\omit
  \kern-\wd\eql@fieldbox@
  \box\eql@fieldbox@
  \hfil
  &\omit\kern-\eql@colsep@
}%
\def\eql@box@lastfield@even{&\omit\kern-\eql@colsep@}
\def\eql@box@lastfield@lines{&\omit\kern-2\eql@colsep@}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@open@align{%
% \TODO templates
  \let\eql@box@lastfield\@empty
  \eql@halign@init{%
%<dev>\eql@dev{starting new line}%
}%
  \tabskip\z@skip
  \halign\bgroup
      &%
      \let\eql@box@lastfield\eql@box@lastfield@odd
      \global\setbox\eql@fieldbox@\hbox{%
        \eql@strut@field
        \@lign
        $\m@th\displaystyle
          \eql@hook@colin
          ##%
          \eql@class@innerleft
          \eql@hook@innerleft
        $%
      }%
      \hfil
      \kern\wd\eql@fieldbox@
      \tabskip\z@skip
      &%
      \eql@fieldwidth@\wd\eql@fieldbox@
      \kern-\eql@fieldwidth@
      \box\eql@fieldbox@
      \let\eql@box@lastfield\eql@box@lastfield@even
      \llap{\unhbox\eql@fieldbox@}%
      \hbox{%
        \eql@strut@field
        \@lign
        $\m@th\displaystyle
          \eql@hook@innerright
          \eql@class@innerright@sel
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
        $%
      }%
      \hfil
      \tabskip\eql@colsep@
    \crcr
    \noalign{%
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@open@lines{%
% \TODO templates
  \let\shoveleft\eql@adjust@shoveleft
  \let\shovecenter\eql@adjust@shovecenter
  \let\shoveright\eql@adjust@shoveright
  \let\eql@box@lastfield\eql@box@lastfield@lines
  \eql@halign@init{%
%<dev>\eql@dev{starting line \the\eql@row@}%
    \global\advance\eql@row@\@ne
  }%
  \tabskip\z@skip
  \halign\bgroup
    &%
    \eql@shape@pos@\m@ne
    \setbox\eql@fieldbox@\hbox{%
      \eql@strut@field
      \@lign
      $\m@th\displaystyle
        \eql@hook@colin
        ##%
        \eql@punct@apply@col
        \eql@hook@colout
      $%
    }%
    \ifnum\eql@shape@pos@=\m@ne
      \eql@shape@eval
    \fi
    \ifcase\eql@shape@pos@
      \kern\eql@shape@amount@
      \box\eql@fieldbox@
      \skip@\@flushglue
      \advance\skip@\eql@paddingleft@\relax
      \advance\skip@\eql@paddingright@\relax
      \advance\skip@-\eql@shape@amount@\relax
      \hskip\skip@
    \or
      \skip@\@flushglue
      \advance\skip@\eql@paddingleft@\relax
      \hskip\skip@
      \box\eql@fieldbox@
      \skip@\@flushglue
      \advance\skip@\eql@paddingright@\relax
      \hskip\skip@
    \or
      \skip@\@flushglue
      \advance\skip@\eql@paddingleft@\relax
      \advance\skip@\eql@paddingright@\relax
      \hskip\skip@
      \box\eql@fieldbox@
    \fi
    \tabskip\eql@colsep@
    \crcr
    \noalign{%
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@close{%
    \ifvmode\else
      \global\eql@totalrows@\eql@row@
      \eql@punct@apply@block
      \eql@box@cr@[\z@skip]%
    \fi
    \crcr
    \noalign{%
      \eql@hook@blockafter
    }%
  \egroup
}
%    \end{macrocode}
%
%   \macro{\eql@box@start}
%    \begin{macrocode}
\def\eql@box@start{%
  \relax
  \ifmmode
    \let\eql@box@endmath\@empty
  \else
    $\let\eql@box@endmath=$%
  \fi
  \eql@nextopt@process{equationsbox}%
  \let\eql@punct@block\eql@punct@main
  \let\eql@punct@main\relax
  \setlength\eql@colsep@\eql@box@colsep
  \setlength\eql@paddingleft@\eql@paddingleft@val
  \setlength\eql@paddingright@\eql@paddingright@val
  \setlength\eql@indent@\eql@indent@val
  \eql@stack@save@boxed
  \let\eql@flushleft\eql@false
  \eql@row@\z@
  \eql@totalrows@\@M
  \eql@shape@sel
  \setlength\skip@\eql@box@marginleft
  \hskip\skip@
  \eql@box@box\bgroup
    \eql@display@leave
    \let\\\eql@box@cr
    \ifdefined\eql@box@mode@lines
      \expandafter\eql@box@open@lines
    \else
      \expandafter\eql@box@open@align
    \fi
}
%    \end{macrocode}
%
%   \macro{\eql@box@end}
%    \begin{macrocode}
\newcommand{\eql@box@end}{%
    \eql@box@close
  \egroup
  \setlength\skip@\eql@box@marginright
  \hskip\skip@
  \eql@stack@restore
  \eql@box@endmath
}
%    \end{macrocode}
%
% \environment{equationsbox}
%    \begin{macrocode}
\newenvironment{equationsbox}{%
%<dev>\eql@dev@enterenv
  \eql@ampprotect\eql@box@testall\eql@box@start
}{%
  \eql@box@end
%<dev>\eql@dev@leaveenv
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@testall{\eql@box@testtilde}
\def\eql@box@testtilde#1{%
  \eql@ifnextgobble@tight~%
    {\eqnaddopt{lines}\eql@box@testopt{#1}}%
    {\eql@box@testopt{#1}}}
\def\eql@box@testopt#1{%
  \eql@ifnextchar@tight[%]
    {\eql@box@addopt{#1}}%
    {#1}}
\def\eql@box@addopt#1[#2]{\eqnaddopt{#2}#1}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@mode@aligned{\let\eql@box@mode@lines\eql@false}
\def\eql@mode@lined{\let\eql@box@mode@lines\eql@true}
\eql@mode@aligned
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Subequation Numbering}
%
% We replicate the \ctanpkg{amsmath} functionality to
% number a block of equations with a common number and
% a sub-numbering.
%
%   \lcounter{parentequation}
% We define a counter to store the main equation number
% while in subequation mode.
% It makes sense to share this definition
% with \ctanpkg{amsmath} as |parentequation|,
% and we need to undefine it when \ctanpkg{amsmath}
% is loaded at a later stage:
%    \begin{macrocode}
\eql@amsmath@futurebefore{
  \let\c@parentequation\@undefined
  \let\theparentequation\@undefined
}
\ifdefined\c@parentequation\else
\newcounter{parentequation}
\fi
%    \end{macrocode}
%
%   \macro{\eql@subequations@template}
% We store a template which will installed as |\theequation|
% in subequations mode:
% \TODO need to protect something?!
%    \begin{macrocode}
\def\eql@subequations@template{\theparentequation\alph{equation}}
%    \end{macrocode}
%
%   \macro{\eql@subequations@active}
% A boolean register which tells whether subequations are in use
% and thus must not be invoked again:
%    \begin{macrocode}
\let\eql@subequations@active\eql@false
%    \end{macrocode}
%
%   \macro{\eql@subequations@init}
% Low-level initialise the subequations mode.
% Store the equation counter in |\eql@subequations@restorecounter|
% for the case that no equation numbers will be used.
% Step the equation counter, copy it to |parentequation|
% and initialise |\theparentequation|
% (and its \ctanpkg{hyperref} counterpart)
% with the expanded current value of |\theequation|;
% fill with tag data instead if a tag has been specified.
% Reset the equation counter and use the template
% for |\thequation|:
%    \begin{macrocode}
\def\eql@subequations@init{%
  \edef\eql@subequations@restorecounter{%
    \global\c@equation\the\c@equation\relax}%
  \ifdefined\eql@blocktag
    \expandafter\eql@tag@makenext\eql@blocktag
    \eql@nexttag
    \global\advance\eql@numbering@refcount@\@ne
    \protected@edef\theHparentequation{eql-\the\eql@numbering@refcount@}%
    \protected@edef\theparentequation{\eql@tag@text}%
  \else
    \advance\c@equation\@ne
    \protected@edef\theparentequation{\theequation}%
    \ifdefined\theHequation
      \protected@edef\theHparentequation{\theHequation}%
    \fi
  \fi
  \global\c@parentequation\c@equation
  \global\c@equation\z@
  \let\theequation\eql@subequations@template
  \def\theHequation{\theHparentequation.\arabic{equation}}%
}
%    \end{macrocode}
%
%   \macro{\eql@subequations@close}
% Low-level close the subequations mode.
% If no number has been used, return to the original equation counter,
% otherwise use the value stored in |parentequation|.
% Note that we cannot use |\setcounter| here because the
% \ctanpkg{calc} version would involve actions which are not
% allowed after |\halign| within a display equation:
%    \begin{macrocode}
\def\eql@subequations@close{%
  \ifnum\c@equation=\z@
    \eql@subequations@restorecounter
  \else
    \global\c@equation\c@parentequation
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@subequations@start}
% Start the subequations environment with optional parameters in |#1|.
% Enter subequations mode and set an anchor for subsequent |\label|'s.
% Manually print the \ctanpkg{showkeys} tag:
% \TODO join with other similar anchor routines |\eql@numbering@printsubeqlabel|
%    \begin{macrocode}
\def\eql@subequations@start{%
  \let\eql@blocktag\@undefined
  \let\eql@blocklabel\@undefined
  \eql@nextopt@process{subequations}%
  \eql@subequations@init
  \global\advance\eql@numbering@refcount@\@ne
  \edef\eql@subequations@currentHref{equation.eql-\the\eql@numbering@refcount@}%
  \eql@Hy@anchor\eql@subequations@currentHref
  \edef\eql@subequations@thepage{\thepage}%
  \def\@currentcounter{equation}%
  \let\@currentHref\eql@subequations@currentHref
  \protected@edef\@currentlabel{\p@equation\theparentequation}%
  \let\@currentlabelname\eql@labelname@default
  \let\eql@subequations@active\eql@true
  \ifdefined\eql@blocklabel
    \ifdefined\eql@SK
      \SK@\SK@@label\eql@blocklabel
    \fi
  \fi
  \ignorespaces
}
%    \end{macrocode}
%
%   \macro{\eql@subequations@end}
% End the subequations environment.
% Issue the label if one has been specified and
% an equation number has actually been used.
% Then close subequations mode:
%    \begin{macrocode}
\def\eql@subequations@end{%
  \ifnum\c@equation>\z@
    \ifdefined\eql@blocklabel
      \begingroup
        \def\@currentcounter{equation}%
        \let\thepage\eql@subequations@thepage
        \let\@currentHref\eql@subequations@currentHref
% \TODO how about tag* ?! also within equations!
        \protected@edef\@currentlabel{\p@equation\theparentequation}%
        \let\@currentlabelname\eql@labelname@default
        \expandafter\eql@label@clean\expandafter{\eql@blocklabel}%
      \endgroup
    \fi
  \fi
  \eql@subequations@close
  \ignorespacesafterend
}
%    \end{macrocode}
%
%   \environment{subequations}
% The subequations environment tests for optional parameters
% and passes on to the start and end routines:
%    \begin{macrocode}
\newenvironment{eql@subequations}{%
%<dev>\eql@dev@enterenv
  \eql@subequations@testall\eql@subequations@start%
}{%
  \eql@subequations@end
%<dev>\eql@dev@leaveenv
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@subequations@testall{\eql@subequations@testopt}
\def\eql@subequations@testopt#1{%
  \eql@ifnextchar@tight[%]
    {\eql@subequations@addopt{\eql@subequations@testat{#1}}}%
    {\eql@subequations@testat{#1}}}
\def\eql@subequations@addopt#1[#2]{\eqnaddopt{#2}#1}
\def\eql@subequations@testat#1{%
  \eql@ifat@tight%
    {\eql@subequations@addlabel{#1}}%
    {#1}}
\def\eql@subequations@addlabel#1#2{\eqnaddopt{label={#2}}#1}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Equation Numbering}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Macros Shared with Amsmath}
%
% \TODO describe
%
%   \macro{\maketag@@@}
%    \begin{macrocode}
\ifdefined\maketag@@@\else
\def\maketag@@@#1{\hbox{\m@th\normalfont#1}}
\fi
%    \end{macrocode}
%
%   \macro{\tagform@}
%    \begin{macrocode}
\ifdefined\tagform@\else
\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}
\fi
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tag@setmake@#1{%
  \def\maketag@@@##1{\hbox{\m@th\normalfont#1}}%
}
\def\eql@tag@setmake#1{%
  \def\maketag@@@##1{\hbox{\m@th\normalfont#1}}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tag@setform@#1{%
  \def\tagform@##1{\maketag@@@{#1}}%
}
\def\eql@tag@setform#1#2#3{%
  \def\tagform@##1{\maketag@@@{#1\ignorespaces#2\unskip\@@italiccorr#3}}%
}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \paragraph{raise tags}
%
%   \ldimen{\eql@raisetag@amount@}
%    \begin{macrocode}
\newdimen\eql@raisetag@amount@
%    \end{macrocode}
%
%   \macro{\raisetag}
%    \begin{macrocode}
\def\eql@raisetag@default{%
  \eql@warning{\string\raisetag\space not allowed here}
  \@gobble
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@amsmath@after{\let\eql@raisetag@default\raisetag}
\eql@amsmath@futurebefore{\let\raisetag\@undefined}
\let\raisetag\eql@raisetag@default
%    \end{macrocode}
%
%    \TODO maybe introduce a star form to enforce raise?
%    \begin{macrocode}
\def\eql@raisetag#1{\setlength\dimen@{#1}\global\eql@raisetag@amount@\dimen@}%
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Showkeys Integration}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@SK\@undefined
\let\eql@SK@lab@relax\@empty
\let\eql@SK@makelabel\@gobble
\let\eql@SK@printlabel@right\@empty
\let\eql@SK@printlabel@left\@empty
\let\eql@SK@printlabel@line\@empty
\def\eql@label@clean{\eql@label@org}
\AddToHook{package/showkeys/after}{
  \let\eql@SK\@empty
  \def\eql@SK@lab@relax{\let\eql@SK@lab\relax}
  \eql@SK@lab@relax
  \def\eql@SK@@label#1>#2\SK@{%
    \def\eql@SK@lab{\smash{\SK@labelcolor\showkeyslabelformat{#2}}}%
  }
  \def\eql@SK@makelabel#1{%
    \SK@\eql@SK@@label#1%
  }
  \def\eql@SK@printlabel@right{%
    \ifx\eql@SK@lab\relax\else
      \rlap{\kern\marginparsep\eql@SK@lab}%
      \eql@SK@lab@relax
    \fi
  }
  \def\eql@SK@printlabel@left{%
    \ifx\eql@SK@lab\relax\else
      \llap{\eql@SK@lab\kern\marginparsep}%
      \eql@SK@lab@relax
    \fi
  }
  \def\eql@SK@printlabel@line{%
    \ifx\eql@SK@lab\relax\else
      \dimen@\prevdepth
      \nointerlineskip
      \ifdefined\eql@tagsleft
        \llap{%
          \eql@SK@lab
          \kern\marginparsep
        }%
        \eql@SK@lab@relax
      \else
        \rlap{%
          \dimen@\displaywidth
          \advance\dimen@\marginparsep
          \kern\dimen@
          \eql@SK@lab
        }%
      \fi
      \eql@SK@lab@relax
      \prevdepth\dimen@
    \fi
  }
  \let\eql@label@org\label
  \def\eql@label@clean{\let\SK@\@gobbletwo\eql@label@org}
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Labels}
%
% \TODO describe
%
%    \begin{macrocode}
% \TODO implement (via label[] or labelname similar to label/tag)
\let\eql@nextlabel\@undefined
\def\eql@labelname@default{[equation]}
%    \end{macrocode}
%
%   \macro{\eql@label@org}
%    \begin{macrocode}
\let\eql@label@org\label
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Tags}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@nexttag\@undefined
%    \end{macrocode}
%
%   \macro{\eql@tag@default}
%    \begin{macrocode}
\def\eql@tag@default{%
  \eql@error{\string\tag\space not allowed here}{}\eql@tag@gobble}
\eql@amsmath@after{
  \let\eql@tag@default\tag
}
\let\tag\eql@tag@default
%    \end{macrocode}
%
%   \macro{\eql@tag@gobble}
% \TODO ifnextchar, gobbletwo?
%    \begin{macrocode}
\def\eql@tag@gobble@[#1]#2{}
\def\eql@tag@gobble{%
  \eql@ampprotecttwo\eql@teststaropt@tight\eql@tag@gobble@\eql@tag@gobble@{}}
%    \end{macrocode}
%
%   \macro{\eql@nexttag}
%   \macro{\eql@tag@makenext}
%   \macro{\eql@tag@makenext@@}
%   \macro{\eql@tag@makenext@@@}
% \TODO can amsmath handle also counter refstepcounter in tags?
%
%    hyperref anchors
%    \begin{macrocode}
\let\eql@Hy@anchor\@gobble
\AddToHook{package/hyperref/after}{
  \def\eql@Hy@anchor#1{%
    \Hy@raisedlink{\hyper@anchor{#1}}%
  }%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tag@makenext{%
  \eql@ampprotecttwo\eql@teststaropt@tight
    \eql@tag@makenext@star\eql@tag@makenext@\eql@tag@text
}
%    \end{macrocode}
%
% \TODO not sure about |\protected@edef\eql@tag@text| was |\def| only
%    \begin{macrocode}
\def\eql@tag@makenext@star[#1]#2{%
  \global\def\eql@nexttag{%
    \let\eql@tag@tool\maketag@@@
    \protected@edef\eql@tag@text{#2}%
    \protected@edef\eql@tag@label{#1}%
  }%
}
\def\eql@tag@makenext@[#1]#2{%
  \global\def\eql@nexttag{%
    \let\eql@tag@tool\tagform@
    \protected@edef\eql@tag@text{#2}%
    \protected@edef\eql@tag@label{#1}%
    \protected@edef\eql@tag@label{\p@equation\eql@tag@label}%
  }%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Anchors}
%
% \TODO describe
%
%   \tcounter{\eql@numbering@refcount@}
%    \begin{macrocode}
\newcount\eql@numbering@refcount@
\eql@numbering@refcount@\z@
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@makeblockanchor{%
  \global\advance\eql@numbering@refcount@\@ne
  \global\edef\eql@label@currentHref{equation.eql-\the\eql@numbering@refcount@}%
  \eql@Hy@anchor\eql@label@currentHref
  \global\edef\eql@label@thepage{\thepage}%
}
\def\eql@numbering@setblockanchor{%
  \let\thepage\eql@label@thepage
  \let\@currentHref\eql@label@currentHref
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Tag Composition}
%
% \TODO describe
%
%   \macro{\eql@compose@anchor}
%   \macro{\eql@compose@tag}
%   \macro{\eql@compose@label}
%    \begin{macrocode}
\def\eql@compose@anchor{%
  \ifdefined\eql@nexttag
    \eql@nexttag
    \def\@currentcounter{equation}%
    \let\@currentlabel\eql@tag@label
    \global\advance\eql@numbering@refcount@\@ne
    \edef\@currentHref{equation.eql-\the\eql@numbering@refcount@}%
    \eql@Hy@anchor\@currentHref
    \global\let\eql@nexttag\@undefined
  \else
    \refstepcounter{equation}%
    \let\eql@tag@tool\tagform@
    \edef\eql@tag@text{\theequation}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@compose@label{%
  \ifmeasuring@\else
    \eql@SK@lab@relax
    \ifdefined\eql@nextlabel
      \ifnum
        \ifnum\eql@numbering@target@<\z@
          \eql@row@
        \else
          \eql@numbering@target@
        \fi=\eql@row@
        \eql@compose@label@
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@compose@label@{%
  \eql@SK@makelabel\eql@nextlabel
  \begingroup
    \ifnum\eql@numbering@target@=\eql@row@
      \eql@numbering@setblockanchor
    \fi
    \let\@currentlabelname\eql@labelname@default
    \expandafter\eql@label@clean\expandafter{\eql@nextlabel}%
    \global\let\eql@nextlabel\@undefined
  \endgroup
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@compose@tag{%
  \eql@tag@tool\eql@tag@text
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@compose@print{%
  \eql@compose@anchor
  \eql@compose@label
  \ifdefined\eql@tagsleft
    \eql@SK@printlabel@left
    \eql@compose@tag
  \else
    \eql@compose@tag
    \eql@SK@printlabel@right
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@compose@measure{%
  \ifdefined\eql@nexttag
    \eql@nexttag
    \eql@tag@tool\eql@tag@text
  \else
    \stepcounter{equation}%
    \tagform@\theequation
  \fi
  \ifnum\eql@numbering@target@<\z@
    \global\let\eql@nextlabel\@undefined
    \global\let\eql@nexttag\@undefined
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@compose@null{%
  \ifdefined\eql@nexttag\else
    \stepcounter{equation}%
  \fi
  \ifnum\eql@numbering@target@<\z@
    \global\let\eql@nextlabel\@undefined
    \global\let\eql@nexttag\@undefined
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Tagbox Methods}
%
% \TODO describe
%
%  \TODO one might still compare width to zero and pretend the tag is absent??
%    \begin{macrocode}
\def\eql@tagbox@make#1{%
  \setbox\eql@tagbox@\hbox{\eql@strut@tag\@lign#1}%
  \eql@tagwidth@\wd\eql@tagbox@
  \ifdim\eql@tagwidth@<\eql@tagwidthmin@
    \eql@tagwidth@\eql@tagwidthmin@
  \fi
  \advance\eql@tagwidth@\eql@tagsepmin@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@right{%
  \kern-\wd\eql@tagbox@
  \box\eql@tagbox@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@left{%
  \wd\eql@tagbox@\z@
  \box\eql@tagbox@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@right@raise{%
  \ifnum\eql@row@=\eql@totalrows@
    \global\advance\eql@raisetag@firstlast@\tw@
  \fi
  \llap{\vtop{%
    \vskip-\eql@raisetag@amount@
    \normalbaselines
    \setbox\@ne\hbox{}%
    \dp\@ne\eql@line@depth@
    \box\@ne
    \box\eql@tagbox@
  }}%
}
\def\eql@tagbox@print@left@raise{%
  \ifnum\eql@row@=\@ne
    \global\advance\eql@raisetag@firstlast@\@ne
  \fi
  \rlap{\vbox{%
    \normalbaselines
    \box\eql@tagbox@
    \vbox to\eql@line@height@{}%
    \vskip\eql@raisetag@amount@
  }}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@printsubeqlabel{%
  \ifdefined\eql@parentlabel
    \eql@numbering@makeblockanchor
    \eql@SK@makelabel\eql@parentlabel
    \begingroup
      \def\@currentcounter{equation}%
      \eql@numbering@setblockanchor
      \let\@currentlabelname\eql@labelname@default
      \protected@edef\@currentlabel{\p@equation\theparentequation}%
      \expandafter\eql@label@clean\expandafter{\eql@parentlabel}%
    \endgroup
    \eql@SK@printlabel@line
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Numbering Schemes}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@tab@first{first}
\def\eql@numbering@tab@last{last}
\def\eql@numbering@tab@middle{middle}
\def\eql@numbering@tab@here{here}
\def\eql@numbering@tab@in{in}
\def\eql@numbering@tab@out{out}
\def\eql@numbering@tab@sub{sub}
\def\eql@numbering@tab@all{all}
\def\eql@numbering@tab@none{none}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@tab@f\eql@numbering@tab@first
\let\eql@numbering@tab@l\eql@numbering@tab@last
\let\eql@numbering@tab@m\eql@numbering@tab@middle
\let\eql@numbering@tab@mid\eql@numbering@tab@middle
\let\eql@numbering@tab@o\eql@numbering@tab@out
\let\eql@numbering@tab@outside\eql@numbering@tab@out
\let\eql@numbering@tab@i\eql@numbering@tab@in
\let\eql@numbering@tab@inside\eql@numbering@tab@in
\let\eql@numbering@tab@within\eql@numbering@tab@in
\let\eql@numbering@tab@h\eql@numbering@tab@here
\let\eql@numbering@tab@s\eql@numbering@tab@sub
\let\eql@numbering@tab@subeq\eql@numbering@tab@sub
\let\eql@numbering@tab@subequation\eql@numbering@tab@sub
\let\eql@numbering@tab@subequations\eql@numbering@tab@sub
\let\eql@numbering@tab@a\eql@numbering@tab@all
\let\eql@numbering@tab@n\eql@numbering@tab@none
\expandafter\let\csname eql@numbering@tab@!\endcsname\eql@numbering@tab@all
\expandafter\let\csname eql@numbering@tab@*\endcsname\eql@numbering@tab@none
\expandafter\let\csname eql@numbering@tab@1\endcsname\eql@numbering@tab@first
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@numbering@mode\eql@numbering@tab@all
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@numbering@set#1{%
  \ifcsname eql@numbering@tab@#1\endcsname
    \expandafter\let\expandafter\eql@numbering@mode
      \csname eql@numbering@tab@#1\endcsname
  \else
    \eql@error{numbering mode `#1' unknown: setting to `all'}%
    \let\eql@numbering@mode\eql@numbering@tab@all
  \fi
}
%    \end{macrocode}
%
%   \tcounter{\eql@numbering@target@}
%    \begin{macrocode}
\let\eql@numbering@active\eql@true
\newcount\eql@numbering@target@
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@numbering@mode@all{%
  \eql@numbering@target@\m@ne}
\def\eql@numbering@mode@sub{%
  \eql@numbering@target@\m@ne
  \let\eql@numbering@subeq@use\eql@true}
\def\eql@numbering@mode@none{%
  \eql@numbering@target@\m@ne
  \let\eql@numbering@active\eql@false}
\def\eql@numbering@mode@first{%
  \eql@numbering@target@\@ne}
\def\eql@numbering@mode@last{%
  \eql@numbering@target@\@MM}
\def\eql@numbering@mode@here{%
  \eql@numbering@target@\z@}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@mode@in{%
  \ifdefined\eql@tagsleft
    \eql@numbering@mode@last
  \else
    \eql@numbering@mode@first
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@mode@out{%
  \ifdefined\eql@tagsleft
    \eql@numbering@mode@first
  \else
    \eql@numbering@mode@last
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@mode@middle{%
  \eql@numbering@target@\z@
  \let\eql@numbering@eval@target\eql@numbering@eval@middle}
\def\eql@numbering@eval@middle{%
  \ifnum\eql@numbering@target@=\z@
    \count@\eql@row@
    \advance\count@\@ne
    \divide\count@\tw@
    \global\eql@numbering@target@\count@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@eval@mode{%
  \let\eql@numbering@eval@target\@undefined
  \let\eql@numbering@subeq@use\eql@false
  \csname eql@numbering@mode@\eql@numbering@mode\endcsname
  \ifdefined\eql@numbering@active
    \let\eql@numbering@eqnswinit\@eqnswtrue
  \else
    \let\eql@numbering@eqnswinit\@eqnswfalse
  \fi
  \let\eql@numbering@active\eql@false
}
%    \end{macrocode}
%
% \TODO reconsider operation
%   \imacro{\numberhere}
%    \begin{macrocode}
\def\numberhere{%
  \ifmeasuring@
    \ifnum\eql@numbering@target@<\z@\else
      \global\eql@numbering@target@\eql@row@
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%   \imacro{\numbernext}
%    \begin{macrocode}
\def\numbernext{%
  \ifmeasuring@
    \ifnum\eql@numbering@target@<\z@\else
      \ifnum\eql@numbering@target@=\eql@row@
        \global\advance\eql@numbering@target@\@ne
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Numbering Framework}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@numbering@autolabel\eql@false
\let\eql@numbering@autotag\eql@true
\let\eql@numbering@blocklabel\@undefined
\let\eql@numbering@blocktag\@undefined
%    \end{macrocode}
%
% \TODO where does this belong?
%    \begin{macrocode}
\eql@amsmath@after{
  \let\eql@print@eqnum@default\print@eqnum
  \let\eql@incr@eqnum@default\incr@eqnum
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\donumber{%
  \if@eqnsw\else
    \global\@eqnswtrue
    \ifx\print@eqn\@empty
      \global\let\print@eqn\eql@print@eqnum@default
    \fi
    \ifx\incr@eqn\@empty
      \global\let\incr@eqn\eql@incr@eqnum@default
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@label@warn{%
  \ifdefined\eql@numbering@autolabel
    \global\@eqnswtrue
  \fi
  \ifdefined\eql@nextlabel
    \eql@warn@label@multiple\eql@nextlabel
  \fi
  \global\edef\eql@nextlabel
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tag@warn{%
  \ifdefined\eql@numbering@autotag
    \global\@eqnswtrue
  \fi
  \ifdefined\eql@nexttag
    \eql@warn@tag@multiple
  \fi
  \eql@tag@makenext
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@label@nowarn{%
  \ifdefined\eql@numbering@autolabel
    \global\@eqnswtrue
  \fi
  \global\edef\eql@nextlabel
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tag@nowarn{%
  \ifdefined\eql@numbering@autotag
    \global\@eqnswtrue
  \fi
  \eql@tag@makenext
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@blocklabel@set#1{%
  \ifdefined\eql@blocklabel
    \eql@warn@label@multiple\eql@blocklabel
  \fi
  \edef\eql@blocklabel{#1}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@blocktag@set#1{%
  \ifdefined\eql@blocktag
    \eql@warn@tag@multiple
  \fi
  \def\eql@blocktag{{#1}}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@blocktag@setstar#1{%
  \ifdefined\eql@blocktag
    \eql@warn@tag@multiple
  \fi
  \def\eql@blocktag{*{#1}}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Single-Line}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@single@init{%
  \let\label\eql@label@warn
  \let\tag\eql@tag@warn
  \let\raisetag\eql@raisetag
  \eql@numbering@target@\m@ne
  \let\eql@nextlabel\eql@blocklabel
  \ifdefined\eql@blocktag
    \expandafter\eql@tag@makenext\eql@blocktag
  \else
    \let\eql@nexttag\@undefined
  \fi
  \eql@numbering@eqnswinit
  \ifdefined\eql@numbering@autolabel
    \ifdefined\eql@nextlabel
      \@eqnswtrue
    \fi
  \fi
  \ifdefined\eql@numbering@autotag
    \ifdefined\eql@nexttag
      \@eqnswtrue
    \fi
  \fi
  \global\eql@raisetag@amount@\z@
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Multi-Line Measuring Pass}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@measure@init{%
  \let\label\eql@label@warn
  \let\tag\eql@tag@warn
  \let\raisetag\eql@raisetag
  \global\let\eql@nextlabel\eql@blocklabel
  \ifdefined\eql@blocktag
    \expandafter\eql@tag@makenext\eql@blocktag
  \else
    \global\let\eql@nexttag\@undefined
  \fi
  \ifnum\eql@numbering@target@<\z@\else
    \eql@numbering@eqnswinit
    \ifdefined\eql@numbering@autolabel
      \ifdefined\eql@nextlabel
        \@eqnswtrue
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@measure@line@begin{%
  \ifnum\eql@numbering@target@<\z@
    \global\eql@numbering@eqnswinit
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@measure@eval{%
  \ifdefined\eql@numbering@eval@target
    \eql@numbering@eval@target
  \fi
  \ifnum\eql@numbering@target@>\eql@row@
    \global\eql@numbering@target@\eql@row@
  \fi
  \ifnum\eql@numbering@target@>\z@
    \if@eqnsw\else
      \global\eql@numbering@target@\z@
    \fi
  \fi
  \ifnum\eql@numbering@target@<\@ne
    \ifdefined\eql@nextlabel
      \eql@warn@label@unused
      \global\let\eql@nextlabel\@undefined
    \fi
    \ifdefined\eql@nexttag
      \eql@warn@tag@unused
      \global\let\eql@nexttag\@undefined
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Multi-Line Print Pass}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@print@init{%
  \ifnum\eql@numbering@target@<\z@
    \let\label\eql@label@nowarn
    \let\tag\eql@tag@nowarn
    \let\raisetag\eql@raisetag
    \let\eql@nextlabel\eql@blocklabel
    \ifdefined\eql@blocktag
      \expandafter\eql@tag@makenext\eql@blocktag
    \else
      \let\eql@nexttag\@undefined
    \fi
  \else
    \let\label\@gobble
    \let\tag\eql@tag@gobble
    \let\raisetag\eql@gobble
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@print@block@begin{%
  \ifnum\eql@numbering@target@>\z@
    \eql@numbering@makeblockanchor
  \fi
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@printsubeqlabel
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@print@line@begin{%
  \ifnum\eql@numbering@target@<\z@
    \global\eql@numbering@eqnswinit
    \global\eql@raisetag@amount@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@print@line@eval{%
  \ifnum\eql@numbering@target@<\z@\else
    \ifnum\eql@numbering@target@=\eql@row@
      \global\@eqnswtrue
    \else
      \global\@eqnswfalse
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Subequations}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@subeq@init{%
  \let\eql@save@theequation\theequation
  \let\eql@save@theHequation\theHequation
  \eql@subequations@init
  \let\eql@parentlabel\eql@blocklabel
  \let\eql@parenttag\eql@blocktag
  \let\eql@blocklabel\@undefined
  \let\eql@blocktag\@undefined
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@subeq@test{%
  \ifnum\c@equation<\tw@
    \let\eql@numbering@subeq@use\@ne
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@subeq@revert{%
  \let\eql@blocklabel\eql@parentlabel
  \let\eql@blocktag\eql@parenttag
  \let\eql@numbering@subeq@use\eql@false
  \let\theequation\eql@save@theequation
  \let\theHequation\eql@save@theHequation
  \eql@subequations@restorecounter
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
% \TODO note must not use setcounter here (when calc is loaded)
\def\eql@numbering@subeq@close{%
  \eql@subequations@close
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Display Equations Support}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Display Breaks}
%
% \TODO describe
%
%   \macro{\interdisplaylinepenalty}
%    \begin{macrocode}
\interdisplaylinepenalty\@M
%    \end{macrocode}
%
%   \macro{\eql@getdsp@pen}
%    \TODO isn't this the opposite order than |\@getpen|?!
%    \begin{macrocode}
\def\eql@getdsp@pen#1{%
  \ifcase #1\@M \or 9999 \or 6999 \or 2999 \or \z@\fi
}
%    \end{macrocode}
%
% \TODO allow a displaybreak before equations
%    \begin{macrocode}
\DeclareRobustCommand{\eql@displaybreak@default}[1][4]{%
  \eql@warning{Invalid use of \string\displaybreak}{}}
\eql@amsmath@futurebefore{\let\displaybreak\@undefined}
\eql@amsmath@after{\let\eql@displaybreak@default\displaybreak}
\let\displaybreak\eql@displaybreak@default
%    \end{macrocode}
%
%    \begin{macrocode}
\newcount\eql@displaybreak@pen@
\newcount\eql@displaybreak@prepen@
%    \end{macrocode}
%
%    \begin{macrocode}
\protected\def\eql@displaybreak@print{%
  \eql@ampprotect\eql@testopt@tight\eql@displaybreak@print@{4}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@displaybreak@print@[#1]{%
  \ifnum#1<\z@
    \global\eql@displaybreak@pen@\@MM
  \else
    \global\eql@displaybreak@pen@-\@getpen{#1}\relax
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@displaybreak@pre#1{%
  \ifnum#1<\z@
    \global\eql@displaybreak@prepen@\@MM
  \else
    \global\eql@displaybreak@prepen@-\@getpen{#1}\relax
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\protected\def\eql@displaybreak@measure{%
  \eql@ampprotect\eql@testopt@tight\eql@displaybreak@measure@{4}%
}
\def\eql@displaybreak@measure@[#1]{}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{General Initialisation}
%
% \TODO describe
%
%   \macro{\eql@display@atend}
%    \begin{macrocode}
\def\eql@display@atend#1{%
  \expandafter\def\expandafter\eql@display@doatend\expandafter
    {\eql@display@doatend#1}%
}
%    \end{macrocode}
%
%   \lskip{\eql@vspaceskip@}
%   \lskip{\eql@abovespace@}
%   \lskip{\eql@belowspace@}
% \TODO add a proper star variant?!
%    \begin{macrocode}
\newskip\eql@vspaceskip@
\newskip\eql@abovespace@
\newskip\eql@belowspace@
\let\eql@vspace@org\vspace
\def\eql@vspace{\eql@ifstar@loose\eql@vspace@\eql@vspace@}
\def\eql@vspace@#1{%
  \setlength\skip@{#1}%
  \global\advance\eql@vspaceskip@\skip@
}
%    \end{macrocode}
%
%   \macro{\eql@display@init}
%    \begin{macrocode}
\def\eql@display@init{%
  \eql@display@firstavail@\z@
  \eql@raisetag@firstlast@\z@
  \let\displaybreak\eql@displaybreak@print
  \eql@displaybreak@pen@\@MM
  \eql@vspaceskip@\z@skip
  \let\eql@vspace@org\vspace
  \let\vspace\eql@vspace
}
%    \end{macrocode}
%
%   \macro{\eql@display@close}
% \TODO there seems to be an offset of 1em in predisplaysize
%   towards actual content, nice.
% \TODO must not use setlength or setcounter when calc is loaded
%    \begin{macrocode}
\def\eql@display@close{%
  \ifdim\eql@halign@prevdepth@=\maxdimen
    \ifdim\predisplaysize=-\maxdimen
%  \TODO hbox was clear (noindent)
      \abovedisplayskip\eql@abovedisplaycontskip@
% \TODO whether to enable or disable short
      \predisplaysize\maxdimen
      \abovedisplayshortskip\abovedisplayskip
      \belowdisplayshortskip\belowdisplayskip
    \fi
  \else
%  \TODO should tagskip be allowed to override these?! rather not
    \ifdim\eql@halign@prevdepth@=\@m\p@
      \predisplaypenalty\z@
      \abovedisplayskip\eql@abovedisplaytopskip@
% \TODO whether to offer this?
      \belowdisplayskip\eql@belowdisplaytopskip@
    \else
      \predisplaypenalty\z@
      \abovedisplayskip\eql@abovedisplayparskip@
    \fi
% \TODO whether to enable or disable short
    \predisplaysize\maxdimen
    \abovedisplayshortskip\abovedisplayskip
    \belowdisplayshortskip\belowdisplayskip
  \fi
  \eql@display@doatend
  \ifdim\eql@display@firstavail@<\z@
    \eql@display@firstavail@\z@
  \fi
  \advance\eql@display@firstavail@\displayindent
  \ifdim\eql@display@firstavail@>\predisplaysize
    \ifcase\eql@displayshortmode@
    \or
      \abovedisplayskip\abovedisplayshortskip
    \or
      \abovedisplayskip\abovedisplayshortskip
      \ifnum\eql@row@=\tw@
        \belowdisplayskip\belowdisplayshortskip
      \fi
    \or
      \abovedisplayskip\abovedisplayshortskip
      \belowdisplayskip\belowdisplayshortskip
    \fi
  \fi
  \ifodd\eql@raisetag@firstlast@
    \abovedisplayskip\eql@abovedisplaytagskip@
  \fi
  \ifnum\eql@raisetag@firstlast@>\@ne
    \belowdisplayskip\eql@belowdisplaytagskip@
  \fi
  \ifnum\eql@displaybreak@pen@=\@MM\else
    \postdisplaypenalty\eql@displaybreak@pen@
  \fi
  \ifnum\eql@displaybreak@prepen@=\@MM\else
    \predisplaypenalty\eql@displaybreak@prepen@
  \fi
% \TODO here or above?
  \advance\abovedisplayskip\eql@abovespace@
  \advance\belowdisplayskip\eql@belowspace@
  \advance\belowdisplayskip\eql@vspaceskip@
  \count@\prevgraf
  \advance\count@\eql@row@
  \advance\count@-\tw@
  \prevgraf\count@
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@display@leave{%
  \let\label\eql@label@org
  \let\tag\eql@tag@default
  \let\raisetag\eql@raisetag@default
  \let\displaybreak\eql@displaybreak@default
  \let\vspace\eql@vspace@org
}
\expandafter\def\expandafter\@arrayparboxrestore\expandafter{%
  \@arrayparboxrestore
  \eql@display@leave
% \TODO should we always revert to originals? or only if switch is set
  \eql@amprevert
  \@displayfalse
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{halign Support}
%
% \TODO describe
%
%   \macro{\eql@strut}
%   \macro{\eql@strutbox@}
% Next follows a special internal strut which is supposed to match
% the height and the depth of a normal |\strut| minus
% |\normallineskiplimit| according to M.\ Spivak.
%    \begin{macrocode}
\newbox\eql@strutbox@
\def\eql@strut{\copy\eql@strutbox@}
\let\eql@strut@field\eql@strut
\let\eql@strut@tag\eql@strut
\def\eql@strut@make{%
  \setbox\eql@strutbox@\hbox{%
    \@tempdima\normalbaselineskip
    \advance\@tempdima-\normallineskiplimit
    \@tempdimb.3\normalbaselineskip
    \advance\@tempdimb.5\normallineskiplimit
    \advance\@tempdima-\@tempdimb
    \vrule\@height\@tempdima\@depth\@tempdimb\@width\z@
  }
}
\AtBeginDocument{\eql@strut@make}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@halign@spread{%
  \dimen@\eql@spread\relax
  \advance\dimen@\normalbaselineskip
  \ifdim\dimen@>\baselineskip
    \normalbaselines
    \dimen@\eql@spread\relax
    \advance\dimen@\normalbaselineskip
    \advance\dimen@-\baselineskip
    \openup\dimen@
    \ifdefined\spread@equation
      \let\spread@equation\@empty
    \fi
  \fi
}
%    \end{macrocode}
%
%   \ldimen{\eql@halign@prevdepth@}
%    \begin{macrocode}
\newdimen\eql@halign@prevdepth@
\def\eql@halign@catchprevdepth{%
  \ifvmode
    \eql@halign@prevdepth@\prevdepth
    \nointerlineskip
    \noindent
  \else
    \eql@halign@prevdepth@\maxdimen
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@halign@before{%
  \ifdim\eql@halign@prevdepth@=\maxdimen\else
    \prevdepth\eql@halign@prevdepth@
  \fi
  \ifdim\prevdepth=-\@m\p@\else
    \skip@\normalbaselineskip
    \advance\skip@-\eql@display@height\relax
    \advance\skip@-\prevdepth\relax
    \ifdim\skip@<\normallineskiplimit
      \vskip\normallineskip
    \else
      \vskip\skip@
    \fi
    \nointerlineskip
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@halign@after{%
  \prevdepth\eql@display@depth\relax
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@halign@init#1{%
  \eql@halign@spread
  \eql@strut@make
  \everycr{\noalign{#1}}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Stack}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@stack@enable{%
  \let\eql@stack@save@single\eql@stack@save@single@
  \let\eql@stack@save@multi\eql@stack@save@multi@
  \let\eql@stack@save@boxed\eql@stack@save@boxed@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@stack@save@single\eql@stack@enable
\let\eql@stack@save@multi\eql@stack@enable
\let\eql@stack@save@boxed\eql@stack@enable
\let\eql@stack@restore\@empty
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@stack@save@reg#1{\global#1\the#1\relax}
\def\eql@stack@save@let#1#2{\global\let\noexpand#2\noexpand#1}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@stack@save@single@{%
  \let\eql@stack@nextlabel\eql@nextlabel
  \let\eql@stack@nexttag\eql@nexttag
  \edef\eql@stack@restore{%
    \global\if@eqnsw\noexpand\@eqnswtrue\else\noexpand\@eqnswfalse\fi
    \eql@stack@save@let\eql@stack@nextlabel\eql@nextlabel
    \eql@stack@save@let\eql@stack@nexttag\eql@nexttag
    \eql@stack@save@reg\eql@displaybreak@pen@
    \eql@stack@save@reg\eql@vspaceskip@
    \eql@stack@save@reg\eql@shape@pos@
    \eql@stack@save@reg\eql@shape@amount@
    \eql@stack@save@reg\eql@display@firstavail@
    \eql@stack@save@reg\eql@raisetag@amount@
    \eql@stack@save@reg\eql@raisetag@firstlast@
  }%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@stack@save@multi@{%
  \let\eql@stack@nextlabel\eql@nextlabel
  \let\eql@stack@nexttag\eql@nexttag
  \let\eql@stack@tagwidth@tab\eql@tagwidth@tab
  \let\eql@stack@fieldlength@tab\eql@fieldlength@tab
  \let\eql@stack@colwidth@tab\eql@colwidth@tab
  \let\eql@stack@label@thepage\eql@label@thepage
  \let\eql@stack@label@currentHref\eql@label@currentHref
  \edef\eql@stack@restore{%
    \global\if@eqnsw\noexpand\@eqnswtrue\else\noexpand\@eqnswfalse\fi
    \eql@stack@save@let\eql@stack@nextlabel\eql@nextlabel
    \eql@stack@save@let\eql@stack@nexttag\eql@nexttag
    \eql@stack@save@let\eql@stack@tagwidth@tab\eql@tagwidth@tab
    \eql@stack@save@let\eql@stack@fieldlength@tab\eql@fieldlength@tab
    \eql@stack@save@let\eql@stack@colwidth@tab\eql@colwidth@tab
    \eql@stack@save@let\eql@stack@label@thepage\eql@label@thepage
    \eql@stack@save@let\eql@stack@label@currentHref\eql@label@currentHref
    \eql@stack@save@reg\eql@displaybreak@pen@
    \eql@stack@save@reg\eql@vspaceskip@
    \eql@stack@save@reg\eql@shape@pos@
    \eql@stack@save@reg\eql@shape@amount@
    \eql@stack@save@reg\eql@display@firstavail@
    \eql@stack@save@reg\eql@raisetag@amount@
    \eql@stack@save@reg\eql@raisetag@firstlast@
    \eql@stack@save@reg\eql@column@
    \eql@stack@save@reg\eql@totalcolumns@
    \eql@stack@save@reg\eql@line@avail@
    \eql@stack@save@reg\eql@line@pos@
    \eql@stack@save@reg\eql@line@width@
    \eql@stack@save@reg\eql@line@depth@
    \eql@stack@save@reg\eql@line@height@
    \eql@stack@save@reg\eql@numbering@target@
    \eql@stack@save@reg\eql@row@
  }%
}
\def\eql@stack@save@boxed@{%
  \edef\eql@stack@restore{%
    \eql@stack@save@reg\eql@row@
    \eql@stack@save@reg\eql@totalrows@
    \eql@stack@save@reg\eql@shape@pos@
    \eql@stack@save@reg\eql@shape@amount@
  }%
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Horizontal Spacing for Lines}
%
% The following code adjusts individual lines of equations
% for the equation and lines mode
% according to the selected layout and shape.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Supporting Definitionss}
%
%   \macro{\inf@bad}
% The |\inf@bad| constant is for testing overfull boxes:
%    \begin{macrocode}
\ifdefined\inf@bad\else%
  \newcount\inf@bad
  \inf@bad1000000\relax
\fi
%    \end{macrocode}
%
%   \macro{\eql@restore@hfuzz}
%   \macro{\eql@save@hfuzz}
% We need to change the value of |\hfuzz| temporarily.
% The method |\eql@save@hfuzz| stores the value
% for recovery through |\eql@restore@hfuzz|:
%    \begin{macrocode}
\let\eql@restore@hfuzz\@empty
\def\eql@save@hfuzz{\edef\eql@restore@hfuzz{\hfuzz\the\hfuzz\relax}}
%    \end{macrocode}
%
%   \ldimen{\eql@shape@pos@}
%   \ldimen{\eql@shape@amount@}
% The registers |\eql@shape@pos@| and |\eql@shape@amount@|
% specify the currently selected horizontal alignment
% (|0| for left, |1| for center, |2| for right)
% and the indentation amount, respectively:
%    \begin{macrocode}
\newcount\eql@shape@pos@
\newdimen\eql@shape@amount@
%    \end{macrocode}
%
%   \ldimen{\eql@marginleft@}
%   \ldimen{\eql@marginright@}
% The registers |\eql@marginleft@| and |\eql@marginright@|
% store the intended left and right margin for the equation lines:
%    \begin{macrocode}
\newdimen\eql@marginleft@
\newdimen\eql@marginright@
%    \end{macrocode}
%
%   \macro{\eql@marginbadness@}
%   \macro{\eql@maxbadness@}
% The registers |\eql@marginbadness@| and |\eql@maxbadness@|
% store the allowable badness threshold for shrinking equation lines
% to the intended margin or to fit into the line at all
% before the tag is raised or lowered:
%    \begin{macrocode}
\newcount\eql@marginbadness@
\newcount\eql@maxbadness@
\eql@marginbadness@\inf@bad
\eql@maxbadness@\inf@bad
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Shape Schemes}
%
% The horizontal alignment of each line is specified by
% a shape scheme.
%
%   \macro{\eql@shape@tab@...}
% We select the scheme through a |\csname| selector
% with the following names:
%    \begin{macrocode}
\def\eql@shape@tab@default{default}
\def\eql@shape@tab@left{left}
\def\eql@shape@tab@center{center}
\def\eql@shape@tab@right{right}
\def\eql@shape@tab@first{first}
\def\eql@shape@tab@hanging{hanging}
\def\eql@shape@tab@steps{steps}
%    \end{macrocode}
%
% For convenience, we add further alias names for the schemes:
%    \begin{macrocode}
\let\eql@shape@tab@def\eql@shape@tab@default
\let\eql@shape@tab@\eql@shape@tab@default
\let\eql@shape@tab@l\eql@shape@tab@left
\let\eql@shape@tab@c\eql@shape@tab@center
\let\eql@shape@tab@r\eql@shape@tab@right
\let\eql@shape@tab@rc\eql@shape@tab@first
\let\eql@shape@tab@indent\eql@shape@tab@first
\let\eql@shape@tab@hang\eql@shape@tab@hanging
\let\eql@shape@tab@lc\eql@shape@tab@hanging
\let\eql@shape@tab@outdent\eql@shape@tab@hanging
\let\eql@shape@tab@lcr\eql@shape@tab@steps
%    \end{macrocode}
%
%   \macro{\eql@shape@mode}
% The currently selected scheme is stored in |\eql@shape@mode|.
% It it set to |default|:
%    \begin{macrocode}
\let\eql@shape@mode\eql@shape@tab@default
%    \end{macrocode}
%
%   \macro{\eql@shape@set}
% Set the scheme via the translation table:
%    \begin{macrocode}
\def\eql@shape@set#1{%
  \ifcsname eql@shape@tab@#1\endcsname
    \expandafter\let\expandafter\eql@shape@mode
      \csname eql@shape@tab@#1\endcsname
  \else
    \eql@error{shape `#1' unknown: setting to default}%
    \let\eql@shape@mode\eql@shape@tab@default
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@shape@center@...}
%   \macro{\eql@shape@left@...}
% Define the uniform shape schemes |left|, |center|, |right| and |default|
% for the centered and flush-left layout.
% The scheme functions determine the desired alignment and indentation
% for the current row:
%    \begin{macrocode}
\def\eql@shape@center@left{\eql@shape@pos@\z@\eql@shape@amount@\z@}
\def\eql@shape@center@center{\eql@shape@pos@\@ne\eql@shape@amount@\z@}
\def\eql@shape@center@right{\eql@shape@pos@\tw@\eql@shape@amount@\z@}
\let\eql@shape@center@default\eql@shape@center@center
\def\eql@shape@left@left{\eql@shape@pos@\z@\eql@shape@amount@\z@}
\def\eql@shape@left@center{\eql@shape@pos@\@ne\eql@shape@amount@\z@}
\def\eql@shape@left@right{\eql@shape@pos@\tw@\eql@shape@amount@\z@}
\let\eql@shape@left@default\eql@shape@left@left
%    \end{macrocode}
%
% The |first| scheme implements left alignment with
% indentation for the first line (unless there is only one line):
%    \begin{macrocode}
\def\eql@shape@center@first{%
  \eql@shape@pos@\z@
  \eql@shape@amount@\z@
  \ifnum\eql@totalrows@>\@ne
    \ifnum\eql@row@=\@ne
      \eql@shape@amount@\eql@indent@
    \fi
  \fi
}
\def\eql@shape@left@first{%
  \eql@shape@pos@\z@
  \eql@shape@amount@\z@
  \ifnum\eql@totalrows@>\@ne
    \ifnum\eql@row@=\@ne
      \eql@shape@amount@\eql@indent@
    \fi
  \fi
}
%    \end{macrocode}
%
% 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:
%    \begin{macrocode}
\def\eql@shape@center@hanging{%
  \eql@shape@pos@\z@
  \eql@shape@amount@\eql@indent@
  \ifnum\eql@totalrows@>\@ne
    \ifnum\eql@row@=\@ne
      \eql@shape@amount@\z@
    \fi
  \fi
}
\def\eql@shape@left@hanging{%
  \eql@shape@pos@\z@
  \eql@shape@amount@\z@
  \ifnum\eql@totalrows@>\@ne
    \ifnum\eql@row@=\@ne
      \eql@shape@amount@-\eql@indent@
    \fi
  \fi
}
%    \end{macrocode}
%
% 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:
%    \begin{macrocode}
\def\eql@shape@center@steps{%
  \eql@shape@amount@\z@
  \eql@shape@pos@\@ne
  \ifnum\eql@totalrows@>\@ne
    \ifnum\eql@row@=\@ne
      \eql@shape@pos@\z@
    \fi
    \ifnum\eql@row@=\eql@totalrows@
      \eql@shape@pos@\tw@
    \fi
  \fi
}
\def\eql@shape@left@steps{%
  \eql@shape@pos@\z@
  \eql@shape@amount@\z@
  \ifnum\eql@totalrows@>\@ne
    \ifnum\eql@row@=\@ne
      \eql@shape@amount@-\eql@indent@
    \fi
    \ifnum\eql@row@=\eql@totalrows@
      \eql@shape@amount@\eql@indent@
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@shape@sel}
%   \macro{\eql@shape@eval}
% Select the shape selector function
% for the currrent scheme |@\eql@shape@mode| and layout
% and store it in |\eql@shape@eval|:
%    \begin{macrocode}
\let\eql@shape@eval\@undefined
\def\eql@shape@sel{%
  \expandafter\let\expandafter\eql@shape@eval
    \csname eql@shape%
    @\ifdefined\eql@flushleft left\else center\fi
    @\eql@shape@mode\endcsname
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@shoveleft}
%   \macro{\eql@adjust@shoveright}
%   \macro{\eql@adjust@shovecenter}
% Adjust the alignment of the current equation line.
% For left alignment an optional argument specifies the amount of indentation:
%    \begin{macrocode}
\def\eql@adjust@shoveleft{%
  \global\eql@shape@pos@\z@
  \eql@srbgroup\eql@ifstar@tight
    {\eql@adjust@shoveleft@[\eql@indent@]}%
    {\eql@ifnextgobble@tight{!}%
      {\eql@adjust@shoveleft@[-\eql@indent@]}%
      {\eql@testopt@tight\eql@adjust@shoveleft@\z@}%
    }%
}
\def\eql@adjust@shoveleft@[#1]{%
  \eql@sregroup\setlength\dimen@{#1}\global\eql@shape@amount@\dimen@}
\def\eql@adjust@shovecenter{%
  \global\eql@shape@pos@\@ne\global\eql@shape@amount@\z@}
\def\eql@adjust@shoveright{%
  \global\eql@shape@pos@\tw@\global\eql@shape@amount@\z@}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Adjustment Methods}
%
%   \macro{\eql@adjust@try}
% Try to fit the current equation line in the available space.
% Argument |#1| specifies the amount of reserved space.
% Unpack the box |\eql@fieldbox@|, replace the previous kerning
% with the new reserved space, and save the box back into |\eql@fieldbox@|:
%    \begin{macrocode}
\def\eql@adjust@try#1{%
  \setbox\eql@fieldbox@\hbox to\displaywidth{%
    \unhbox\eql@fieldbox@\unkern\kern#1}%
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@print}
% We have found the final adjustment of the current line,
% so we typeset it with initial and final space adjustments |#1| and |#2|,
% respectively. Restore the original value for |\hfuzz|:
%    \begin{macrocode}
\def\eql@adjust@print#1#2{%
  \eql@restore@hfuzz
  \hbox to\displaywidth{#1\unhbox\eql@fieldbox@\unkern#2}%
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@print@alignleft}
%   \macro{\eql@adjust@print@aligncenter}
%   \macro{\eql@adjust@print@alignright}
% Fit the current equation line with the selected alignment
% within a given left and right margins |#1| and |#2|.
% If we're on the first line,
% adjust |\eql@display@firstavail@|
% to the mininum left available space we can guarantee:
%    \begin{macrocode}
\def\eql@adjust@print@alignleft#1#2{%
  \ifnum\eql@row@=\@ne
    \global\eql@display@firstavail@#1%
  \fi
  \eql@adjust@print{\kern#1}{\kern#2}%
}
\def\eql@adjust@print@alignright#1#2{%
  \ifnum\eql@row@=\@ne
    \eql@display@firstavail@\displaywidth
    \advance\eql@display@firstavail@-\eql@fieldwidth@
    \global\advance\eql@display@firstavail@-#2%
  \fi
  \eql@adjust@print{\kern#1\hfil}{\unskip\kern#2}%
}
\def\eql@adjust@print@aligncenter#1#2{%
  \ifnum\eql@row@=\@ne
    \eql@display@firstavail@\displaywidth
    \advance\eql@display@firstavail@-\eql@fieldwidth@
    \advance\eql@display@firstavail@#1%
    \advance\eql@display@firstavail@-#2%
    \global\divide\eql@display@firstavail@\tw@
  \fi
  \eql@adjust@print{\kern#1\hfil}{\kern#2}%
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@init}
% Initialise the horizontal adjustment framework.
% Turn off overfull box messages temporarily -- otherwise there
% would be unwanted extra ones emitted during our measuring operations.
% Select the shape scheme:
%    \begin{macrocode}
\def\eql@adjust@init{%
  \eql@save@hfuzz
  \hfuzz\maxdimen
  \eql@shape@sel
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@sel@tag}
%   \macro{\eql@adjust@sel@notag}
% Select the appropriate adjustment method depending
% on the selected layout, selected tag placement,
% current alignment position and on whether a tag is present or not:
%    \begin{macrocode}
\def\eql@adjust@sel@tag{%
  \csname eql@adjust%
    @\ifdefined\eql@flushleft flushleft\else center\fi
    @\ifdefined\eql@tagsleft tagsleft\else tagsright\fi
    @\ifcase\eql@shape@pos@ shoveleft\or shovecenter\or shoveright\fi
    @tag\endcsname
}
\def\eql@adjust@sel@notag{%
  \csname eql@adjust%
    @\ifdefined\eql@flushleft flushleft\else center\fi
    @\ifdefined\eql@tagsleft tagsleft\else tagsright\fi
    @\ifcase\eql@shape@pos@ shoveleft\or shovecenter\or shoveright\fi
    @notag\endcsname
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Centered Layout}
%
% \TODO describe
%
% \TODO check all these!!
%    \begin{macrocode}
\def\eql@adjust@center@tagsright@shovecenter@notag{%
  \dimen@\displaywidth
  \advance\dimen@-\eql@fieldwidth@
  \ifdim\dimen@>\eql@tagmargin@
    \eql@adjust@print@aligncenter\z@\eql@tagmargin@
  \else
    \eql@adjust@print@alignleft\z@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsright@shovecenter@tag{%
  \dimen@\displaywidth
  \ifdim\eql@tagwidth@<\eql@tagmargin@
    \advance\dimen@-\eql@tagmargin@
  \else
    \advance\dimen@-2\eql@tagwidth@
    \advance\dimen@\eql@tagmargin@
  \fi
  \ifdim\eql@fieldwidth@<\dimen@
    \eql@adjust@print@aligncenter\z@\eql@tagmargin@
    \eql@tagbox@print@right
  \else
    \eql@adjust@try\eql@tagwidth@
    \ifnum\badness<\eql@maxbadness@
      \ifdim\eql@tagwidth@<\eql@tagmargin@
        \eql@adjust@print@alignleft\z@\eql@tagwidth@
      \else
        \eql@adjust@print@alignright\z@\eql@tagwidth@
      \fi
      \eql@tagbox@print@right
    \else
      \eql@adjust@center@tagsright@shovecenter@notag
      \eql@tagbox@print@right@raise
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsleft@shovecenter@notag{%
  \dimen@\displaywidth
  \advance\dimen@-\eql@tagmargin@
  \ifdim\eql@fieldwidth@<\dimen@
    \eql@adjust@print@aligncenter\eql@tagmargin@\z@
  \else
    \eql@adjust@print@alignright\z@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsleft@shovecenter@tag{%
  \dimen@\displaywidth
  \ifdim\eql@tagwidth@<\eql@tagmargin@
    \advance\dimen@-\eql@tagmargin@
  \else
    \advance\dimen@-2\eql@tagwidth@
    \advance\dimen@\eql@tagmargin@
  \fi
  \ifdim\eql@fieldwidth@<\dimen@
    \eql@tagbox@print@left
    \eql@adjust@print@aligncenter\eql@tagmargin@\z@
  \else
    \eql@adjust@try\eql@tagwidth@
    \ifnum\badness<\eql@maxbadness@
      \eql@tagbox@print@left
      \ifdim\eql@tagwidth@<\eql@tagmargin@
        \eql@adjust@print@alignright\eql@tagwidth@\z@
      \else
        \eql@adjust@print@alignleft\eql@tagwidth@\z@
      \fi
    \else
      \eql@tagbox@print@left@raise
      \eql@adjust@center@tagsleft@shovecenter@notag
    \fi
  \fi
  \eql@display@firstavail@set\z@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsright@shoveleft@notag{%
  \dimen@\displaywidth
  \advance\dimen@-\eql@marginleft@
  \advance\dimen@-\eql@shape@amount@
  \ifdim\eql@fieldwidth@<\dimen@
    \dimen@\eql@marginleft@
    \advance\dimen@\eql@shape@amount@
    \eql@adjust@print@alignleft\dimen@\z@
  \else
    \eql@adjust@print@alignright\z@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsright@shoveleft@tag{%
  \dimen@\eql@marginleft@
  \advance\dimen@\eql@shape@amount@
  \advance\dimen@\eql@tagwidth@
  \eql@adjust@try\dimen@
  \ifnum\badness<\eql@marginbadness@
    \dimen@\eql@marginleft@
    \advance\dimen@\eql@shape@amount@
    \eql@adjust@print@alignleft\dimen@\eql@tagwidth@
    \eql@tagbox@print@right
  \else
    \ifdim\eql@marginleft@>-\eql@shape@amount@
      \eql@adjust@try\eql@tagwidth@
    \fi
    \ifnum\badness<\eql@maxbadness@
      \eql@adjust@print@alignright\z@\eql@tagwidth@
      \eql@tagbox@print@right
    \else
      \eql@adjust@center@tagsright@shoveleft@notag
      \eql@tagbox@print@right@raise
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsleft@shoveright@notag{%
  \dimen@\displaywidth
  \advance\dimen@-\eql@tagmargin@
  \advance\dimen@-\eql@marginright@
  \ifdim\eql@fieldwidth@<\dimen@
    \eql@adjust@print@alignright\z@\eql@marginright@
  \else
    \eql@adjust@print@alignleft\z@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsleft@shoveright@tag{%
  \dimen@\eql@marginright@
  \advance\dimen@\eql@tagwidth@
  \eql@adjust@try\dimen@
  \ifnum\badness<\eql@marginbadness@
    \eql@tagbox@print@left
    \eql@adjust@print@alignright\eql@tagwidth@\eql@marginright@
  \else
    \ifdim\eql@marginright@>\z@
      \eql@adjust@try\eql@tagwidth@
    \fi
    \ifnum\badness<\eql@maxbadness@
      \eql@tagbox@print@left
      \eql@adjust@print@alignleft\eql@tagwidth@\z@
    \else
      \eql@tagbox@print@left@raise
      \eql@adjust@center@tagsleft@shoveright@notag
    \fi
  \fi
  \eql@display@firstavail@set\z@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsright@shoveright@notag{%
  \dimen@\displaywidth
  \advance\dimen@-\eql@tagmargin@
  \advance\dimen@-\eql@marginright@
  \ifdim\eql@fieldwidth@<\dimen@
    \dimen@\eql@tagmargin@
    \advance\dimen@\eql@marginright@
    \eql@adjust@print@alignright\z@\dimen@
  \else
    \eql@adjust@print@alignleft\z@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsright@shoveright@tag{%
  \dimen@\eql@tagmargin@
  \advance\dimen@\eql@marginright@
  \ifdim\eql@tagwidth@<\dimen@
    \eql@adjust@try\dimen@%
    \ifnum\badness<\eql@marginbadness@
      \eql@adjust@print@alignright\z@\dimen@
      \eql@tagbox@print@right
    \else
      \eql@adjust@try\eql@tagwidth@
      \ifnum\badness<\eql@maxbadness@
        \eql@adjust@print@alignleft\z@\eql@tagwidth@
        \eql@tagbox@print@right
      \else
        \eql@adjust@print@alignleft\z@\z@
        \eql@tagbox@print@left@raise
      \fi
    \fi
  \else
    \eql@adjust@try\eql@tagwidth@
    \ifnum\badness<\eql@maxbadness@
      \eql@adjust@print@alignright\z@\eql@tagwidth@
      \eql@tagbox@print@right
    \else
      \eql@adjust@center@tagsright@shoveright@notag
      \eql@tagbox@print@right@raise
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsleft@shoveleft@notag{%
  \dimen@\displaywidth
  \advance\dimen@-\eql@tagmargin@
  \advance\dimen@-\eql@marginleft@
  \advance\dimen@-\eql@shape@amount@
  \ifdim\eql@fieldwidth@<\dimen@
    \dimen@\eql@tagmargin@
    \advance\dimen@\eql@marginleft@
    \advance\dimen@\eql@shape@amount@
    \eql@adjust@print@alignleft\dimen@\z@
  \else
    \eql@adjust@print@alignright\z@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@center@tagsleft@shoveleft@tag{%
  \dimen@\eql@tagmargin@
  \advance\dimen@\eql@marginleft@
  \advance\dimen@\eql@shape@amount@
  \ifdim\eql@tagwidth@<\dimen@
    \eql@adjust@try\dimen@%
    \ifnum\badness<\eql@marginbadness@
      \eql@tagbox@print@left
      \eql@adjust@print@alignleft\dimen@\z@
    \else
      \eql@adjust@try\eql@tagwidth@
      \ifnum\badness<\eql@maxbadness@
        \eql@tagbox@print@left
        \eql@adjust@print@alignright\eql@tagwidth@\z@
      \else
        \eql@tagbox@print@left@raise
        \eql@adjust@print@alignright\z@\z@
      \fi
    \fi
  \else
    \eql@adjust@try\eql@tagwidth@
    \ifnum\badness<\eql@maxbadness@
      \eql@tagbox@print@left
      \eql@adjust@print@alignleft\eql@tagwidth@\z@
    \else
      \eql@tagbox@print@left@raise
      \eql@adjust@center@tagsleft@shoveleft@notag
    \fi
  \fi
  \eql@display@firstavail@set\z@
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Flush-Left Layout}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@adjust@flushleft@shoveleft{%
  \eql@marginleft@\eql@flushleftmargin@
  \advance\eql@marginleft@\eql@shape@amount@
  \ifdim\eql@marginleft@<\eql@flushleftmarginmin@
    \eql@marginleft@\eql@flushleftmarginmin@
  \fi
  \ifdim\eql@marginleft@>\eql@flushleftmarginmax@
    \eql@marginleft@\eql@flushleftmarginmax@
  \fi
}
%    \end{macrocode}
%
%   \TODO perform checks based on unstretched dimension?!
%    \TODO mention alternatives to fill; emphasis is on
%       good left margin with ragged right
%          (allow space between tag and equation in close case)
%    \begin{macrocode}
\def\eql@adjust@flushleft@shoveleft@notag{%
  \ifdim\eql@flushleftmarginmin@<\eql@marginleft@
    \eql@adjust@try\eql@marginleft@
    \ifnum\badness<\eql@marginbadness@
      \eql@adjust@print@alignleft\eql@marginleft@\z@
    \else
      \eql@adjust@print@alignleft\eql@flushleftmarginmin@\z@
    \fi
  \else
    \eql@adjust@print@alignleft\eql@marginleft@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@flushleft@tagsright@shoveleft@notag{%
  \eql@adjust@flushleft@shoveleft
  \eql@adjust@flushleft@shoveleft@notag
}
\let\eql@adjust@flushleft@tagsleft@shoveleft@notag
  \eql@adjust@flushleft@tagsright@shoveleft@notag
%    \end{macrocode}
%
%   \TODO what is worse, extend into margin or raise tag?
%     this assumes raise tag, but other option might be better
%    \TODO mention alternatives to fill; emphasis is on good left
%      margin with ragged right
%          (allow space between tag and equation in close case)
%    \begin{macrocode}
\def\eql@adjust@flushleft@tagsright@shoveleft@tag{%
  \eql@adjust@flushleft@shoveleft
  \dimen@\eql@marginleft@
  \advance\dimen@\eql@tagwidth@
  \eql@adjust@try\dimen@
  \ifnum\badness<\eql@marginbadness@
    \eql@adjust@print@alignleft\eql@marginleft@\eql@tagwidth@
    \eql@tagbox@print@right
  \else
    \ifdim\eql@flushleftmarginmin@<\eql@marginleft@
      \dimen@\eql@flushleftmarginmin@
      \advance\dimen@\eql@tagwidth@
      \eql@adjust@try\dimen@
    \fi
    \ifnum\badness<\eql@maxbadness@
      \eql@adjust@print@alignleft\eql@flushleftmarginmin@\eql@tagwidth@
      \eql@tagbox@print@right
    \else
      \eql@adjust@flushleft@shoveleft@notag
      \eql@tagbox@print@right@raise
    \fi
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@adjust@flushleft@tagsleft@shoveleft@tag{%
  \eql@adjust@flushleft@shoveleft
  \ifdim\eql@tagwidth@<\eql@flushleftmarginmin@
    \eql@tagbox@print@left
    \eql@adjust@flushleft@notag
  \else
    \ifdim\eql@tagwidth@<\eql@marginleft@
      \eql@adjust@try\eql@marginleft@
      \ifnum\badness<\eql@marginbadness@
        \eql@tagbox@print@left
        \eql@adjust@print@alignleft\eql@marginleft@\z@
      \else
        \eql@adjust@try\eql@tagwidth@
        \ifnum\badness<\eql@maxbadness@
          \eql@tagbox@print@left
          \eql@adjust@print@alignleft\eql@tagwidth@\z@
        \else
          \eql@tagbox@print@left@raise
          \eql@adjust@print@alignleft\eql@flushleftmarginmin@\z@
        \fi
      \fi
    \else
      \ifdim\eql@tagwidth@>\eql@flushleftmarginmax@
        \eql@tagbox@print@left@raise
        \eql@adjust@flushleft@shoveleft@notag
      \else
        \eql@adjust@try\eql@tagwidth@
        \ifnum\badness<\eql@maxbadness@
          \eql@tagbox@print@left
          \eql@adjust@print@alignleft\eql@tagwidth@\z@
        \else
          \eql@tagbox@print@left@raise
          \eql@adjust@flushleft@shoveleft@notag
        \fi
      \fi
    \fi
  \fi
  \eql@display@firstavail@set\z@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@flushleft@shoveright@notag{%
  \eql@marginleft@\eql@flushleftmargin@
  \ifdim\eql@flushleftmarginmin@<\eql@marginleft@
    \eql@adjust@try\eql@marginleft@
    \ifnum\badness<\eql@marginbadness@
      \eql@adjust@print@alignright\eql@marginleft@\z@
    \else
      \eql@adjust@print@alignright\eql@flushleftmarginmin@\z@
    \fi
  \else
    \eql@adjust@print@alignright\eql@marginleft@\z@
  \fi
}
\let\eql@adjust@flushleft@tagsright@shoveright@notag
  \eql@adjust@flushleft@shoveright@notag
\let\eql@adjust@flushleft@tagsleft@shoveright@notag
  \eql@adjust@flushleft@shoveright@notag
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@flushleft@tagsright@shoveright@tag{%
  \dimen@\eql@marginleft@
  \advance\dimen@\eql@tagwidth@
  \eql@adjust@try\dimen@
  \ifnum\badness<\eql@marginbadness@
    \eql@adjust@print@alignright\eql@marginleft@\eql@tagwidth@
    \eql@tagbox@print@right
  \else
    \ifdim\eql@flushleftmarginmin@<\eql@marginleft@
      \dimen@\eql@flushleftmarginmin@
      \advance\dimen@\eql@tagwidth@
      \eql@adjust@try\dimen@
    \fi
    \ifnum\badness<\eql@maxbadness@
      \eql@adjust@print@alignright\eql@flushleftmarginmin@\eql@tagwidth@
      \eql@tagbox@print@right
    \else
      \eql@adjust@flushleft@shoveright@notag
      \eql@tagbox@print@right@raise
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@adjust@flushleft@tagsleft@shoveright@tag{%
  \ifdim\eql@tagwidth@<\eql@flushleftmarginmin@
    \eql@tagbox@print@left
    \eql@adjust@flushleft@shoveright@notag
  \else
    \ifdim\eql@tagwidth@<\eql@marginleft@
      \eql@adjust@try\eql@marginleft@
      \ifnum\badness<\eql@marginbadness@
        \eql@tagbox@print@left
        \eql@adjust@print@alignright\eql@marginleft@\z@
      \else
        \eql@adjust@try\eql@tagwidth@
        \ifnum\badness<\eql@maxbadness@
          \eql@tagbox@print@left
          \eql@adjust@print@alignright\eql@tagwidth@\z@
        \else
          \eql@tagbox@print@left@raise
          \eql@adjust@print@alignright\eql@flushleftmarginmin@\z@
        \fi
      \fi
    \else
      \ifdim\eql@tagwidth@>\eql@flushleftmarginmax@
        \eql@tagbox@print@left@raise
        \eql@adjust@flushleft@shoveright@notag
      \else
        \eql@adjust@try\eql@tagwidth@
        \ifnum\badness<\eql@maxbadness@
          \eql@tagbox@print@left
          \eql@adjust@print@alignright\eql@tagwidth@\z@
        \else
          \eql@tagbox@print@left@raise
          \eql@adjust@flushleft@shoveright@notag
        \fi
      \fi
    \fi
  \fi
  \eql@display@firstavail@set\z@
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@adjust@flushleft@shovecenter{%
  \eql@error{shove center not implemented for left alignment}%
}
\let\eql@adjust@flushleft@tagsright@shovecenter@notag
  \eql@adjust@flushleft@shovecenter
\let\eql@adjust@flushleft@tagsright@shovecenter@tag
  \eql@adjust@flushleft@shovecenter
\let\eql@adjust@flushleft@tagsleft@shovecenter@notag
  \eql@adjust@flushleft@shovecenter
\let\eql@adjust@flushleft@tagsleft@shovecenter@tag
  \eql@adjust@flushleft@shovecenter
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Single-Line Equation}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Environment}
%
%    \begin{macrocode}
\def\eql@single@cr{%
  \eql@error{Cannot use `\string\\' within display equation.
    Please switch to equations environment}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@single@start{%
  \eql@numbering@eval@mode
  \let\eql@numbering@subeq@use\eql@false
  \eql@stack@save@single
%    \end{macrocode}
%
%    \TODO make other display environments push these!?
%    \begin{macrocode}
  \eql@numbering@single@init
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifdefined\eql@single@native
    \let\eql@single@start@sel\eql@single@start@native
    \let\eql@single@end@sel\eql@single@end@native
    \let\raisetag\eql@raisetag@default
  \else
    \let\eql@single@start@sel\eql@single@start@adjust
    \let\eql@single@end@sel\eql@single@end@adjust
  \fi
  \ifdefined\eql@single@crerror\else
    \let\\\eql@single@cr
  \fi
  \eql@single@start@sel
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@single@end{%
  \eql@punct@apply@block
  \eql@hook@eqout
  \eql@single@end@sel
  \eql@stack@restore
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Native}
%
%    \begin{macrocode}
\def\eql@single@start@native{%
%  \mathopen{}%
  \eql@hook@eqin
}%
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@single@end@native{%
%  \mathclose{}%
  \if@eqnsw
    \ifdefined\eql@tagsleft
      \leqno
    \else
      \eqno
    \fi
    \eql@compose@print
  \fi
  \ifnum\eql@displaybreak@pen@=\@MM\else
    \postdisplaypenalty\eql@displaybreak@pen@
  \fi
}%
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Adjustment}
%
%    \begin{macrocode}
\def\eql@single@start@adjust{%
  \eql@totalrows@\@ne
  \eql@row@\z@
  \eql@display@init
  \let\shoveleft\eql@adjust@shoveleft
  \let\shovecenter\eql@adjust@shovecenter
  \let\shoveright\eql@adjust@shoveright
  \ifdefined\eql@flushleft\else
    \eql@marginleft@\z@
    \eql@marginright@\z@
  \fi
  \eql@adjust@init
  \eql@shape@eval
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@row@\@ne
  \setbox\eql@fieldbox@\hbox\bgroup
    \eql@restore@hfuzz
    \eql@strut@field
    $\m@th\displaystyle%$
      \eql@hook@eqin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@single@end@adjust{%
    $%$
    \hfil
    \kern\z@
  \egroup
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@fieldwidth@\wd\eql@fieldbox@
  \eql@line@height@\ht\eql@fieldbox@
  \eql@line@depth@\dp\eql@fieldbox@
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@halign@init{}%
  \halign{##\cr
    \noalign{\eql@halign@before}%
    \if@eqnsw
      \eql@tagbox@make\eql@compose@print
      \eql@adjust@sel@tag
    \else
      \eql@adjust@sel@notag
    \fi
    \cr
    \noalign{\eql@halign@after}%
  }%
  \eql@row@\tw@
  \eql@display@close
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Multi-Line Support}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Registers}
%
%   \macro{\eql@column@}
%   \macro{\eql@totalcolumns@}
%    \begin{macrocode}
\newcount\eql@column@
\newcount\eql@totalcolumns@
%    \end{macrocode}
%
%   \ldimen{\eql@totalwidth@}
%    \begin{macrocode}
\newdimen\eql@totalwidth@
%    \end{macrocode}
%
%   \ldimen{\eql@line@width@}
%   \ldimen{\eql@line@avail@}
%   \ldimen{\eql@line@pos@}
%    \begin{macrocode}
\newdimen\eql@line@width@
\newdimen\eql@line@avail@
\newdimen\eql@line@pos@
%    \end{macrocode}
%
%   \macro{\eql@fieldlength@tab}
%   \macro{\eql@fieldlength@save}
%   \macro{\eql@fieldlength@get}
%    \begin{macrocode}
\let\eql@fieldlength@tab\@empty
\def\eql@fieldlength@save#1{%
  \begingroup
    \let\or\relax
    \global\edef\eql@fieldlength@tab{%
      \eql@fieldlength@tab
      \ifnum#1=\@ne
        \or
      \else
        ,%
      \fi
      \the\wd\eql@fieldbox@
    }%
  \endgroup
}
\def\eql@fieldlength@get#1{%
  \ifcase\expandafter#1\eql@fieldlength@tab\fi
}
%    \end{macrocode}
%
%   \macro{\eql@tagwidth@get}
%   \macro{\eql@tagwidth@save}
%    \begin{macrocode}
\let\eql@tagwidth@tab\@empty
\def\eql@tagwidth@get#1{%
  \ifcase\expandafter#1\eql@tagwidth@tab\fi
}
\def\eql@tagwidth@save{%
  \begingroup
    \let\or\relax
    \global\edef\eql@tagwidth@tab{\eql@tagwidth@tab\or\the\eql@tagwidth@}%
  \endgroup
}
\def\eql@tagwidth@savezero{%
  \begingroup
    \let\or\relax
    \global\edef\eql@tagwidth@tab{\the\eql@tagwidth@\eql@tagwidth@tab}%
  \endgroup
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Measure Support}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@measure@init#1{%
  \measuring@true
  \eql@row@\z@
  \let\displaybreak\eql@displaybreak@measure
  \tabskip\z@skip
  \everycr{%
    \noalign{%
      \global\advance\eql@row@\@ne
      #1%
    }%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@measure@restorecounters}
%   \macro{\eql@measure@savecounters}
%    \begin{macrocode}
\let\eql@measure@restorecounters\@empty
\def\eql@measure@savecounters{%
  \begingroup
    \def\@elt##1{%
      \global\csname c@##1\endcsname\the\csname c@##1\endcsname}%
    \global\edef\@gtempa{%
      \cl@@ckpt
      \let\noexpand\eql@measure@restorecounters\noexpand\@empty
    }%
  \endgroup
  \let\eql@measure@restorecounters\@gtempa
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Print Support}
%
% \TODO describe
%
%   \macro{\eql@print@inithalign}
%    \begin{macrocode}
\def\eql@print@init#1{%
  \eql@row@\z@
  \eql@halign@init{%
    \global\eql@displaybreak@pen@\@MM
    \global\advance\eql@row@\@ne
    #1%
  }%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@print@overfull{%
  \dimen@\eql@line@width@
  \advance\dimen@-\hfuzz
  \ifdim\dimen@>\displaywidth
    \setbox\z@\hbox to\displaywidth{\hbox to\eql@line@width@{\hfil}}%
    \wd\z@\z@
    \ht\z@\eql@line@height@
    \dp\z@\eql@line@depth@
    \box\z@
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@tagbox@print@multi}
%    \begin{macrocode}
\def\eql@tagbox@print@multi{%
  \advance\eql@tagwidth@-\eql@tagfuzz@
  \ifdefined\eql@tagsleft
    \eql@display@firstavail@set\z@
    \ifdim\eql@tagwidth@>\eql@line@avail@
      \eql@tagbox@print@left@raise
    \else
      \eql@tagbox@print@left
    \fi
    \kern\displaywidth
  \else
    \kern\displaywidth
    \advance\eql@tagwidth@\eql@line@width@
    \ifdim\eql@tagwidth@>\displaywidth
      \eql@tagbox@print@right@raise
    \else
      \eql@tagbox@print@right
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Line Breaks}
%
% \TODO describe
%
%   \macro{\eql@math@cr}
%    \begin{macrocode}
\protected\def\eql@math@cr{%
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@ampprotecttwo\eql@teststaropt@tight
    {\global\eql@displaybreak@pen@\@M\eql@math@cr@}\eql@math@cr@\z@}
%    \end{macrocode}
%
%   \macro{\eql@math@cr@}
%    \begin{macrocode}
\def\eql@math@cr@[#1]{%
  \eql@math@cr@@@
  \cr
%    \end{macrocode}
%
%    \begin{macrocode}
  \noalign{%
    \ifnum\eql@displaybreak@pen@=\@MM
      \penalty\interdisplaylinepenalty
    \else
      \penalty\eql@displaybreak@pen@
    \fi
    \addtolength\eql@vspaceskip@{#1}%
    \vskip\eql@vspaceskip@
    \global\eql@vspaceskip@\z@skip
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@let@cr}
%    \begin{macrocode}
\def\eql@let@cr#1{%
  \let\\\eql@math@cr
  \let\eql@math@cr@@@#1%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Intertext}
%
% \TODO describe
%
%    \begin{macrocode}
\eql@amsmath@futurebefore{\let\intertext\@undefined}
%    \end{macrocode}
% \TODO revert in everymath?
%   \macro{\intertext}
%   \macro{\eql@intertext@}
%    \begin{macrocode}
\providecommand{\intertext}{\eql@error{Invalid use of \string\intertext}}
%    \end{macrocode}
%
% \TODO why does it fail in measuring? total width?!
% determine total width otherwise!?
%    \begin{macrocode}
\def\eql@intertext@process#1{%
  \eql@math@cr@@@
  \cr
  \ifmeasuring@\else
    \expandafter\eql@intertext@print{#1}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@intertext@print#1{%
  \noalign{%
    \eql@halign@after
    \eql@setkeys{intertext}\eql@intertext@opt
    \normalbaselines
    \penalty\postdisplaypenalty
    \addtolength\eql@vspaceskip@\belowdisplayskip
    \vskip\eql@vspaceskip@
    \global\eql@vspaceskip@\z@skip
    \vbox{%
      \@parboxrestore
      \ifdim
        \ifdim\@totalleftmargin=\z@\linewidth\else-\maxdimen\fi=\columnwidth
      \else
        \parshape\@ne
        \@totalleftmargin\linewidth
      \fi
      \noindent
      \ignorespaces
      #1%
      \par
    }%
    \penalty\predisplaypenalty
    \vskip\abovedisplayskip
    \eql@halign@prevdepth@\z@
    \eql@halign@before
  }
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\newenvironment{eql@intertext}{%
  \eql@testopt@tight\eql@intertext@{}%
}{%
  \aftergroup\eql@intertext@after
  \ignorespacesafterend
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@intertext@env{intertext}
\def\eql@intertext@[#1]{%
  \global\def\eql@intertext@opt{#1}%
  \ifx\@currenvir\eql@intertext@env
    \expandafter\eql@scan@env\expandafter\eql@intertext@inject
  \else
    \expandafter\eql@intertext@process
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@intertext@inject{%
  \global\edef\eql@intertext@after{%
    \noexpand\eql@intertext@process{%
      \ifx\eql@scan@body\eql@scan@body@dump
        \eql@scan@body@dump
      \else
        \noexpand\scantokens{\eql@scan@body@dump}%
      \fi
    }%
  }%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Main}
%
% \TODO note that switching from align to lines mode,
% the width can be incorrect due to different formatting (punctuation only?!).
% only minor discrpancies expected and lines can adjust
%   \macro{\eql@multi@main}
%    \begin{macrocode}
\let\eql@multi@mode@lines\eql@false
\def\eql@multi@main{%
  \eql@numbering@eval@mode
  \eql@stack@save@multi
  \ifdefined\eql@subequations@active
    \let\eql@numbering@subeq@use\eql@false
  \fi
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@init
  \fi
  \let\intertext\eql@intertext
  \let\endintertext\endeql@intertext
  \let\shoveleft\eql@adjust@shoveleft
  \let\shovecenter\eql@adjust@shovecenter
  \let\shoveright\eql@adjust@shoveright
  \ifdefined\eql@multi@mode@lines
    \expandafter\eql@lines@measure
  \else
    \ifdefined\eql@ampproof@active
      \eql@ampproof
    \fi
    \expandafter\eql@align@measure
  \fi
  \ifx\eql@numbering@subeq@use\@ne
    \eql@numbering@subeq@revert
  \fi
  \ifdefined\eql@multi@mode@lines\else
    \ifdefined\eql@multi@linesfallback
      \ifnum\eql@totalcolumns@=\@ne
        \let\eql@multi@mode@lines\eql@true
        \eql@shape@set{r}%
%        \eql@lines@measure
      \fi
    \fi
  \fi
  \ifdefined\eql@multi@mode@lines
    \expandafter\eql@lines@print
  \else
    \expandafter\eql@align@print
  \fi
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@close
  \fi
  \eql@stack@restore
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@mode@equation{%
  \let\eql@equations@mode@single\eql@true
  \let\eql@equations@end\eql@single@end
}
\def\eql@mode@align{%
  \let\eql@equations@mode@single\eql@false
  \let\eql@multi@mode@lines\eql@false
  \let\eql@equations@end\@empty
}
\def\eql@mode@lines{%
  \let\eql@equations@mode@single\eql@false
  \let\eql@multi@mode@lines\eql@true
  \let\eql@equations@end\@empty
}
\eql@mode@align
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Multi-Line Lines Mode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Measure}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@lines@measure@line@begin{%
%<dev>\eql@dev{starting line \the\eql@row@}%
  \eql@numbering@measure@line@begin
  \eql@hook@linein
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@measure@line@end{%
  \eql@punct@apply@line
  \eql@hook@lineout
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@measure@field{%
  \kern\wd\eql@fieldbox@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@measure@tag{%
  \ifnum\eql@numbering@target@<\z@
    \if@eqnsw
      \eql@compose@null
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@lines@measure}
%    \begin{macrocode}
\def\eql@lines@measure{%
%<dev>\eql@dev@enter\eql@lines@measure
  \eql@measure@savecounters
  \setbox\z@\vbox{%
    \eql@numbering@measure@init
    \eql@measure@init\eql@lines@measure@line@begin
    \eql@let@cr\eql@lines@measure@line@end
    \halign{%
      \setbox\eql@fieldbox@\hbox{%
        \@lign
        $\m@th\displaystyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
        $%
      }%
      \eql@lines@measure@field
      \eql@lines@measure@tag
      \crcr
      \noalign{%
        \eql@hook@blockbefore
      }%
      \eql@hook@blockin
      \eql@scan@body
      \ifvmode\else
        \eql@punct@apply@block
        \eql@hook@blockout
        \eql@lines@measure@line@end
        \cr
      \fi
      \omit
      \cr
      \noalign{%
        \eql@hook@blockafter
      }%
    }%
    \global\advance\eql@row@-\tw@
    \eql@numbering@measure@eval
  }%
  \eql@totalrows@\eql@row@
  \setbox\z@\vbox{%
    \unvbox\z@
    \unpenalty
    \global\setbox\@ne\lastbox
  }%
  \eql@totalwidth@\wd\@ne
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@test
  \fi
  \eql@measure@restorecounters
%<dev>\eql@dev@leave\eql@lines@measure
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Print}
%
% \TODO describe
%
%   \macro{\eql@lines@math@cr}
%    \begin{macrocode}
\def\eql@lines@print@line@begin{%
%<dev>\eql@dev{starting line \the\eql@row@}%
  \eql@numbering@print@line@begin
  \eql@hook@linein
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@print@line@end{%
  \eql@punct@apply@line
  \eql@hook@lineout
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@print@line@adjust{%
  \eql@numbering@print@line@eval
  \eql@fieldwidth@\wd\eql@fieldbox@
  \eql@line@height@\ht\eql@fieldbox@
  \eql@line@depth@\dp\eql@fieldbox@
  \if@eqnsw
    \eql@tagbox@make\eql@compose@print
    \eql@adjust@sel@tag
  \else
    \eql@adjust@sel@notag
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@print{%
%<dev>\eql@dev@enter\eql@lines@print
  \eql@display@init
  \ifdefined\eql@flushleft
% \TODO any init needed here? marginleft is used per line!
  \else
    \ifdefined\eql@paddingmax
      \eql@marginleft@\z@
      \eql@marginright@\z@
    \else
      \dimen@\displaywidth
      \advance\dimen@-\eql@totalwidth@
      \advance\dimen@-\eql@tagmargin@
      \divide\dimen@\tw@
      \eql@marginleft@\dimen@
      \advance\eql@marginleft@-\eql@paddingleft@
      \ifdim\eql@marginleft@<\z@
        \eql@marginleft@\z@
      \fi
      \eql@marginright@\dimen@
      \advance\eql@marginright@-\eql@paddingright@
      \ifdim\eql@marginright@<\z@
        \eql@marginright@\z@
      \fi
    \fi
  \fi
  \eql@adjust@init
  \eql@numbering@print@init
  \eql@print@init\eql@lines@print@line@begin
  \eql@let@cr\eql@lines@print@line@end
  \tabskip\z@skip
  \halign{%
      \eql@shape@eval
      \setbox\eql@fieldbox@\hbox{%
        \eql@restore@hfuzz
        \eql@strut@field
        \@lign
        $\m@th\displaystyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
        $%
        \hfil
        \kern\z@
      }%
      \eql@lines@print@line@adjust
      \crcr
    \noalign{%
      \eql@halign@before
      \eql@numbering@print@block@begin
      \eql@hook@blockbefore
    }%
% \TODO relax? leavevmode?!
    \eql@hook@blockin
    \eql@scan@body
    \ifvmode\else
      \eql@punct@apply@block
      \eql@hook@blockout
      \eql@lines@print@line@end
      \cr
    \fi
    \noalign{%
      \eql@hook@blockafter
      \eql@halign@after
%<dev>\eql@dev@leave\eql@lines@print
    }%
  }%
  \eql@display@close
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Multi-Line Align Mode}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Registers}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@align@margins\eql@true
%    \end{macrocode}
%
%   \macro{\eql@align@inter@}
%    \begin{macrocode}
\newcount\eql@align@inter@
%    \end{macrocode}
%
%   \macro{\eql@colwidth@tab}
%    \begin{macrocode}
\let\eql@colwidth@tab\@empty
%    \end{macrocode}
%
%   \macro{\eql@align@colwidth@get}
%    \begin{macrocode}
\def\eql@align@colwidth@get#1{%
  \ifcase\expandafter#1\eql@colwidth@tab\else\z@\fi
}
\def\eql@align@colwidth@save{%
  \begingroup
    \let\or\relax
    \global\edef\eql@colwidth@tab{\or\the\wd\thr@@\eql@colwidth@tab}%
  \endgroup
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{General Processing, Preamble}
%
% \TODO describe
%
%   \macro{\eql@align@add@amp}
%   \macro{\eql@align@completerow}
%    \begin{macrocode}
\def\eql@align@add@amp#1{\if m#1&\omit\expandafter\eql@align@add@amp\fi}
\def\eql@align@completerow#1{%
  \begingroup
  \count@#1%
  \advance\count@-\eql@column@
\advance\count@\@ne
  \edef\eql@tmp{\endgroup
    \expandafter\eql@align@add@amp\romannumeral\number\count@ 000q}%
  \eql@tmp
}
%    \end{macrocode}
%
%   \macro{\eql@align@preamble}
%    \begin{macrocode}
\def\eql@align@preamble#1#2#3{%
  &%
  \global\advance\eql@column@\@ne
  \hfil
  \global\setbox\eql@fieldbox@\hbox{%
    #3%
    \@lign
    $\m@th\displaystyle
      \eql@hook@colin
      ##%
      \eql@class@innerleft
      \eql@hook@innerleft
    $%
  }%
  \global\eql@fieldwidth@\wd\eql@fieldbox@
  #2%
  \tabskip\z@skip
  &%
  \global\advance\eql@column@\@ne
  \setbox\eql@fieldbox@\hbox{%
% \TODO temp
\kern-\wd\eql@fieldbox@
\box\eql@fieldbox@
    #3%
    \@lign
    $\m@th\displaystyle
      \eql@hook@innerright
      \eql@class@innerright@sel
      ##%
      \eql@punct@apply@col
      \eql@hook@colout
    $%
  }%
  #2%
  \hfil
  \tabskip#1%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@align@print@trailright{%
   &\omit
    \global\advance\eql@column@\@ne
    \setbox\eql@fieldbox@\hbox{%
\kern-\wd\eql@fieldbox@\box\eql@fieldbox@
    }%
    \eql@align@print@field
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Print}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@align@print@field{%
%    \end{macrocode}
% determine available and used space
%    \begin{macrocode}
  \dimen@\eql@align@colwidth@get\eql@column@\relax
  \ifdim\wd\eql@fieldbox@>\z@
    \ifdim\eql@line@width@=\z@
      \eql@line@avail@\eql@line@pos@
      \ifodd\eql@column@
        \advance\eql@line@avail@\dimen@
        \advance\eql@line@avail@-\wd\eql@fieldbox@
      \fi
      \global\eql@line@avail@\eql@line@avail@
    \fi
    \eql@line@width@\eql@line@pos@
    \ifodd\eql@column@
      \advance\eql@line@width@\dimen@
    \else
      \advance\eql@line@width@\wd\eql@fieldbox@
    \fi
    \global\eql@line@width@\eql@line@width@
  \fi
  \advance\eql@line@pos@\dimen@
  \ifodd\eql@column@\else
    \advance\eql@line@pos@\eql@colsep@
  \fi
  \global\eql@line@pos@\eql@line@pos@
%    \end{macrocode}
%    update height and depth
%    \begin{macrocode}
  \ifdim\ht\eql@fieldbox@>\eql@line@height@
    \global\eql@line@height@\ht\eql@fieldbox@
  \fi
  \ifdim\dp\eql@fieldbox@>\eql@line@depth@
    \global\eql@line@depth@\dp\eql@fieldbox@
  \fi
%    \end{macrocode}
%    print box
% enforce given width:
% hopefully measure was correct, but need a precise width for tag placement
%    \begin{macrocode}
%
%  \box\eql@fieldbox@
%
%  \dimen@\eql@align@colwidth@get\eql@column@\relax
%  \advance\dimen@-\wd\eql@fieldbox@
%  \ifodd\eql@column@
%    \kern\dimen@
%    \box\eql@fieldbox@
%  \else
%    \box\eql@fieldbox@
%    \kern\dimen@
%  \fi
%
  \dimen@\eql@align@colwidth@get\eql@column@\relax
  \ifodd\eql@column@
    \kern\dimen@
  \else
    \advance\dimen@-\wd\eql@fieldbox@
    \box\eql@fieldbox@
    \kern\dimen@
  \fi
%
}
%    \end{macrocode}
%
%   \macro{\eql@align@print@line@begin}
%    \begin{macrocode}
\def\eql@align@print@line@begin{%
%<dev>\eql@dev{starting line \the\eql@row@}%
  \global\eql@column@\z@
  \global\eql@line@pos@\eql@marginleft@
  \global\eql@line@width@\z@
  \global\eql@line@avail@\eql@totalwidth@
  \global\eql@line@height@\z@
  \global\eql@line@depth@\z@
  \eql@numbering@print@line@begin
  \eql@hook@linein
}
%    \end{macrocode}
%
%   \macro{\eql@align@print@line@end}
%    \begin{macrocode}
\def\eql@align@print@line@end{%
  \eql@punct@apply@line
  \eql@hook@lineout
% \TODO add an even column with empty stuff if box processing deferred
  \ifodd\eql@column@
    \expandafter\eql@align@print@trailright
  \fi
  \eql@align@completerow\eql@totalcolumns@
  \eql@align@print@line
}
%    \end{macrocode}
%
%   \macro{\eql@align@print@line}
%    \begin{macrocode}
\def\eql@align@print@line{%
  \dimen@\eql@totalwidth@
  \advance\dimen@\eql@colsep@
  \kern-\dimen@
%    \end{macrocode}
%    determine first line available space
%    \begin{macrocode}
  \eql@display@firstavail@set\eql@line@avail@
  \eql@print@overfull
  \eql@numbering@print@line@eval
  \if@eqnsw
    \eql@tagbox@make\eql@compose@print
    \eql@tagbox@print@multi
  \else
    \kern\displaywidth
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@align@print}
%    \begin{macrocode}
\def\eql@align@print{%
%<dev>\eql@dev@enter\eql@align@print
  \eql@align@adjust
  \eql@display@init
  \eql@numbering@print@init
  \eql@print@init\eql@align@print@line@begin
  \eql@let@cr\eql@align@print@line@end
  \tabskip\eql@marginleft@
  \halign{%
    \span\eql@align@preamble\eql@colsep@\eql@align@print@field\eql@strut@field
    \crcr
    \noalign{%
      \eql@halign@before
      \eql@numbering@print@block@begin
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
    \eql@scan@body
    \ifvmode\else
      \eql@punct@apply@block
      \eql@hook@blockout
      \eql@align@print@line@end
      \cr
    \fi
    \noalign{%
      \eql@hook@blockafter
      \eql@halign@after
%<dev>\eql@dev@leave\eql@align@print
    }%
  }%
  \eql@display@close
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Measure}
%
% \TODO describe
%
%   \macro{\eql@align@measure@line@begin}
%    \begin{macrocode}
\def\eql@align@measure@line@begin{%
%<dev>\eql@dev{starting line \the\eql@row@}%
  \global\eql@column@\z@
  \eql@numbering@measure@line@begin
  \eql@hook@linein
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@align@measure@field{%
  \eql@fieldlength@save\eql@column@
  \kern\wd\eql@fieldbox@
}
%    \end{macrocode}
%
%   \macro{\eql@align@measure@line@end}
%    \begin{macrocode}
\def\eql@align@measure@line@end{%
  \eql@punct@apply@line
  \eql@hook@lineout
  &\omit
  \ifnum\eql@column@>\eql@totalcolumns@
    \global\eql@totalcolumns@\eql@column@
  \fi
  \eql@align@measure@tag
}
%    \end{macrocode}
%
%   \macro{\eql@align@measure@tag}
%    \begin{macrocode}
\def\eql@align@measure@tag{%
  \ifnum\eql@numbering@target@<\z@
    \if@eqnsw
      \eql@tagbox@make\eql@compose@measure
    \else
      \eql@tagwidth@\z@
    \fi
    \eql@tagwidth@save
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@align@measure}
%    \begin{macrocode}
\def\eql@align@measure{%
%<dev>\eql@dev@enter\eql@align@measure
  \eql@totalcolumns@\z@
  \let\eql@tagwidth@tab\@empty
  \let\eql@fieldlength@tab\@empty
  \eql@measure@savecounters
  \setbox\z@\vbox{%
    \eql@numbering@measure@init
    \eql@measure@init\eql@align@measure@line@begin
    \eql@let@cr\eql@align@measure@line@end
    \halign{%
      \span\eql@align@preamble\z@skip\eql@align@measure@field\relax
      \crcr
      \noalign{%
        \eql@hook@blockbefore
      }%
      \eql@hook@blockin
      \eql@scan@body
%    \end{macrocode}
%    \TODO test for vmode okay?!
%    \begin{macrocode}
      \ifvmode\else
        \eql@punct@apply@block
        \eql@hook@blockout
        \eql@align@measure@line@end
        \cr
      \fi
      \noalign{%
        \eql@hook@blockafter
      }%
%    \end{macrocode}
%    \TODO should we enforce even columns already here?!
%    \TODO should we guard against no columns at all?!
%    \begin{macrocode}
      \eql@align@completerow\eql@totalcolumns@
      \cr
    }%
    \global\advance\eql@row@-\tw@
    \eql@numbering@measure@eval
    \ifnum\eql@numbering@target@>\z@
      \eql@tagbox@make\eql@compose@measure
      \eql@tagwidth@savezero
    \fi
  }%
  \eql@totalrows@\eql@row@
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@test
  \fi
  \eql@measure@restorecounters
%  \eql@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@totalwidth@\wd\@ne
%    \end{macrocode}
%
%    \TODO why not recycle box contents altogether?!
%    \begin{macrocode}
  \let\eql@colwidth@tab\@empty
  \loop
    \setbox\@ne\hbox{%
      \unhbox\@ne
      \unskip
      \global\setbox\thr@@\lastbox
    }%
  \ifhbox\thr@@
    \eql@align@colwidth@save
  \repeat
%<dev>\eql@dev@leave\eql@align@measure
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Adjust}
%
% \TODO describe
%
%   \TODO does this respect the margin for numbers in centre mode?
%
%    \begin{macrocode}
\def\eql@align@adjust{%
%    \end{macrocode}
%
%    \TODO shouldn't we do this earlier for access to last column?
%    \begin{macrocode}
  \ifodd\eql@totalcolumns@
    \advance\eql@totalcolumns@\@ne
  \fi
%    \end{macrocode}
%
%    \TODO should we guard against no columns?!
%    \begin{macrocode}
  \ifnum\eql@totalcolumns@<\thr@@
    \let\eql@align@margins\eql@true
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@align@inter@\eql@totalcolumns@
  \divide\eql@align@inter@\tw@
  \advance\eql@align@inter@\m@ne
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@colsep@\displaywidth
  \advance\eql@colsep@-\eql@totalwidth@
  \ifdefined\eql@flushleft
    \advance\eql@colsep@-\eql@flushleftmargin@
  \fi
  \count@\eql@align@inter@
  \ifdefined\eql@align@margins
    \ifdefined\eql@flushleft
      \advance\count@\@ne
    \else
      \advance\count@\tw@
    \fi
  \fi
  \divide\eql@colsep@\count@
%    \end{macrocode}
%    \TODO here or above, this code does not make much sense
%    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)
%    \begin{macrocode}
  \ifdim\eql@colsep@<\eql@colsepmin@
    \eql@colsep@\eql@colsepmin@
  \else
    \ifdim\eql@colsep@>\eql@colsepmax@
      \eql@colsep@\eql@colsepmax@
    \fi
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifdefined\eql@flushleft
    \ifdim\eql@colsep@=\eql@colsepmin@
      \eql@marginleft@\displaywidth
      \advance\eql@marginleft@-\eql@totalwidth@
      \advance\eql@marginleft@-\eql@align@inter@\eql@colsep@
      \ifdim\eql@marginleft@>\eql@flushleftmargin@
        \eql@marginleft@\eql@flushleftmargin@
      \else
        \ifdim\eql@marginleft@<\eql@flushleftmarginmin@
          \eql@marginleft@\eql@flushleftmarginmin@
        \fi
      \fi
    \else
      \eql@marginleft@\eql@flushleftmargin@
    \fi
  \else
    \ifdefined\eql@align@margins
      \eql@marginleft@\displaywidth
      \advance\eql@marginleft@-\eql@totalwidth@
      \advance\eql@marginleft@-\eql@align@inter@\eql@colsep@
      \ifdim\eql@marginleft@<\eql@tagmargin@
        \ifdim\ifdefined\eql@tagsleft\eql@marginleft@\else-\p@\fi<\z@
          \eql@marginleft@\z@
        \fi
      \else
        \advance\eql@marginleft@-\eql@tagmargin@
        \divide\eql@marginleft@\tw@
      \fi
    \else
      \eql@marginleft@\z@
    \fi
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifdefined\eql@tagsleft
    \let\eql@align@adjust@test\eql@align@adjust@test@tagleft
  \else
    \let\eql@align@adjust@test\eql@align@adjust@test@tagright
  \fi
  \loop\ifnum\eql@row@>\z@
    \ifnum\eql@numbering@target@<\z@
      \eql@tagwidth@\eql@tagwidth@get\eql@row@\relax
    \else
      \ifnum\eql@numbering@target@=\eql@row@
        \eql@tagwidth@\eql@tagwidth@get\z@\relax
      \fi
    \fi
    \ifdim\eql@tagwidth@>\z@
      \eql@align@adjust@width
      \eql@align@adjust@test
    \fi
    \advance\eql@row@\m@ne
  \repeat
%    \end{macrocode}
%
%    \begin{macrocode}
  \advance\eql@totalwidth@\eql@align@inter@\eql@colsep@
  \advance\eql@totalwidth@\eql@marginleft@
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \paragraph{Calc Space.}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@align@adjust@width{%
  \eql@line@pos@\z@
  \eql@column@\z@
  \eql@line@avail@\eql@totalwidth@
  \@tempcnta\eql@totalcolumns@
  \eql@line@width@\z@
  \@tempcntb\z@
  \edef\@tempb{\eql@fieldlength@get\eql@row@}%
  \@for\@tempa:=\@tempb\do
    \eql@align@adjust@width@col
  \advance\@tempcnta\m@ne
  \divide\@tempcnta\tw@
  \advance\@tempcntb\m@ne
  \divide\@tempcntb\tw@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@align@adjust@width@col{%
  \advance\eql@column@\@ne
  \@tempdima\@tempa\relax
  \dimen@\eql@align@colwidth@get\eql@column@\relax
  \ifdim\@tempdima>\z@
    \ifdim\eql@line@width@=\z@
      \eql@line@avail@\eql@line@pos@
      \@tempcnta\eql@column@
      \ifodd\eql@column@
        \advance\eql@line@avail@\dimen@
        \advance\eql@line@avail@-\@tempdima
      \fi
    \fi
    \eql@line@width@\eql@line@pos@
    \@tempcntb\eql@column@
    \ifodd\eql@column@
      \advance\eql@line@width@\dimen@
    \else
      \advance\eql@line@width@\@tempdima
    \fi
  \fi
  \advance\eql@line@pos@\dimen@
}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \paragraph{Placement for right tags.}
%
% \TODO describe
%
%   \macro{\eql@align@adjust@test@r}
%    \begin{macrocode}
\def\eql@align@adjust@test@tagright{%
%    \end{macrocode}
%
%    \begin{macrocode}
  \@tempdima\eql@line@width@
  \advance\@tempdima\eql@tagwidth@
%    \end{macrocode}
%
%    \begin{macrocode}
  \dimen@\eql@marginleft@
  \advance\dimen@\@tempdima
  \advance\dimen@\@tempcntb\eql@colsep@
  \ifdim\dimen@>\displaywidth
    \eql@align@adjust@modify@tagright
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@align@adjust@modify@tagright{%
  \dimen@\eql@colsepmin@
  \multiply\dimen@\@tempcntb
  \advance\dimen@\@tempdima
  \ifdefined\eql@flushleft
    \advance\dimen@\eql@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?!
%    \begin{macrocode}
    \ifnum\@tempcntb>\z@
      \dimen@\displaywidth
      \advance\dimen@-\@tempdima
      \count@\@tempcntb
      \ifdefined\eql@flushleft
        \advance\dimen@-\eql@marginleft@
      \else
        \ifdefined\eql@align@margins
          \advance\count@\@ne
        \fi
      \fi
      \divide\dimen@\count@
      \ifdim\dimen@<\eql@colsep@
        \ifdim\dimen@<\eql@colsepmin@
          \dimen@\eql@colsepmin@
        \fi
        \eql@colsep@\dimen@
      \fi
    \fi
%    \end{macrocode}
%
%    \TODO could this possibly be less than the minimum margin?
%      (we checked above, but under the assumption that
%      |\eql@colsep@| is minimal!)
%    \begin{macrocode}
    \dimen@\displaywidth
    \advance\dimen@-\@tempdima
    \advance\dimen@-\@tempcntb\eql@colsep@
    \ifdim\dimen@<\eql@marginleft@
      \eql@marginleft@\dimen@
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \paragraph{Placement for left tags.}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@align@adjust@test@tagleft{%
  \count@\eql@align@inter@
  \advance\count@-\@tempcnta
  \@tempdima-\eql@line@avail@
  \advance\@tempdima\eql@tagwidth@
  \dimen@\eql@marginleft@
  \advance\dimen@\@tempcnta\eql@colsep@
  \ifdim\dimen@<\@tempdima
    \eql@align@adjust@modify@tagleft
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@align@adjust@modify@tagleft{%
%    \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?!
%    \begin{macrocode}
  \ifdefined\eql@flushleft
    \dimen@\eql@flushleftmarginmax@
  \else
    \dimen@\displaywidth
  \fi
  \ifdim\dimen@>\eql@tagwidth@
%    \end{macrocode}
%
%    \begin{macrocode}
    \dimen@\eql@colsepmin@
    \multiply\dimen@\count@
    \advance\dimen@\eql@totalwidth@
    \advance\dimen@\@tempdima
    \ifdim\dimen@>\displaywidth\else
%    \end{macrocode}
%
%    \begin{macrocode}
      \ifnum\count@>0
        \dimen@\displaywidth
        \advance\dimen@-\eql@totalwidth@
        \advance\dimen@-\@tempdima
        \ifdefined\eql@align@margins
          \advance\count@\@ne
        \fi
        \divide\dimen@\count@
        \ifdim\dimen@<\eql@colsep@
          \ifdim\dimen@<\eql@colsepmin@
            \dimen@\eql@colsepmin@
          \fi
          \advance\dimen@-\eql@colsep@
          \advance\eql@marginleft@-\eql@align@inter@\dimen@
          \advance\eql@colsep@\dimen@
        \fi
      \fi
%    \end{macrocode}
%
%    \begin{macrocode}
      \dimen@-\@tempcnta\eql@colsep@
      \advance\dimen@\@tempdima
      \ifdim\dimen@>\eql@marginleft@
        \eql@marginleft@\dimen@
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Interface}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Scanning the Environment's Body}
%
% The multi-line equatiuon environment must scan its body twice:
% once to determine how wide the columns are and then to actually
% typeset them. This means that we must collect all text in this body
% before calling the environment macros.
% The mechanism and its description follows \ctanpkg{amsmath} closely.
%
%   \macro{\eql@scan@reg@}
% We start by defining a token register to contain the body.
%    \begin{macrocode}
\newtoks\eql@scan@reg@
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@scan@body@dump{\the\eql@scan@reg@}
\def\eql@scan@body@rescan{%
  \expandafter\scantokens\expandafter{\the\eql@scan@reg@}}
\let\eql@scan@body\eql@scan@body@dump
%    \end{macrocode}
%
%   \macro{\eql@scan@addto}
% Then we define a macro to add something (i.e.\ its argument) to the
% token register |\@envbody|:
%    \begin{macrocode}
\def\eql@scan@addto#1{\eql@scan@reg@\expandafter{\the\eql@scan@reg@#1}}
%    \end{macrocode}
%
%   \macro{\eql@scan@env}
% The macro |\eql@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:
%    \begin{macrocode}
\def\eql@scan@env#1{%
%<dev>\eql@dev@enter\eql@scan@env
  \def\eql@scan@end{#1\expandafter\end\expandafter{\@currenvir}}%
  \eql@scan@reg@{}\def\eql@scan@stack{b}%
%    \end{macrocode}
% If we simply called |\eql@scan@env@iterate| directly,
% the error message for a |\par| token (usually from a blank line)
% would refer to |\eql@scan@env@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@scan@env@iterate|:
%    \begin{macrocode}
%  \begingroup
  \edef\eql@scan@iterate{\expandafter\noexpand\csname\@currenvir\endcsname}%
  \expandafter\let\expandafter\eql@scan@env@org\eql@scan@iterate
  \expandafter\let\eql@scan@iterate\eql@scan@env@iterate
  \eql@scan@iterate
}
%    \end{macrocode}
%
%   \macro{\eql@scan@env@count}
% When adding a piece of the current environment's contents to
% |\eql@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@scan@env@count#1\begin#2{%
  \ifx\end#2\else b\expandafter\eql@scan@env@count\fi
}
%    \end{macrocode}
%
%   \macro{\eql@scan@env@iterate}
% |\eql@scan@env@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@begins| function. 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:
%    \begin{macrocode}
\def\eql@scan@env@iterate#1\end#2{%
  \edef\eql@scan@stack{%
    \eql@scan@env@count#1\begin\end\expandafter\@gobble\eql@scan@stack}%
  \ifx\@empty\eql@scan@stack
    \@checkend{#2}%
    \eql@scan@addto{#1}%
    \expandafter\let\eql@scan@iterate\eql@scan@env@org
%<dev>\eql@dev@leave\eql@scan@env
    \expandafter\eql@scan@end
  \else
    \eql@scan@addto{#1\end{#2}}%
    \expandafter\eql@scan@iterate
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@scan@env@cancel{%
  \@namedef{end\@currenvir}{\ignorespacesafterend}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{square brackets}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@scan@sqr#1{%
%<dev>\eql@dev@enter\eql@scan@sqr
  \def\eql@scan@end{#1\]}%
  \eql@scan@reg@{}\def\eql@scan@stack{b}%
  \let\eql@scan@sqr@org\[%\]
  \let\[\eql@scan@sqr@iterate%\]
  \[%\]
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@scan@sqr@count#1\[#2{%\]
  \ifx\]#2\else b\expandafter\eql@scan@sqr@count\fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@scan@sqr@iterate#1\]{%
  \edef\eql@scan@stack{%
    \eql@scan@sqr@count#1\[\]\expandafter\@gobble\eql@scan@stack}%
  \ifx\@empty\eql@scan@stack
    \let\[\eql@scan@sqr@org%\]
    \eql@scan@addto{#1}%
%<dev>\eql@dev@leave\eql@scan@sqr
    \expandafter\eql@scan@end
  \else
    \eql@scan@addto{#1\]}%
    \expandafter\[%\]
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@scan@sqrang@cancel{\ignorespaces}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{anuglar brackets}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@scan@ang#1{%
%<dev>\eql@dev@enter\eql@scan@ang
  \def\eql@scan@end{#1\>}%
  \eql@scan@reg@{}\def\eql@scan@stack{b}%
  \let\eql@scan@ang@org\<%\>
  \let\<\eql@scan@ang@iterate%\>
  \<%\>
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@scan@ang@count#1\<#2{%\>
  \ifx\>#2\else b\expandafter\eql@scan@ang@count\fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@scan@ang@iterate#1\>{%
  \edef\eql@scan@stack{%
    \eql@scan@ang@count#1\<\>\expandafter\@gobble\eql@scan@stack}%
  \ifx\@empty\eql@scan@stack
    \let\<\eql@scan@ang@org%\>
    \eql@scan@addto{#1}%
%<dev>\eql@dev@leave\eql@scan@ang
    \expandafter\eql@scan@end
  \else
    \eql@scan@addto{#1\>}%
    \expandafter\<%\>
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Options Processing}
%
%    \begin{macrocode}
\def\eql@equations@testall{\eql@equations@testtilde}
\def\eql@equations@testtilde#1{%
  \eql@ifnextgobble@tight~%
    {\eqnaddopt{lines}\eql@equations@testopt{#1}}%
    {\eql@equations@testopt{#1}}}
\def\eql@equations@testopt#1{%
  \eql@ifnextchar@tight[%]
    {\eql@equations@addopt{\eql@equations@testexcl{#1}}}%
    {\eql@equations@testexcl{#1}}}
\def\eql@equations@addopt#1[#2]{\eqnaddopt{#2}#1}
\def\eql@equations@testexcl#1{%
  \eql@ifnextgobble@tight!%
    {\eqnaddopt{donumber}\eql@equations@testat{#1}}%
    {\eql@equations@teststar{#1}}}
\def\eql@equations@teststar#1{%
  \eql@ifstar@tight%
    {\eqnaddopt{nonumber}\eql@equations@testat{#1}}%
    {\eql@equations@testat{#1}}}
\def\eql@equations@testat#1{%
  \eql@ifat@tight
    {\eql@equations@addlabel{#1}}%
    {#1}}
\def\eql@equations@addlabel#1#2{\eqnaddopt{label={#2}}#1}
\def\eql@equations@processopt{%
  \let\eql@blocklabel\@undefined
  \let\eql@blocktag\@undefined
  \let\eql@display@doatend\@empty
  \eql@abovespace@\z@skip
  \eql@belowspace@\z@skip
  \eql@displaybreak@prepen@\@MM
  \eql@nextopt@process{equations}%
  \let\eql@punct@block\eql@punct@main
  \let\eql@punct@main\relax
  \setlength\eql@paddingleft@\eql@paddingleft@val
  \setlength\eql@paddingright@\eql@paddingright@val
  \setlength\eql@indent@\eql@indent@val
  \setlength\eql@colsepmin@\eql@colsepmin@val
  \setlength\eql@colsepmax@\eql@colsepmax@val
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Environments}
%
%  \environment{equations}
%    \begin{macrocode}
\newenvironment{equations}{%
%<dev>\eql@dev@enterenv
  \ifmmode
    \eql@error@mathmode{\string\begin{\@currenvir}}%
    \expandafter\eql@scan@env\expandafter\eql@scan@env@cancel
  \else
    \eql@halign@catchprevdepth
    $$%$$
    \expandafter\eql@ampprotect\expandafter\eql@equations@testall
      \expandafter\eql@equations@start
  \fi
}{%
  \eql@equations@end
  $$%$$
  \ignorespacesafterend
%<dev>\eql@dev@leaveenv
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@equations@start{%
  \eql@equations@processopt
  \ifdefined\eql@equations@mode@single
    \expandafter\eql@single@start
  \else
    \expandafter\eql@scan@env\expandafter\eql@multi@main
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{square and angle brackets}
%
%    \begin{macrocode}
\def\eql@equations@sqr@opt{equation,nonumber}
\protected\def\eql@equations@sqr@open{%
  \ifmmode
    \eql@error@mathmode{\string\[...\string\]}%
    \expandafter\eql@scan@sqr\expandafter\eql@scan@sqrang@cancel
  \else
%<dev>\eql@dev@enter{\[...\string\]}%
    \expandafter\eqnaddopt\expandafter{\eql@equations@sqr@opt}%
    \eql@halign@catchprevdepth
    $$%$$
    \expandafter\eql@ampprotect\expandafter\eql@equations@testall
      \expandafter\eql@equations@sqr@start
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@equations@ang@opt{align,nonumber}
\protected\def\eql@equations@ang@open{%
  \ifmmode
    \eql@error@mathmode{\string\<...\string\>}%
    \expandafter\eql@scan@ang\expandafter\eql@scan@sqrang@cancel
  \else
%<dev>\eql@dev@enter{\<...\string\>}%
    \expandafter\eqnaddopt\expandafter{\eql@equations@ang@opt}%
    \eql@halign@catchprevdepth
    $$%$$
    \expandafter\eql@ampprotect\expandafter\eql@equations@testall
      \expandafter\eql@equations@ang@start
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@equations@sqr@start{%
  \eql@equations@processopt
  \ifdefined\eql@equations@mode@single
    \expandafter\eql@single@start
  \else
    \expandafter\eql@scan@sqr\expandafter\eql@multi@main
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@equations@ang@start{%
  \eql@equations@processopt
  \ifdefined\eql@equations@mode@single
    \expandafter\eql@single@start
  \else
    \expandafter\eql@scan@ang\expandafter\eql@multi@main
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\protected\def\eql@equations@sqr@close{%
  \eql@equations@end
  $$%$$
%<dev>\eql@dev@leave{\[...\string\]}%
  \ignorespaces
}
%    \end{macrocode}
%
%    \begin{macrocode}
\protected\def\eql@equations@ang@close{%
  \eql@equations@end
  $$%$$
%<dev>\eql@dev@leave{\<...\string\>}%
  \ignorespaces
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Independent Routines of amsmath}
%
%   \macro{\eqref}
% \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@eqref}[1]{\textup{\tagform@{\ref{#1}}}}
%    \end{macrocode}
%
%   \macro{\numberwithin}
% \ctanpkg{amsmath} defines the macro |\numberwithin|
% to specify that equations should be numbered within sections.
% The \LaTeX{} kernel contains a similar command
% |\counterwithin| (with a slightly extended syntax) that can be used
% as a drop-in replacement for |\numberwithin|:
%    \begin{macrocode}
\DeclareRobustCommand{\eql@numberwithin}[3][\arabic]{%
  \@ifundefined{c@#2}{\@nocounterr{#2}}{%
    \@ifundefined{c@#3}{\@nocounterr{#3}}{%
      \ifdefined\HyOrg@addtoreset
        \HyOrg@addtoreset{#2}{#3}%
      \else
        \@addtoreset{#2}{#3}%
      \fi
      \expandafter\xdef\csname the#2\endcsname{%
        \expandafter\noexpand\csname the#3\endcsname.\noexpand#1{#2}}%
      \ifdefined\theHequation
        \expandafter\xdef\csname theH#2\endcsname{%
          \expandafter\noexpand
          \csname the\@ifundefined{theH#3}{}H#3\endcsname.%
            \noexpand\arabic{#2}}%
      \fi
    }%
  }%
}
%    \end{macrocode}
%
%   \imacro{\allowdisplaybreaks}
% \ctanpkg{amsmath} defines the macro |\allowdisplaybreaks|
% which we also provide for completeness.
% The package uses the general setup mechanism instead:
%    \begin{macrocode}
\DeclareRobustCommand{\eql@allowdisplaybreaks}[1][4]{%
  \eqnlinesset{allowbreaks=#1}%
}
%    \end{macrocode}
%
%   \imacro{\notag}
% \ctanpkg{amsmath} defines the alias |\notag| for |\nonumber|
% which we also provide for completeness:
%    \begin{macrocode}
\newcommand{\eql@notag}{\nonumber}
%    \end{macrocode}
%
%   \imacro{\thetag}
% \ctanpkg{amsmath} defines |\thetag| to print a tag
% which we also provide for completeness:
%    \begin{macrocode}
\newcommand{\eql@thetag}{\leavevmode\tagform@}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Options}
%
% The package uses the \ctanpkg{keyval} mechanism to parse
% key-value pairs to specify adjustments to the behaviour
% of the equations environments:
%    \begin{macrocode}
\RequirePackage{keyval}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Selection Tools}
%
%   \macro{\eql@decide@select}
% Some parameter values take values in a given set,
% e.g.\ |true| vs.\ |false| or |left| vs.\ |right|.
% The macro |\eql@decide@select| is a general purpose selector.
% Arguments |#1| and |#2| describe the category and key
% 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:
%    \begin{macrocode}
\def\eql@decide@select#1#2#3#4{%
  \def\@tempa{#3}%
  \let\@tempd\@undefined
  \@for\@tempc:=#4\do{%
    \ifdefined\@tempd\else
      \edef\@tempb{\noexpand\@tempb:=\expandafter\@firstoftwo\@tempc}%
      \expandafter\@for\@tempb\do{%
        \ifx\@tempa\@tempb
          \expandafter\expandafter\expandafter\def
          \expandafter\expandafter\expandafter\@tempd
          \expandafter\expandafter\expandafter{%
          \expandafter\@secondoftwo\@tempc}%
        \fi
      }%
    \fi
  }%
  \ifdefined\@tempd
    \@tempd
  \else
    \eql@error{undefined value `#3' for option `#2' of `#1'}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@decide@if}
% We will often have to decide between |true| and |false| or related
% pairs of values:
%    \begin{macrocode}
\def\eql@decide@if#1#2#3#4#5{%
  \eql@decide@select{#1}{#2}{#3}{%
    {{on,true,yes,enabled,1}{#4}},%
    {{off,false,no,disabled,0}{#5}}}}
%    \end{macrocode}
%
%   \macro{\eql@decide@bool}
% Boolean values frequently need to be stored into conditional registers:
%    \begin{macrocode}
\def\eql@decide@bool#1#2#3#4{%
  \eql@decide@if{#1}{#2}{#3}{\let#4\eql@true}{\let#4\eql@false}}
%    \end{macrocode}
%
%   \macro{\eql@decide@abovebelow}
% \TODO describe
%    \begin{macrocode}
\def\eql@decide@abovebelow#1#2#3#4#5{%
  \eql@decide@select{#1}{#2}{#3}{%
    {,abovebelow,both,tb}{#4#5},%
    {above,top,t}{#4},%
    {below,bottom,b}{#5}}%
  }
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Declaration Code}
%
%   \macro{\eql@define@key}
% For convenience, we define a wrapper for \ctanpkg{keyval}'s |\define@key|
% which accepts lists of categories and keys.
% We prepend the prefix |eql@| to all our categories so that it is hidden
% from the user in error messages:
%    \begin{macrocode}
\def\eql@define@key#1#2{%
  \eql@ifnextchar@loose[%]
    {\eql@definekey@opt{#1}{#2}}%
    {\eql@definekey@noopt{#1}{#2}}%
}
\def\eql@definekey@noopt#1#2#3{\eql@definekey@for{#1}{#2}{{#3}}}
\def\eql@definekey@opt#1#2[#3]#4{\eql@definekey@for{#1}{#2}{[#3]{#4}}}
\def\eql@definekey@for#1#2#3{%
  \def\eql@for@fn##1##2##3{\define@key{eql@##3}{##2}#3}%
  \edef\eql@for@vara{\noexpand\eql@for@vara:=#1}%
  \expandafter\@for\eql@for@vara\do{%
    \edef\eql@for@varb{\noexpand\eql@for@varb:=#2}%
    \expandafter\@for\eql@for@varb\do{%
      \edef\eql@for@call##1{%
        \noexpand\eql@for@fn{##1}{\eql@for@varb}{\eql@for@vara}}%
      \eql@for@call{##1}%
    }%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@setkeys}
% Our wrapper of \ctanpkg{keyval}'s |\setkeys|
% prepends the prefix |eql@| to the category,
% and it expands the list argument once:
%    \begin{macrocode}
\def\eql@setkeys#1#2{
  \def\eql@tmp{\setkeys{eql@#1}}%
  \expandafter\eql@tmp\expandafter{#2}%
}
%    \end{macrocode}
%
%   \macro{\eql@nextopt}
%   \macro{\eql@nextopt@process}
%   \macro{\eqnaddopt}
% It can be convenient to add arguments to the following
% equations environment, e.g.\ towards defining
% modifier macros:
%    \begin{macrocode}
\let\eql@nextopt\@empty
\def\eql@nextopt@process#1{%
%<dev>\eql@dev@start\eql@nextopt@process
  \eql@setkeys{#1}\eql@nextopt
  \global\let\eql@nextopt\@empty
}
\newcommand{\eqnaddopt}[1]{%
  \expandafter\def\expandafter\eql@nextopt\expandafter{\eql@nextopt,#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Options Declarations}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Modes for Equations Box Environment.}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{equationsbox}{gathered,gather,ga,lines,lined,ln,\string~}[]{%
  \eql@mode@lined}
\eql@define@key{equationsbox}{aligned,align,al,columns,col,@}[]{%
  \eql@mode@aligned}
\eql@define@key{equationsbox}{top,t}[]{\let\eql@box@box\vtop}
\eql@define@key{equationsbox}{center,c}[]{\let\eql@box@box\vcenter}
\eql@define@key{equationsbox}{bottom,b}[]{\let\eql@box@box\vbox}
\eql@define@key{equationsbox}{colsep}{\def\eql@box@colsep{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Modes for Equations Environment.}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{equations}{equation,eq,single,1}[]{\eql@mode@equation}
\eql@define@key{equations}{gathered,gather,ga,lines,lined,ln,\string~}[]{%
  \eql@mode@lines}
\eql@define@key{equations}{aligned,align,al,columns,col,@}[]{%
  \eql@mode@align}
\eql@define@key{equations}{native}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@single@native%
  \ifdefined\eql@single@native\let\eql@flushleft\eql@false\fi}
\eql@define@key{setup}{native}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@single@native}
\eql@define@key{setup}{sqropt}[]{%
  \def\eql@equations@sqr@opt{equation,#1}}
\eql@define@key{setup}{angopt}[]{%
  \def\eql@equations@ang@opt{align,#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Vertical Spacing.}
%
% \TODO set at end of env only!
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,equationsbox,setup}
\eql@define@key\eql@keycat{spread}[\jot]{\def\eql@spread{#1}}
\eql@define@key\eql@keycat{strut}[true]{\eql@decide@if{#3}{#2}{#1}%
  {\let\eql@strut@field\eql@strut}{\let\eql@strut@field\relax}}
\eql@define@key\eql@keycat{struttag}[true]{\eql@decide@if{#3}{#2}{#1}%
  {\let\eql@strut@tag\eql@strut}{\let\eql@strut@tag\relax}}
%    \end{macrocode}
%
% \TODO describe
% \TODO maybe also add pre and post variants? for general setup?
%    \begin{macrocode}
\eql@define@key{equations}{displaybreak}[4]{\eql@displaybreak@pre{#1}}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{allowbreaks,allowdisplaybreaks}[4]{%
  \interdisplaylinepenalty\eql@getdsp@pen{#1}\relax}
\eql@define@key\eql@keycat{displayheight}[\ht\eql@strutbox@]{%
  \def\eql@display@height{#1}}
\eql@define@key\eql@keycat{displaydepth}[\dp\eql@strutbox@]{%
  \def\eql@display@depth{#1}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{equations}{noskip}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\eql@display@atend{%
      \abovedisplayskip\z@skip
      \abovedisplayshortskip\z@skip
      \eql@abovedisplaytagskip@\z@skip}}%
    {\eql@display@atend{%
      \belowdisplayskip\z@skip
      \belowdisplayshortskip\z@skip
      \eql@belowdisplaytagskip@\z@skip}}}
\eql@define@key{equations}{short}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\eql@display@atend{%
      \abovedisplayskip\abovedisplayshortskip}}%
    {\eql@display@atend{%
      \belowdisplayskip\belowdisplayshortskip}}}
\eql@define@key{equations}{long}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\eql@display@atend{%
      \abovedisplayshortskip\abovedisplayskip}}%
    {\eql@display@atend{%
      \belowdisplayshortskip\belowdisplayskip}}}
\eql@define@key{equations}{medskip}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\eql@display@atend{%
      \abovedisplayskip\eql@abovedisplaymedskip@}}%
    {\eql@display@atend{%
      \belowdisplayskip\eql@belowdisplaymedskip@}}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{equations}{skip}{%
  \setlength\eql@abovedisplayskip@{#1}%
  \eql@belowdisplayskip@\eql@abovedisplayskip@%
  \eql@display@atend{%
    \abovedisplayskip\eql@abovedisplayskip@
    \abovedisplayshortskip\abovedisplayskip
    \eql@abovedisplaytagskip@\abovedisplayskip
    \belowdisplayskip\abovedisplayskip
    \belowdisplayshortskip\belowdisplayskip
    \eql@belowdisplaytagskip@\belowdisplayskip}}
\eql@define@key{equations}{aboveskip}{%
  \setlength\eql@abovedisplayskip@{#1}%
  \eql@display@atend{%
    \abovedisplayskip\eql@abovedisplayskip@
    \abovedisplayshortskip\abovedisplayskip
    \eql@abovedisplaytagskip@\abovedisplayskip}}
\eql@define@key{equations}{belowskip}{%
  \setlength\eql@belowdisplayskip@{#1}%
  \eql@display@atend{%
    \belowdisplayskip\eql@belowdisplayskip@
    \belowdisplayshortskip\belowdisplayskip%
    \eql@belowdisplaytagskip@\belowdisplayskip}}
\eql@define@key{equations}{abovespace}{%
  \addtolength\eql@abovespace@{#1}}
\eql@define@key{equations}{belowspace}{%
  \addtolength\eql@belowspace@{#1}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{intertext}{skip}{%
  \setlength\abovedisplayskip{#1}\belowdisplayskip\abovedisplayskip}
\eql@define@key{intertext}{aboveskip}{%
  \setlength\belowdisplayskip{#1}}
\eql@define@key{intertext}{belowskip}{%
  \setlength\abovedisplayskip{#1}}
\eql@define@key{intertext}{noskip}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\belowdisplayskip\z@skip\belowdisplayshortskip\z@skip}%
    {\abovedisplayskip\z@skip\abovedisplayshortskip\z@skip}}
\eql@define@key{intertext}{short}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\belowdisplayskip\belowdisplayshortskip}%
    {\abovedisplayskip\abovedisplayshortskip}}
\eql@define@key{intertext}{long}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\belowdisplayshortskip\belowdisplayskip}%
    {\abovedisplayshortskip\abovedisplayskip}}
\eql@define@key{intertext}{medskip}[]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\belowdisplayskip\eql@belowdisplaymedskip@}%
    {\abovedisplayskip\eql@abovedisplaymedskip@}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{setup}{skip}{%
  \setlength\abovedisplayskip{#1}\belowdisplayskip\abovedisplayskip}
\eql@define@key{setup}{aboveskip}{%
  \setlength\abovedisplayskip{#1}}
\eql@define@key{setup}{belowskip}{%
  \setlength\belowdisplayskip{#1}}
\eql@define@key{setup}{aboveshortskip}{%
  \setlength\abovedisplayshortskip{#1}}
\eql@define@key{setup}{belowshortskip}{%
  \setlength\belowdisplayshortskip{#1}}
\eql@define@key{setup}{tagskip}{%
  \setlength\eql@abovedisplaytagskip@{#1}%
  \eql@belowdisplaytagskip@\eql@abovedisplaytagskip@}
\eql@define@key{setup}{abovetagskip}{%
  \setlength\eql@abovedisplaytagskip@{#1}}
\eql@define@key{setup}{belowtagskip}{%
  \setlength\eql@belowdisplaytagskip@{#1}}
\eql@define@key{setup}{medskip}{%
  \setlength\eql@abovedisplaymedskip@{#1}%
  \eql@belowdisplaymedskip@\eql@abovedisplaymedskip@}
\eql@define@key{setup}{abovemedskip}{%
  \setlength\eql@abovedisplaymedskip@{#1}}
\eql@define@key{setup}{abovetopskip}{%
  \setlength\eql@abovedisplaytopskip@{#1}}
\eql@define@key{setup}{aboveparskip}{%
  \setlength\eql@abovedisplayparskip@{#1}}
\eql@define@key{setup}{abovecontskip}{%
  \setlength\eql@abovedisplaycontskip@{#1}}
\eql@define@key{setup}{belowmedskip}{%
  \setlength\eql@belowdisplaymedskip@{#1}}
\eql@define@key{setup}{shortmode}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{off,never,no}{\eql@displayshortmode@\z@}},%
    {{above,neverbelow,notbelow,belowoff}{\eql@displayshortmode@\@ne}},%
    {{belowone,belowsingle}{\eql@displayshortmode@\tw@}},%
    {{belowall,always,on}{\eql@displayshortmode@\thr@@}}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Labels and Tag Declaration.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,subequations}
\eql@define@key\eql@keycat{label}{\eql@blocklabel@set{#1}}
\eql@define@key\eql@keycat{tag}{\eql@blocktag@set{#1}}
\eql@define@key\eql@keycat{tag*}{\eql@blocktag@setstar{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tag Spacing.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{tagmargin}{\setlength\eql@tagmargin@{#1}}
\eql@define@key\eql@keycat{tagmargin*}{\settowidth\eql@tagmargin@{#1}}
\eql@define@key\eql@keycat{mintagsep}{\setlength\eql@tagsepmin@{#1}}
\eql@define@key\eql@keycat{mintagwidth}{\setlength\eql@tagwidthmin@{#1}}
\eql@define@key\eql@keycat{mintagwidth*}{\settowidth\eql@tagwidthmin@{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tag Layout.}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{setup}{taglayout}{\eql@tag@setmake{#1}}
\eql@define@key{setup}{taglayout*}{\eql@tag@setmake@{#1}}
\eql@define@key{setup}{tagform}{\eql@tag@setform#1}
\eql@define@key{setup}{tagform*}{\eql@tag@setform@{#1}}
\eql@define@key{setup}{subeqtemplate}{\def\eql@subequations@template{#1}}
\eql@define@key{setup}{autolabel}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@autolabel}
\eql@define@key{setup}{autotag}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@autotag}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Equation Numbering.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{numberline,numline,n}[all]{%
  \eql@numbering@set{##1}}
\eql@define@key\eql@keycat{nonumber,nn,*}[]{\let\eql@numbering@active\eql@false}
\eql@define@key\eql@keycat{donumber,dn,!}[]{\let\eql@numbering@active\eql@true}
\eql@define@key\eql@keycat{number,num}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@numbering@active}
\eql@define@key\eql@keycat{tagsleft,leqno}[]{\let\eql@tagsleft\eql@true}
\eql@define@key\eql@keycat{tagsright,reqno}[]{\let\eql@tagsleft\eql@false}
\eql@define@key\eql@keycat{tags,eqno}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{right,r}{\let\eql@tagsleft\eql@false}},%
    {{left,l}{\let\eql@tagsleft\eql@true}}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Horizontal Layout.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{layout}{\eql@decide@select{#3}{#2}{#1}{%
  {{center,c}{\let\eql@flushleft\eql@false}},%
  {{left,l}{\let\eql@flushleft\eql@true}}}}
\eql@define@key\eql@keycat{center}[]{\let\eql@flushleft\eql@false}
\eql@define@key\eql@keycat{flushleft,left}[]{\let\eql@flushleft\eql@true}
\eql@define@key\eql@keycat{leftmargin}{%
  \setlength\eql@flushleftmargin@{#1}}
\eql@define@key\eql@keycat{minleftmargin}{%
  \setlength\eql@flushleftmarginmin@{#1}}
\eql@define@key\eql@keycat{maxleftmargin}{%
  \setlength\eql@flushleftmarginmax@{#1}}
\eql@define@key\eql@keycat{maxleftmargin*}[]{%
  \setlength\eql@flushleftmarginmax@{.5\maxdimen}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Horizontal Spacing and Columns.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{marginbadness}{\eql@marginbadness@#1\relax}
\eql@define@key\eql@keycat{maxbadness}{\eql@maxbadness@#1\relax}
\eql@define@key\eql@keycat{mincolsep}{\def\eql@colsepmin@val{#1}}
\eql@define@key\eql@keycat{maxcolsep}{\def\eql@colsepmax@val{#1}}
\eql@define@key\eql@keycat{maxcolsep*}[]{\def\eql@colsepmax@val{.5\maxdimen}}
\eql@define@key\eql@keycat{margins}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@align@margins}
\def\eql@keycat{equationsbox,setup}
\eql@define@key\eql@keycat{margin}{%
  \def\eql@box@marginleft{#1}\def\eql@box@marginright{#1}}
\eql@define@key\eql@keycat{marginleft}{\def\eql@box@marginleft{#1}}
\eql@define@key\eql@keycat{marginright}{\def\eql@box@marginright{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Horizontal Shape.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,equationsbox,setup}
\eql@define@key\eql@keycat{shape}[default]{\eql@shape@set{#1}}
\eql@define@key\eql@keycat{padding,pad}[\eql@indent@val]{%
  \let\eql@paddingmax\eql@false
  \def\eql@paddingleft@val{#1}\def\eql@paddingright@val{#1}}
\eql@define@key\eql@keycat{padleft}[\eql@indent@val]{%
  \let\eql@paddingmax\eql@false\def\eql@paddingleft@val{#1}}
\eql@define@key\eql@keycat{padright}[\eql@indent@val]{%
  \let\eql@paddingmax\eql@false\def\eql@paddingright@val{#1}}
\eql@define@key\eql@keycat{padmax}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@paddingmax}
\eql@define@key\eql@keycat{indent}[2em]{%
  \def\eql@indent@val{#1}}
\eql@define@key\eql@keycat{indent*}[2em]{%
  \def\eql@indent@val{#1}\def\eql@paddingleft@val{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Math Classes at Alignment.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,equationsbox,setup}
\eql@define@key\eql@keycat{classout}{\eql@class@innerleft@set{#1}}
\eql@define@key\eql@keycat{classin}{\eql@class@innerright@set{#1}}
\eql@define@key\eql@keycat{classin*}{\eql@class@innerlead@set{#1}}
\eql@define@key\eql@keycat{ampeq}[]{\eql@class@ampeq}
\eql@define@key\eql@keycat{eqamp}[]{\eql@class@eqamp}
\eql@define@key\eql@keycat{class}{\eql@decide@select{#3}{#2}{#1}{%
  {{ampeq,amprel,eqafter,beforerel}\eql@class@ampeq},%
  {{eqamp,relamp,eqbefore,afterrel}\eql@class@eqamp}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Punctuation.}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@punct@main\relax
\def\eql@keycat{equations,equationsbox,setup}
\eql@define@key\eql@keycat{punctsep}[\,]{\def\eql@punct@sep{#1}}
\eql@define@key\eql@keycat{punct}[.]{\def\eql@punct@main{#1}}
\eql@define@key\eql@keycat{punctline}[,]{\def\eql@punct@line{#1}}
\eql@define@key\eql@keycat{punctcol}[,]{\def\eql@punct@col{#1}}
\eql@define@key\eql@keycat{punct*}[]{\let\eql@punct@main\relax}
\eql@define@key\eql@keycat{punctline*}[]{\let\eql@punct@line\relax}
\eql@define@key\eql@keycat{punctcol*}[]{\let\eql@punct@col\relax}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Global Switches.}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@multi@linesfallback\eql@true
\let\eql@single@crerror\eql@true
\let\eql@ampproof@active\eql@true
\eql@define@key{setup}{linesfallback}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@multi@linesfallback}
\eql@define@key{setup}{ampproof}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@ampproof@active}
\eql@define@key{setup}{crerror}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@single@crerror}
\eql@define@key{equations,setup}{rescan}[true]{%
  \eql@decide@if{#3}{#2}{#1}%
    {\let\eql@scan@body\eql@scan@body@rescan}%
    {\let\eql@scan@body\eql@scan@body@dump}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Package Options.}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@provide@amsmath\eql@true
\let\eql@provide@equation\eql@true
\let\eql@provide@ang\eql@true
\let\eql@amsmath@dofixends\eql@true
\eql@define@key{setup}{equation}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@equation}
\eql@define@key{setup}{amsmath}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@amsmath}
\eql@define@key{setup}{amsmathends}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@amsmath@dofixends}
\eql@define@key{setup}{ang}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@ang}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Component Selection}
%
% \TODO describe
%    \begin{macrocode}
\newenvironment{eql@gathered}
  {\eqnaddopt{lines}\equationsbox}{\endequationsbox}
\newenvironment{eql@multlined}
  {\eqnaddopt{lines,padding,shape=steps}\equationsbox}{\endequationsbox}
\newenvironment{eql@aligned}
  {\eqnaddopt{align}\equationsbox}{\endequationsbox}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\newenvironment{eql@equation}
  {\eqnaddopt{equation}\equations}{\endequations}
\newenvironment{eql@gather}
  {\eqnaddopt{lines}\equations}{\endequations}
\newenvironment{eql@multline}
  {\eqnaddopt{lines,padmax,shape=steps,numberline=out}\equations}
  {\endequations}
\newenvironment{eql@align}
  {\eqnaddopt{align}\equations}{\endequations}
\newenvironment{eql@flalign}
  {\eqnaddopt{align,margins=false}\equations}{\endequations}
\newenvironment{eql@equation*}
  {\eqnaddopt{nonumber}\eql@equation}{\endequations}
\newenvironment{eql@gather*}
  {\eqnaddopt{nonumber}\eql@gather}{\endequations}
\newenvironment{eql@multline*}
  {\eqnaddopt{nonumber}\eql@multline}{\endequations}
\newenvironment{eql@align*}
  {\eqnaddopt{nonumber}\eql@align}{\endequations}
\newenvironment{eql@flalign*}
  {\eqnaddopt{nonumber}\eql@flalign}{\endequations}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@movecmd#1#2{%
  \expandafter\let\csname #1\expandafter\endcsname\csname #2\endcsname
}
\def\eql@provide@undefinecmd#1{%
  \expandafter\let\csname #1\endcsname\@undefined
}
\def\eql@provide@moveenv#1#2{%
  \expandafter\let\csname #1\expandafter\endcsname\csname #2\endcsname
  \expandafter\let\csname end#1\expandafter\endcsname\csname end#2\endcsname
}
\def\eql@provide@undefineenv#1{%
  \expandafter\let\csname #1\endcsname\@undefined
  \expandafter\let\csname end#1\endcsname\@undefined
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@onlyonce#1#2{%
  \def\eql@tmp{#2}%
  \def\@tempa{#1}%
  \ifx\eql@tmp\@tempa
    \let\eql@tmp\@undefined
  \fi
  \ifx\eql@tmp\@empty
    \let\eql@tmp\@undefined
  \fi
  \def\@tempa{*}%
  \ifx\eql@tmp\@tempa
    \def\eql@tmp{#1}%
  \fi
  \ifdefined\eql@tmp\else
    \ifcsname eql@provided@#1\endcsname
      \def\eql@tmp{#1}%
    \else
      \expandafter\let\csname eql@provided@#1\endcsname\eql@true
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@cmdonlyonce#1#2{%
  \def\eql@tmp{#2}%
  \edef\@tempb{\expandafter\noexpand\csname#1\endcsname}%
  \ifx\eql@tmp\@tempb
    \let\eql@tmp\@undefined
  \fi
  \ifx\eql@tmp\@empty
    \let\eql@tmp\@undefined
  \fi
  \def\@tempa{*}%
  \ifx\eql@tmp\@tempa
    \let\eql@tmp\@tempb
  \fi
  \ifdefined\eql@tmp
    \edef\eql@tmp{\expandafter\expandafter\expandafter\@gobble
      \expandafter\string\eql@tmp}%
  \else
    \ifcsname eql@provided@#1\endcsname
      \let\eql@tmp\@tempb
    \else
      \expandafter\let\csname eql@provided@#1\endcsname\eql@true
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@cmd#1#2{%
  \eql@provide@cmdonlyonce{#1}{#2}%
  \ifdefined\eql@tmp
    \expandafter\eql@provide@movecmd\expandafter{\eql@tmp}{eql@#1}%
  \else
    \eql@amsmath@after{%
      \eql@provide@movecmd{ams#1}{#1}%
      \eql@provide@movecmd{#1}{eql@#1}%
    }%
    \AddToHook{package/mathtools/after}{%
      \eql@provide@movecmd{#1}{eql@#1}%
    }%
    \eql@provide@movecmd{#1}{eql@#1}%
    \eql@amsmath@futurebefore{\eql@provide@undefinecmd{#1}}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@amsmath@endfix#1#2{%
  \long\edef\@tempa{\expandafter\noexpand\csname end#2\endcsname}%
  \long\edef\@tempb{\expandafter\noexpand\csname eql@amsmath@end#2\endcsname}%
  \expandafter\ifx\csname end#1\endcsname\@tempa
    \expandafter\let\csname end#1\endcsname\@tempb
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@amsmath@fixends{%
  \eql@amsmath@after{%
    \let\eql@amsmath@endmultline\endmultline
    \eql@amsmath@endfix{multline*}{multline}%
    \let\eql@amsmath@endgather\endgather
    \eql@amsmath@endfix{gather*}{gather}%
    \let\eql@amsmath@endalign\endalign
    \eql@amsmath@endfix{align*}{align}%
    \eql@amsmath@endfix{flalign}{align}%
    \eql@amsmath@endfix{flalign*}{align}%
    \eql@amsmath@endfix{alignat}{align}%
    \eql@amsmath@endfix{alignat*}{align}%
    \eql@amsmath@endfix{xalignat}{align}%
    \eql@amsmath@endfix{xalignat*}{align}%
    \eql@amsmath@endfix{xxalignat}{align}%
    \let\eql@amsmath@endaligned\endaligned
    \eql@amsmath@endfix{gathered}{aligned}%
    \eql@amsmath@endfix{alignedat}{aligned}%
  }
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@env#1#2{%
  \eql@provide@onlyonce{#1}{#2}%
  \ifdefined\eql@tmp
    \expandafter\eql@provide@moveenv\expandafter{\eql@tmp}{eql@#1}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{ams#1}{#1}%
      \eql@provide@moveenv{ams#1*}{#1*}%
      \eql@provide@moveenv{#1}{eql@#1}%
      \eql@provide@moveenv{#1*}{eql@#1*}%
    }%
    \AddToHook{package/mathtools/after}{%
      \eql@provide@moveenv{#1}{eql@#1}%
      \eql@provide@moveenv{#1*}{eql@#1*}%
    }%
    \eql@provide@moveenv{#1}{eql@#1}%
    \eql@provide@moveenv{#1*}{eql@#1*}%
    \eql@amsmath@futurebefore{\eql@provide@undefineenv{#1}}%
    \eql@amsmath@futurebefore{\eql@provide@undefineenv{#1*}}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@env@equation#1{%
  \eql@provide@onlyonce{equation}{#1}%
  \ifdefined\eql@tmp
    \expandafter\eql@provide@moveenv\expandafter{\eql@tmp}{eql@equation}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{amsequation}{equation}%
      \eql@provide@moveenv{amsequation*}{equation*}%
      \eql@provide@moveenv{equation}{eql@equation}%
      \eql@provide@moveenv{equation*}{eql@equation*}%
    }%
    \AddToHook{package/hyperref/after}{%
      \@ifpackageloaded{amsmath}{}{%
        \let\latexequation\H@equation
        \let\endlatexequation\H@endequation
        \eql@provide@moveenv{hyperrefequation}{equation}%
        \eql@provide@moveenv{equation}{eql@equation}%
      }%
    }%
    \@ifpackageloaded{amsmath}{}{\@ifpackageloaded{hyperref}{}{%
      \eql@provide@moveenv{latexequation}{equation}%
    }}%
    \eql@provide@moveenv{equation}{eql@equation}%
    \eql@provide@moveenv{equation*}{eql@equation*}%
    \eql@amsmath@futurebefore{\eql@provide@undefineenv{equation*}}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@env@multlined#1{%
  \eql@provide@onlyonce{multlined}{#1}%
  \ifdefined\eql@tmp
    \expandafter\eql@provide@moveenv\expandafter{\eql@tmp}{eql@multlined}%
  \else
    \AddToHook{package/mathtools/after}{%
      \eql@provide@moveenv{amsmultlined}{multlined}%
      \eql@provide@moveenv{multlined}{eql@multlined}%
    }%
    \eql@provide@moveenv{multlined}{eql@multlined}%
    \@ifpackageloaded{mathtools}{}{\AddToHook{package/mathtools/before}{%
      \eql@provide@undefineenv{multlined}}}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@env@subequations@reinstall{%
  \global\let\subequations\eql@subequations
  \let\@tempa\UseHook
  \let\@tempb\UseHookWithArguments
  \def\UseHook{\let\UseHook\@tempa\let\UseHookWithArguments\@tempb%
    \expandafter\subequations\@gobble}%
  \def\UseHookWithArguments{\expandafter\UseHook\@gobble}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@env@subequations#1{%
  \eql@provide@onlyonce{subequations}{#1}%
  \ifdefined\eql@tmp
    \expandafter\eql@provide@moveenv
      \expandafter{\eql@tmp}{eql@subequations}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{amssubequations}{subequations}%
      \eql@provide@moveenv{subequations}{eql@subequations}%
      \let\subequations\eql@provide@env@subequations@reinstall
    }%
    \AddToHook{package/hyperref/after}{%
      \AddToHook{cmd/subequations/before}[hyperref]{}%
      \AddToHook{cmd/subequations/after}[hyperref]{}%
      \RemoveFromHook{cmd/subequations/before}[hyperref]%
      \RemoveFromHook{cmd/subequations/after}[hyperref]%
      \AddToHook{cmd/amssubequations/before}%
      {%
        \stepcounter{equation}%
        \protected@edef\theHparentequation{\theHequation}%
        \addtocounter{equation}{-1}%
      }
      \AddToHook{cmd/amssubequations/after}%
      {%
        \def\theHequation{\theHparentequation\alph{equation}}%
        \ignorespaces
      }
    }
    \eql@provide@moveenv{subequations}{eql@subequations}%
    \AddToHook{cmd/subequations/after}{}%
    \let\subequations\eql@provide@env@subequations@reinstall
    \eql@amsmath@futurebefore{\eql@provide@undefineenv{subequations}}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@sqr{%
  \let\[\eql@equations@sqr@open
  \let\]\eql@equations@sqr@close
  \eql@amsmath@after{%
    \let\[\eql@equations@sqr@open
    \let\]\eql@equations@sqr@close
  }%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@ang{%
  \let\<\eql@equations@ang@open
  \let\>\eql@equations@ang@close
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{provide}{equation}[]{\eql@provide@env@equation{#1}}
\eql@define@key{provide}{gather}[]{\eql@provide@env{gather}{#1}}
\eql@define@key{provide}{multline}[]{\eql@provide@env{multline}{#1}}
\eql@define@key{provide}{align}[]{\eql@provide@env{align}{#1}}
\eql@define@key{provide}{flalign}[]{\eql@provide@env{flalign}{#1}}
\eql@define@key{provide}{aligned}[]{\eql@provide@env{aligned}{#1}}
\eql@define@key{provide}{gathered}[]{\eql@provide@env{gathered}{#1}}
\eql@define@key{provide}{multlined}[]{\eql@provide@env@multlined{#1}}
\eql@define@key{provide}{subequations}[]{\eql@provide@env@subequations{#1}}
\eql@define@key{provide}{sqr}[]{\eql@provide@sqr}
\eql@define@key{provide}{ang}[]{\eql@provide@ang}
\eql@define@key{provide}{eqref}[]{\eql@provide@cmd{eqref}{#1}}
\eql@define@key{provide}{notag}[]{\eql@provide@cmd{notag}{#1}}
\eql@define@key{provide}{thetag}[]{\eql@provide@cmd{thetag}{#1}}
\eql@define@key{provide}{allowdisplaybreaks}[]{%
  \eql@provide@cmd{allowdisplaybreaks}{#1}}
\eql@define@key{provide}{numberwithin}[]{\eql@provide@cmd{numberwithin}{#1}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\newcommand{\eqnlinesprovide}[1]{%
%<dev>\eql@dev@start\eqnlinesprovide
  \eql@setkeys{provide}{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Global and Package Options}
%
% Handle global and package options:
%
%   \macro{\eqnlinesset}
% The macro |\eqnlinesset| processes global configuration options
% including the package options:
%    \begin{macrocode}
\newcommand{\eqnlinesset}[1]{%
%<dev>\eql@dev@start\eqnlinesset
  \eql@setkeys{setup}{#1}}
%    \end{macrocode}
%
% Disable error message for exclusive package options:
%    \begin{macrocode}
\let\eql@error@packageoption\@gobble
%    \end{macrocode}
%
% Pass undeclared options on to \ctanpkg{keyval} processing:
%    \begin{macrocode}
\DeclareOption*{\expandafter\eqnlinesset\expandafter{\CurrentOption}}
%    \end{macrocode}
%
% Process package options:
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%   \macro{\eql@error@packageoption}
% Enable error message for explusive package options:
%    \begin{macrocode}
\def\eql@error@packageoption#1{%
  \eql@error{may only use `#1' as a package option}%
}
%    \end{macrocode}
%
% Provide classes of interfaces:
%    \begin{macrocode}
\ifcsname tagsleft@true\endcsname\else
  \expandafter\newif\csname iftagsleft@\endcsname
\fi
\ifcsname @fleqntrue\endcsname\else
  \expandafter\newif\csname if@fleqn\endcsname
\fi
\ifdefined\eql@provide@amsmath
  \let\eql@provide@equation\eql@true
  \eql@amsmath@after{%
    \iftagsleft@
      \eqnlinesset{tagsleft}
    \else
      \eqnlinesset{tagsright}
    \fi
    \if@fleqn
      \eqnlinesset{left}
    \else
      \eqnlinesset{center}
    \fi
  }
\fi
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\ifdefined\eql@provide@equation
  \eqnlinesprovide{equation,sqr}
\fi
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\ifdefined\eql@amsmath@dofixends
  \eql@amsmath@fixends
\fi
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\ifdefined\eql@provide@amsmath
  \eqnlinesprovide{%
    multline,gather,align,flalign,%
    multlined,gathered,aligned,%
    subequations,eqref}
\fi
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\ifdefined\eql@provide@ang
  \eqnlinesprovide{ang}
\fi
%    \end{macrocode}
%
%\iffalse
%</package>
%\fi
%
\endinput
