%
% \iffalse meta-comment
%
% eqnlines.dtx Copyright (C) 2024-2026 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.3
% 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,
% eqnlines.tex, eqnlines.pdf, eqnlines-src.tex, eqnlines-src.pdf.
%
%<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<package>\ProvidesPackage{eqnlines}[2026/01/28 v0.14 Single- and multi-line equations]
%<source>\ProvidesFile{eqnlines-src.tex}[2026/01/28 v0.14 eqnlines source code documentation]
%<manual>\ProvidesFile{eqnlines.tex}[2026/01/28 v0.14 eqnlines reference manual]
%<*main|manual|source>
\def\thedate/{2026/01/28}\def\theversion/{v0.14}
\def\thecopyright/{2024\texorpdfstring{--}{-}2026 Niklas Beisert}
%<*main>
\ProvidesFile{eqnlines.dtx}[\thedate/ \theversion/ eqnlines package main file]
%</main>
\PassOptionsToClass{10pt,a4paper}{article}
\documentclass{ltxdoc}

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

%<*main>
\title{The \markpkg{eqnlines} Package}
\hypersetup{pdftitle={The eqnlines Package}}
\hypersetup{pdfsubject={Documentation for the LaTeX2e Package eqnlines}}
%</main>
%<manual>\title{The \markpkg{eqnlines} Package\\Reference Manual}
%<manual>\hypersetup{pdftitle={The eqnlines Package -- Reference Manual}}
%<manual>\hypersetup{pdfsubject={Reference Manual for the LaTeX2e Package eqnlines}}
%<source>\title{The \markpkg{eqnlines} Package\\Source Code Documentation}
%<source>\hypersetup{pdftitle={The eqnlines Package -- Source Code Documentation}}
%<source>\hypersetup{pdfsubject={Documented Source for the LaTeX2e Package eqnlines}}
\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}}
\date{\thedate/, \theversion/\\[1ex]
\url{https://ctan.org/pkg/eqnlines}\\[0.5ex]
\url{https://github.com/nbeisert/latex-pkg-nb}}

\hypersetup{pdflang={en-UK}}
\hypersetup{pdfurl={https://ctan.org/pkg/eqnlines}}
\hypersetup{pdfcopyright={Copyright \thecopyright/.
  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/}}

\hypersetup{keeppdfinfo=true}
\hypersetup{pdfsource={}}
\AddToHook{begindocument/before}{\hypersetup{colorlinks=false}}
\hypersetup{urlbordercolor={.5 1 1}}
\hypersetup{linkbordercolor={1 .7 .7}}
\AddToHook{begindocument/before}{\hypersetup{pdfstartview=FitH}}

\parskip1ex
\parindent0pt
\edef\itemize{\unexpanded\expandafter{\itemize}\parskip0pt}

\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}}}

\def\verbbar{\texttt{\char"7C}}

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

\def\tex/{\TeX}
\def\latex/{\LaTeX}
\def\amsmath/{\ctanpkg{amsmath}}

\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}

\usepackage{verbatim}
\makeatletter
\def\example@addline#1{%
  \g@addto@macro\example@dbuf{#1 }%
  \g@addto@macro\example@pbuf{\item|#1|}}
\def\scanexample{%
  \gdef\example@dbuf{}%
  \gdef\example@pbuf{}%
  \begingroup
  \@bsphack
  \let\do\@makeother\dospecials
  \catcode`\^^M\active
  \def\verbatim@processline{\expandafter\example@addline\expandafter%
    {\the\verbatim@line}}%
  \verbatim@start}
\def\endscanexample{\@esphack\endgroup\ignorespacesafterend}
\def\printexample{\begingroup
  \topsep\z@skip\parsep\z@skip\itemsep\z@skip\partopsep\z@skip\parskip\z@skip
  \trivlist
  \expandafter\scantokens\expandafter{\example@pbuf}%
  \endtrivlist
  \endgroup}
\def\doexample{\expandafter\scantokens\expandafter{\example@dbuf}}
\newcommand{\showexampleh}[1][0.5]{\par%
  \parbox{\dimexpr#1\textwidth\relax}{\printexample}%
  \parbox{\dimexpr\textwidth-#1\textwidth\relax}{\doexample}%
  \par\medskip\ignorespaces}
\newcommand{\showexamplev}{%
  \printexample
  \par\medskip
  \parbox{\textwidth}{\doexample}%
  \par\medskip\ignorespaces}
\newenvironment{example}
  {\parskip\z@skip\par\medskip\hrule\medskip}
  {\par\hrule\par\medskip}
\makeatother

\usepackage{eqnlines}
\eqnlinesset{belowtopmode=top,belowtopskip=0pt}
\def\pstrut{\vphantom{(}}
\def\bstrut{\vphantom{b}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

\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}

\begingroup
\parskip0ex
\tableofcontents
\endgroup


%<*main|manual>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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-line equations
with alignment. Some of its deficiencies were addressed by
the multi-line equation environments of the package \amsmath/
which have become an established standard for these purposes.

The package \ctanpkg{eqnlines} builds upon and extends
the functionality of the \latex/ and \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 \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 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 \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 original \LaTeXe{} code
without using the \markpkg{expl3} layer.
\end{itemize}

The package represents a stand-alone implementation
of an equations environment
which is largely compatible with the established \latex/ and \amsmath/
environments |equation|, |multline|, |gather|, |align|
and their variants.
Hence, the package can be used instead of \amsmath/
with no or minor modifications to the \latex/ sources for
single- and multi-line equations.
It can also be used alongside \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 \amsmath/
are either replaced or left in place while the \ctanpkg{eqnlines}
environments can be accessed using the alternate name |equations|.


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

% \TODO notice regarding development
\textbf{Notice regarding package version \theversion/:}
Please note that this package is still in a development and testing stage.
The present version serves as a release candidate for v1.0.
Please report any malfunction that you may notice.

\medskip

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

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Options.}

\DescribeEnv{equations}
The environment |equations|
accepts a comma-separated list of optional parameters
`|[|\textit{opts}|]|':
%
\begin{center}
\begin{tabular}{l}
|\begin{equations}|\textit{mod}|[|\textit{opts}|]|%
  \textit{mod}\texttt{\textvisiblespace}
\\
\ldots
\\
|\end{equations}|\texttt{\textvisiblespace}
\end{tabular}
\end{center}
%
Furthermore, the environment accepts modifiers \textit{mod}
(like the star modifier `|*|' for many other \latex/ macros)
acting as shortcuts for some options to be explained further below.
They can be specified in any order.

We note that the |equations| environment should be started with a whitespace
character `\texttt{\textvisiblespace}'
which provides a clear separation
from optional arguments `|[|\textit{opts}|]|'
and/or modifiers which must immediately follow
the environment declaration |\begin{equations}|
without whitespaces.
Any character without a proper meaning will also start the equation content,
however, future versions of the package may extend the syntax of modifiers,
and thus a separation by whitespace is advertised
(misplaced modifiers produce warning messages).
Similarly, |\end{equations}| allows trailing modifiers
and it should be followed by a whitespace
to avoid undesired effects or warnings.

\DescribeInterfaceMacro{\eqnlinesset}
Most options, but not all, can be set permanently by the macro:
%
\begin{center}
|\eqnlinesset{|\textit{opts}|}|
\end{center}
%
\DescribeInterfaceMacro{\eqnaddopt}
Options for the following equations block are set by the macro:
%
\begin{center}
|\eqnaddopt{|\textit{opts}|}|
\end{center}
%
\DescribeInterfaceMacro{\eqncontrol}
Several options can be controlled
for individual lines or cells within the equations block by the macro:
%
\begin{center}
|\eqncontrol{|\textit{opts}|}|
\end{center}
%
The |\eqncontrol| interface also provides several features
for which no other macro definitions exist.
Shortcuts to frequently used features could be installed by
user definitions such as:
%
\begin{center}
|\newcommand{\|\textit{shortcut}|}[1]{\eqncontrol{|\textit{key}|={#1}}}|
\end{center}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Modes of Operation.}

The package supplies a main maths environment called |equations|
which has three principal modes of operation.
It can display a single-line equation
just as the \latex/ environment |equation| or
the symbolic shortcut |\[|\,\ldots|\]|:
%
\[
\framebox[8cm]{\pstrut single line}
\]
%
It can display a stack of equations
analogous to the \amsmath/ environments |gather| and |multline|:
\unskip\footnote{Arguably, a single-line equation is
just a stack of equations of height 1.
Nevertheless, there is a single-line mode
which prohibits line breaks and which works slightly more efficiently:
For example, the multi-line modes will process the input
twice which is not needed for the single-line mode.
Apart from that, the package takes care that the layout and spacing
of single-line equations and multi-line equations consisting of a single line
is the same.}
%
\<=[pad]
\framebox[4cm]{\pstrut stacked line 1}
\\
\framebox[7cm]{\pstrut stacked line 2}
\\
\framebox[5cm]{\pstrut stacked line 3}
\\
\shoveright\framebox[5cm]{\pstrut stacked line 4}
\>
%
It can also display one or several columns of aligned equations
analogous to the \amsmath/ environment family |align|:
%
\<
\framebox[1.0cm]{\pstrut 1a-L}\hskip-0.5pt&\framebox[3.0cm]{\pstrut 1a-R}
&
\framebox[1.5cm]{\pstrut 1b-L}\hskip-0.5pt&\framebox[3.5cm]{\pstrut 1b-R}
\\
\framebox[2.5cm]{\pstrut 2a-L}\hskip-0.5pt&\framebox[4.5cm]{\pstrut 2a-R}
&
&\framebox[2cm]{\pstrut 2b-R}
\\
&\framebox[4cm]{\pstrut 3a-R}
\>
%

\DescribeKey{single}
\DescribeKey{lines}
\DescribeKey{columns}
The three modes of operation
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
           & |\<=|\textvisiblespace\,\ldots|\>|\textvisiblespace
           & |\<|\textvisiblespace\,\ldots|\>|\textvisiblespace \\
\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).

\begin{example}
\begin{scanexample}
\begin{equations}[single]
x=\cos\phi
\end{equations}
\end{scanexample}
\showexampleh
\begin{scanexample}
\begin{equations}[lines]
x=\cos\phi \\ \phi=\arccos x
\end{equations}
\end{scanexample}
\showexampleh
\begin{scanexample}
\begin{equations}[columns]
x&=\cos\phi & \phi&=\arccos x \\
 &=(z+z^{-1})/2 & &=-i\log z
\end{equations}
\end{scanexample}
\showexampleh
\end{example}

\DescribeInterfaceMacro{\\}
\DescribeInterfaceMacro{&}
As usual, lines are separated by `|\\|' and columns by `|&|'.
Note that `|\\|' admits some optional parameters:
%
\begin{center}
|\\|[|~|][|*|]|[|\textit{skip}|]|
\end{center}
%
The combination |[|\textit{skip}|]| introduces
additional glue between the lines;
the modifier `|*|' inhibits a page break,
and `|~|' indicates a continued equation
which suppresses punctuation (see \secref{sec:punctuation})
and defers numbering (see \secref{sec:numbering}).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Alternative Forms.}

\DescribeInterfaceMacro{\[...\string\]}
\DescribeInterfaceMacro{\<...\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.
\DescribeKey{=}
\DescribeKey{-}
\DescribeKey{\verbbar}
An additional equal sign `|=|' in |\<=|\textvisiblespace\,\ldots|\>|
serves as a modifier character
which acts as a short form for the optional argument |lines|
selecting the lines mode.
Similarly, the modifiers minus `|-|' and bar `\verbbar'
select single-line and columns mode, respectively.
\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}.

\begin{example}
\begin{scanexample}
\[
x=\cos\phi
\]
\end{scanexample}
\showexampleh
\begin{scanexample}
\<=
x=\cos\phi \\ \phi=\arccos x
\>
\end{scanexample}
\showexampleh
\begin{scanexample}
\<
x&=\cos\phi & \phi&=\arccos x \\
 &=(z+z^{-1})/2 & &=-i\log z
\>
\end{scanexample}
\showexampleh
\begin{scanexample}
\eqnlinesset{sqropt={donumber}}
\[ x=\cos\phi \]
\end{scanexample}
\showexampleh
\end{example}

\DescribeEnv{equation}
\DescribeEnv{gather}
\DescribeEnv{multline}
\DescribeEnv{align}
The package also supplies or overwrites the \amsmath/
environments |equation|, |gather|, |multline|, |align| and |flalign|
including their starred -|at| variants
(but not the |split| construction).
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}

\begin{example}
\begin{scanexample}
\begin{equation}
x=\cos\phi
\end{equation}
\end{scanexample}
\showexampleh
\begin{scanexample}
\begin{gather}
x=\cos\phi \\ \phi=\arccos x
\end{gather}
\end{scanexample}
\showexampleh
\begin{scanexample}
\begin{align}
x&=\cos\phi & \phi&=\arccos x \\
 &=(z+z^{-1})/2 & &=-i\log z
\end{align}
\end{scanexample}
\showexampleh
\begin{scanexample}
\newenvironment{eqnlist}
  {\eqnaddopt{lines,shape=left}\equations}
  {\endequations}
\begin{eqnlist}[nonumber]
x=\cos\phi \\ \phi=\arccos x
\end{eqnlist}
\end{scanexample}
\showexampleh[0.65]
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Transposition.}

\DescribeKey{transpose}
\DescribeKey{/}
When the aligned mode is used to produce more than one column of equations,
the default line-by-line ordering of the content may be inconvenient.
The package offers a transposition mode |transpose=plain| in which the content
is specified on a column-by-column basis. Columns are separated by `|\&|'
(the character `\&' must be escaped as `|{\&}|' in this mode)
and the lines within each column are broken by `|\\|' as usual.
The continued transposition mode |transpose=cont|
(abbreviated by the modifier `|/|')
furthermore reduces the input by assuming that all secondary
alignment markers `|&|' indicate a continued equation
and imply a line break with an empty left equation cell.
Note that the transposition is implemented by reprocessing the input,
which imposes some restrictions:
all line and column breaks `|\\|', `|\&|' must be explicit
(must not be produced by macro expansion),
line breaks should not use optional arguments
(they only work on the first column),
and each section separated by `|\&|'
should describe only a single column
with one alignment marker per line (unless in continued transposition mode).
Furthermore, the continued mode processes the alignment marker `|&|',
which may cause issues when nesting aligned content.

\begin{example}
\begin{scanexample}
\<[transpose=plain]
x &= \cos\phi \\ &= (z+z^{-1})/2
\&
\phi &= \arccos x \\ &= -i\log z
\>
\end{scanexample}
\showexampleh

\begin{scanexample}
\<[transpose=cont]
x &= \cos\phi &= (z+z^{-1})/2
\&
\phi &= \arccos x &= -i\log z
\>
\end{scanexample}
\showexampleh
\end{example}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Numbering Schemes.}

\DescribeKey{numberline}
\DescribeKey{n}
The package extends the established interface of \latex/
and the \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} (alternatively |nline| or just |n|)
as follows:
%
\begin{center}
\begin{tabular}{llll}
name     & alt. & description & preset \\
\hline
|all|    & |a|  & individual & all lines \\
|sub|    & |s|  & lines & subequations (a,\,b,\,c,\,\ldots) \\
\hline
|first|  & |f|  & & first line \\
|last|   & |l|  & & last line \\
|out|    & |o|  & & last/first line for right/left tags \\
|in|     & |i|  & single line & first/last line for right/left tags  \\
|middle| & |m*| & & middle line (rounded down/up for right/left tags) \\
|here|   & |h|  & & line indicated by |\numberhere| \\
|best|   & |+|  & & line with most available space \\
\hline
|top|      & |t|  & & at top \\
|bottom|   & |b|  & & at bottom \\
|center|   & |c|  & between & at vertical centre (single line at baseline) \\
|center!|  & |c!| & lines & at vertical centre (also single line) \\
|median|   & |m|  & & middle line (at baseline or between lines) \\
|center*|  & |c*| & & tag baseline centred between outer baselines \\
\hline
|multi|  & |@| & & individual lines, numbering on \\
|none|   & |-| & mode switch & individual lines, numbering off \\
|single| & |1| & & previous single-line mode, numbering on \\
\hline
|on|     & |!| & activation & turn numbering on \\
|off|    & |*| & & turn numbering off \\
\end{tabular}
\end{center}

\begin{example}
\eqnlinesset{evadetag=false}
\begin{scanexample}
\begin{equations}[!,numberline=...]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{scanexample}
\qquad\parbox{0.8\textwidth}{\printexample}
\par\medskip
\makebox[0.33\textwidth]{|all|:}\hfil
\makebox[0.33\textwidth]{|sub|:}\hfil
\makebox[0.33\textwidth]{|best|:}\par\nobreak\smallskip
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=all]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=sub]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=best]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{minipage}
\par\medskip
\makebox[0.33\textwidth]{|first|:}\hfil
\makebox[0.33\textwidth]{|last|:}\hfil
\makebox[0.33\textwidth]{|middle|:}\par\nobreak\smallskip
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=first]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=last]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=middle]
  x  &= \cos\phi  \\ &= (z+z^{-1})/2 \\
\phi &= \arccos x \\ &= -i\log z
\end{equations}
\end{minipage}
\par\medskip
\makebox[0.33\textwidth]{|top|:}\hfil
\makebox[0.33\textwidth]{|bottom|:}\hfil
\makebox[0.33\textwidth]{|center!|:}\par\nobreak\smallskip
\begin{minipage}{0.33\textwidth}
\[![numberline=top]
1+\frac{1}{\displaystyle 1+\frac{1}{\displaystyle 1+\ldots}}
\]
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\[![numberline=bottom]
1+\frac{1}{\displaystyle 1+\frac{1}{\displaystyle 1+\ldots}}
\]
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\[![numberline=center!]
1+\frac{1}{\displaystyle 1+\frac{1}{\displaystyle 1+\ldots}}
\]
\end{minipage}
\par\medskip
\makebox[0.33\textwidth]{|median|:}\hfil
\makebox[0.33\textwidth]{|center*|:}\hfil
\makebox[0.33\textwidth]{|center|:}\par\nobreak\smallskip
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=median]
 x &= -\int \sin\phi\,\mathrm{d}\phi \\
   &= \cos\phi
\end{equations}
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=center*]
 x &= -\int \sin\phi\,\mathrm{d}\phi \\
   &= \cos\phi
\end{equations}
\end{minipage}\vrule\hfil
\begin{minipage}{0.33\textwidth}
\begin{equations}[!,numberline=center]
 x &= -\int \sin\phi\,\mathrm{d}\phi \\
   &= \cos\phi
\end{equations}
\end{minipage}
\end{example}

\DescribeKey{evadetag}
Note that the mode |best| (line with most available space)
is activated automatically if the (single) tagged line
does not have sufficient space to hold the tag.
This feature can be controlled by the setting
|evadetag=|\textit{bool}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Activation and Selection.}

\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{nonumber}
\DescribeKey{donumber}
\DescribeKey{number}
\DescribeKey{nn,*}
\DescribeKey{dn,!}
The numbering can be disabled or enabled for the block
by the keys |nonumber| or |donumber| (|nn|=`|*|' or |dn|=`|!|' for short)
or by |number=|\textit{bool} with \textit{bool}
either |on| or |off| (among several alternative forms).
Alternatively the number can be switched by using modifiers:
%
\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.)
and there is no need to adjust the closing statement.

\DescribeInterfaceMacro{\numberhere}
\DescribeInterfaceMacro{\numbernext}
\DescribeInterfaceMacro{\\\string~}
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.
For example, if an equation is broken into several lines
one may use the combination |\numbernext \\|
to assign the number to the last line.
Note that the modified newline `|\\~|' combines
|\numbernext| and |\\|

\begin{example}
\begin{scanexample}
\begin{equations}
   x &= \cos\phi \nonumber \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \nonumber \\
     &= -i\log z
\end{equations}
\end{scanexample}
\showexampleh
\begin{scanexample}
\begin{equations}*
   x &= \cos\phi \donumber \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \donumber \\
     &= -i\log z
\end{equations}
\end{scanexample}
\showexampleh
\begin{scanexample}
\eqnlinesset{numberline=last}
\<! x &= \cos\phi \\
 \phi &= \arccos x \>
\end{scanexample}
\showexampleh
\begin{scanexample}
\eqnlinesset{angopt=donumber}
\<* x &= \cos\phi \\
 \phi &= \arccos x \>
\end{scanexample}
\showexampleh
\begin{scanexample}
\begin{equations}
   x &= \cos\phi \numbernext \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \numbernext \\
     &= -i\log z
\end{equations}
\end{scanexample}
\showexampleh
\begin{scanexample}
\eqnlinesset{numberline=here}
\<!
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \numberhere \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh
\begin{scanexample}
\eqnlinesset{numberline=first}
\<!
   x &= \cos\phi \numbernext \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \numbernext \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Labels and Tags.}

\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{name}|]{|\textit{label}|}|
\qquad and \qquad
|\tag|[|*|]|[|\textit{ref}|]{|\textit{tag}|}|
\end{center}
%
The optional parameter \textit{name} for |\label| assigns
a name to the label which can be referenced by |\nameref|.
A |\tag| replaces the equation number,
|\tag*| will drop the decoration by parentheses.
The optional parameter \textit{ref} for |\tag|
defines the representation of references by |\ref|.

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/tagging
for the present line or block via |\donumber|, see below.
By default, numbering/tagging is triggered for |\tag|,
but not for |\label| reflecting the behaviour set forth by \amsmath/.
By enabling triggering for |\label|, numbers will be produced
only if they have a chance of being referenced.

\DescribeKey{label}
\DescribeKey{tag}
\DescribeKey{labelname}
\DescribeKey{taglabel}
The |equations| environment provides an alternative means
to specify labels and tags within the optional arguments |[|\textit{opts}|]|
%
\begin{center}
|label={|\textit{label}|}|,
\qquad
|tag|[|*|]|={|\textit{tag}|}|,
\qquad
|labelname={|\textit{name}|}|,
\qquad
|taglabel={|\textit{ref}|}|,
\end{center}
%
\DescribeKey{@}
or via the modifier |@{|\textit{label}|}|:
%
\begin{center}
|\[@{|\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.

The above macros may also be used via the keys
|label|, |labelname|, |tag| and |taglabel|
of the interface |\eqncontrol|.

\DescribeInterfaceMacro{\eqref}
The macro |\eqref| is the standard method for referring
to equation numbers via their label.
This method also uses the layout defined below.
%
\begin{center}
|\eqref{|\textit{label}|}|.
\end{center}
%
\DescribeInterfaceMacro{\tagform}
\DescribeInterfaceMacro{\tagbox}
\DescribeInterfaceMacro{\tagboxed}
For custom typesetting,
|\tagform| encloses a number/tag with decoration,
|\tagbox| puts the decorated number in a box
and |\tagboxed| combines the two.

\DescribeKey{tagbox}
\DescribeKey{tagform}
The typesetting of equation numbers and tags passes through two macros,
one which defines the layout
and another one which adds a decoration by parentheses.
These two methods can be adjusted via the options:
%
\begin{center}
|tagbox|[|*|]|={|\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 parentheses for the tag presentation.

The above setting may also be changed for individual lines
by the corresponding keys of the interface |\eqncontrol|.

\begin{example}
\begin{scanexample}
\eqnlinesset{tagform=[{#1}]}
\eqnlinesset{tagbox={\textcolor{blue}{#1}}}
\<[!,numberline=last]
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh[0.6]
\end{example}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Overall Layout.}

\DescribeKey{layout}
\DescribeKey{center}
\DescribeKey{left}
First of all, the overall layout can be adjusted
between central and left alignment
via |layout=center|, |layout=left| or |center|, |left| for short.

\begin{example}
\begin{scanexample}
\<[layout=center]
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh[0.35]
\begin{scanexample}
\<[layout=left]
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh[0.35]
\end{example}

\DescribeKey{tags}
\DescribeKey{tagsright}
\DescribeKey{tagsleft}
Furthermore, numbers and/or tags may be placed
on the right or left margin
via |tags=right|, |tags=left| or |tagsright|, |tagsleft| for short.

\begin{example}
\begin{scanexample}
\<[tags=right]!
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh
\begin{scanexample}
\<[tags=left]!
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Margins.}

\DescribeKey{margin}
\DescribeKey{marginleft}
\DescribeKey{marginright}
\DescribeKey{linewidth}
For both layout choices,
the margins and line width of an equation block can be adjusted
by |margin|, |marginleft|, |marginright| or |linewidth|.
The equations and corresponding numbers or tags will be fit
within these bounds. This feature can be used within
lists or enumerations to undo an indentation.

\begin{example}
\def\indicate#1{%
  \framebox[\dimexpr\displaywidth-2\fboxsep-2\fboxrule\relax]{\mbox{#1}}}
\begin{scanexample}
\[ \indicate{line width} \]
\end{scanexample}
\showexampleh[0.5]
\begin{scanexample}
\[[margin=2em] \indicate{reduced} \]
\end{scanexample}
\showexampleh[0.5]
\begin{scanexample}
\begin{itemize}
\item first level
  \[ \indicate{default width} \]
  \[[marginleft=0pt]
    \indicate{full width} \]
\end{itemize}
\end{scanexample}
\showexampleh[0.5]
\end{example}

\DescribeKey{tagmargin}
\DescribeKey{tagmargin*}
\DescribeKey{tagmarginratio}
In central alignment layout, one can impose a tag margin
|tagmargin={|\textit{dimen}|}|
which allocates some space to the tag
such that equation content is centred in the remaining horizontal space.
The margin can also be set to the width of some text by
|tagmargin*={|\textit{text}|}| or it can be calculated
as the maximum width of tags by |tagmargin| without parameter (default).
The option |tagmarginratio={|\textit{ratio}|}|
uses the tag margin only for equation blocks
with a ratio of tags to rows above the given (decimal) ratio
(a value above 1 uses the tag margin only for single equations with tags;
default is |0.334|).
The option |tagmarginthreshold={|\textit{threshold}|}|
uses the tag margin only if the ratio of spacings would be below
the given (decimal) threshold (very much off balance;
default is |0.5|).
The latter two options together with some tag margin
can produce a more appealing layout for equation blocks of mixed filling.
In the following example, the former two equations are centred
on all horizontal space
while the latter two equations are centred on the space left of the tag
(the ratio of spacings without tag margin would be very small here):

\begin{example}
\begin{scanexample}
\eqnlinesset{tagmarginthreshold=0.7}
\[! \framebox[4em]{} \]
\[! \framebox[8em]{} \]
\[! \framebox[12em]{} \]
\[! \framebox[16em]{} \]
\end{scanexample}
\showexampleh
\end{example}

\DescribeKey{leftmargin}
\DescribeKey{leftmargin*}
\DescribeKey{minleftmargin}
\DescribeKey{maxleftmargin}
In left alignment layout, all equations are left aligned to a left margin
(|leftmargin| is initialised
to the first level of enumerations and itemisations).
It can be set to the width of some text by |leftmargin*={|\textit{text}|}|.
Depending on the situation, the left margin may be
reduced or extended to |minleftmargin| or |maxleftmargin|, respectively.

\begin{example}
\eqnlinesset{layout=left}
\begin{scanexample}
\eqnlinesset{layout=left}
\<
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh[0.35]
\begin{scanexample}
\<[tags=left,!]
   x &= \cos\phi \\
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\
     &= -i\log z
\>
\end{scanexample}
\showexampleh[0.35]
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Column Separation.}

\DescribeKey{fulllength}
\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
is treated on equal footing to the space between the columns
(option |fulllength=off|; default),
but it can be eliminated so that the outer columns
are pushed right to the margin (option |fulllength=on|).
A minimum and maximum column separation can be specified
via |mincolsep=|\textit{dimen} and |maxcolsep=|\textit{dimen}
(defaults are |2em| and |1em|)
or the maximum column separation can be disabled by |maxcolsep=off|
(which is implied by |fulllength=on|).

\begin{example}
\begin{scanexample}
\<[maxcolsep=2em]
 x &= \cos\phi     & \phi &= \arccos x \\
   &= (z+z^{-1})/2 &      &= -i\log z \>
\end{scanexample}
\showexamplev
\begin{scanexample}
\<[maxcolsep=off]
 x &= \cos\phi     & \phi &= \arccos x \\
   &= (z+z^{-1})/2 &      &= -i\log z \>
\end{scanexample}
\showexamplev
\begin{scanexample}
\<[fulllength]
 x &= \cos\phi     & \phi &= \arccos x \\
   &= (z+z^{-1})/2 &      &= -i\log z \>
\end{scanexample}
\showexamplev
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Alignment Schemes and Control.}

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 replacement \amsmath/
environment |multline|.

\begin{example}
\eqnlinesset{pad=2em}
\begin{scanexample}
\eqnlinesset{pad=2em}
\<=[shape=...] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{scanexample}
\qquad\parbox{0.8\textwidth}{\printexample}
\par\medskip
\makebox[0.33\textwidth]{|left|:}\hfil
\makebox[0.33\textwidth]{|center|:}\hfil
\makebox[0.33\textwidth]{|right|:}\par\nobreak\smallskip
\begin{minipage}{0.33\textwidth}
\<=[shape=left] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{minipage}\vrule\hfill
\begin{minipage}{0.33\textwidth}
\<=[shape=center] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{minipage}\vrule\hfill
\begin{minipage}{0.33\textwidth}
\<=[shape=right] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{minipage}
\par\medskip
\makebox[0.33\textwidth]{|first|:}\hfil
\makebox[0.33\textwidth]{|hanging|:}\hfil
\makebox[0.33\textwidth]{|steps|:}\par\nobreak\smallskip
\begin{minipage}{0.33\textwidth}
\<=[shape=first] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{minipage}\vrule
\begin{minipage}{0.33\textwidth}
\<=[shape=hanging] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{minipage}\vrule
\begin{minipage}{0.33\textwidth}
\<=[shape=steps] x = \cos\phi \\ x = (z+z^{-1})/2 \\
  \phi = \arccos x \\ \phi = -i\log z \>
\end{minipage}
\end{example}

\DescribeKey{align}
\DescribeKey{shiftto}
\DescribeKey{shiftby}
The alignment preset can be adjusted for individual lines by the controls:
%
\begin{center}
\begin{tabular}{l}
|\eqncontrol{align=left|\textbar|center|\textbar|right}|\\
|\eqncontrol{shiftto|\textbar|shiftby=|\textit{dimen}|}|
\end{tabular}
\end{center}
%
\DescribeInterfaceMacro{\shoveleft}
\DescribeInterfaceMacro{\shovecenter}
\DescribeInterfaceMacro{\shoveright}
or by the macros:
%
\begin{center}
|\shoveleft|\textbar|\shovecenter|\textbar|\shoveright|%
[|*|\textbar|!|\textbar|[|\textit{dimen}|]|],
\end{center}
%
In contradistinction to \amsmath/,
these macros can be placed anywhere within the cell
and they do not take the cell contents as their argument
(doing this here will disallow shrinking of glue towards reducing width).
The macros accept an optional argument |[|\textit{dimen}|]|
specifying a variable amount of shift.
\DescribeKey{indent}
They also accept the modifiers
`|*|' or `|!|' for indentation or hanging indentation by
the standard indentation amount (|indent|=|2em|).
\DescribeInterfaceMacro{\shoveby}
Furthermore, |\shoveby|[|*|]|{|\textit{dimen}|}|
shifts the line by the additional amount \textit{dimen}
(the star variant shifts to an absolute position
relative to the reference position).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Reference Positions.}

\DescribeKey{padding}
\DescribeKey{padleft}
\DescribeKey{padright}
The reference positions for left, right and central alignment
are determined as follows:
The central reference position marks the centre of
the available horizontal space.
The left and right reference positions are given
by the ends of the widest line placed centrally.
The latter can be adjusted by adding
some padding around the widest line via the optional argument
|padding|\textbar|padleft|\textbar|padright|[|={|\textit{dimen}|}|]
while preserving the central default position.
The value `|indent|' sets the padding to the default indentation amount
and `|max|' extends the padding to all available space.
Note that |indent*={|\textit{dimen}|}| sets the default indentation amount
and the left padding at the same time.

\begin{example}
\begin{scanexample}
\eqnlinesset{indent=2em,pad=5em}
\<=
\shoveleft   \framebox[5em]{left} \\
\shoveleft*  \framebox[5em]{indent} \\
\shovecenter \framebox[5em]{center} \\
\shoveright  \framebox[5em]{right}
\>
\end{scanexample}
\showexampleh[0.55]
\begin{scanexample}
\eqnlinesset{layout=left}
\eqnlinesset{leftmargin=2em}
\eqnlinesset{indent=2em}
\<=
\shoveleft! \framebox[5em]{outdent} \\
\shoveleft  \framebox[5em]{left} \\
\shoveleft* \framebox[5em]{indent} \\
\shoveright \framebox[5em]{right}
\>
\end{scanexample}
\showexampleh[0.55]
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Fitting.}

Finally, we note that the package will make attempts
at fitting the equation components into the horizontal space
by adjusting some dimensions
with the priority of avoiding overlong lines.
The adjustments will first concern the intercolumn and margin spacing.
Secondly, \tex/ will attempt to shrink the glue between symbols
for very wide single and stacked equations (but not aligned equations).
Finally, equation tags may be shifted out of the way vertically
in order to free up horizontal space.
If all attempts fail, overlong lines will be indicated.

\DescribeKey{alignshrink}
\DescribeKey{tagshrink}
\DescribeKey{alignbadness}
\DescribeKey{tagbadness}
The threshold for shrinking of glue can be controlled by the two parameters
|alignshrink| and |tagshrink| accepting values ranging
between |0| (no shrink) and |4| (full allowable shrink).
They are used towards determining
whether to shift away from the intended alignment position
or whether to raise or lower the equation tag, respectively.
Small values prevent shrinking and higher values allow for more compression.
The corresponding parameters |alignbadness| and |tagbadness|
accept integer values setting the
native threshold in \tex/'s native units of |\badness|.

\begin{example}
\begin{scanexample}
\<=!
x+x \\
x+x+x+x \\
x+x+x+x+x+x \\
x+x+x+x+x+x+x+x \\
x+x+x+x+x+x+x+x+x+x \\
x+x+x+x+x+x+x+x+x+x+x+x \\
\>
\end{scanexample}
\showexampleh[0.6]
\end{example}

\DescribeKey{mintagsep}
If the available space on a line does not suffice to place
both the equation and its tag
(with a minimum separation of |mintagsep|; default is |0.5em|),
a tag will automatically be shifted
(lowered or raised depending on whether it is placed on the right or left)
to an otherwise empty line.
\DescribeKey{shifttag}
\DescribeInterfaceMacro{\raisetag*}
The |\eqncontrol| control |shifttag=|\textit{dimen}
(alternatively |\raisetag*|) may be used to shift a tag up
(or down with negative arguments).
\DescribeKey{smashtag}
\DescribeInterfaceMacro{\raisetag}
The control |smashtag=|\textit{dimen} (alternatively |\raisetag|)
may be used to fine-tune the vertical placement
when the tag requires extra vertical space
but some space above or below the tag is unoccupied.
It smashes some of the tag's height (or depth with negative arguments)
and thus reduces the vertical gap created by the tag.
Note that this feature can be used successively
with positive and negative arguments
to reduce the space in both directions if available.
\DescribeKey{pushtag}
\DescribeInterfaceMacro{\raisetag!}
Where needed, the control |pushtag| (or |\raisetag!|)
force-pushes the tag to a separate line
and frees up the horizontal space occupied by the tag.
The numbering modes |top|, |bottom|,
|center|, |median|, |center!| and |center*|
are special in that they allow for a continuous vertical placement
of the tag between two lines.
\DescribeKey{tagbetween}
The more flexible placement of tags may
also be enabled for the single-lines modes
by the option |tagbetween|.
Here, both lines must have sufficiently much space available for the tag.
If not, the tag is shifted up or down or it is places on separate line
between the two.
\DescribeKey{tagsnap}
The option |tagsnap| defines a range
within which the tag baseline snaps to a nearby math baseline.

\begin{example}
\begin{scanexample}
\[! \phi = -\int \frac{\mathrm{d}x}{\sqrt{1+x^2}} \]
\end{scanexample}
\showexampleh[0.8]
\begin{scanexample}
\[! x = \frac{\partial}{\partial \phi}\sin\phi
    \raisetag{0.45\baselineskip} \]
\end{scanexample}
\showexampleh[0.85]
\begin{scanexample}
\<=![numberline=center] \raisetag*{2pt}
x+x+x+x+x+x+x+x \\
x+x+x+x+x+x+x+x \\
x+x+x+x+x+x+x+x \\
x+x+x+x+x+x+x+x
\>
\end{scanexample}
\showexampleh[0.6]
\end{example}

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

Extending proper punctuation across equations is a delicate matter,
and maintaining it while redacting the text
certainly takes more attention to detail
than many authors 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{\eqnpunct}
\DescribeKey{punct}
The package supplies a semi-automatic scheme by which
equations are terminated by a specific punctuation mark.
\unskip\footnote{Clearly, the implementation of the scheme
will take higher efforts than direct coding.
Hence, the scheme can be useful in situations
where equations typically terminate phrases or
where punctuation is otherwise expected in regular patterns.}
Punctuation marks are set by:
%
\begin{center}
|\eqnlinesset{punct={|\textit{punct}|}}|
\qquad
|\eqnpunct{|\textit{punct}|}|
\qquad
|\[[punct={|\textit{punct}|}]|\,\ldots|\]|
\end{center}
%
The first form sets and enables a default punctuation mark;
the middle form sets the punctuation mark for the
next equation environment in line;
the final form applies to the equation environment only.
For example, one might globally declare `|punct={.}|'
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),
at the end of the equation
or by using the optional argument |[punct={,}]|.
Likewise, |\eqnpunct{}|, |[punct=~]| or |[punct={}]|
eliminates a preset punctuation.
\DescribeKey{. , \string~}
The modifiers dot `|.|', comma `|,|' and tilde `|~|'
for the equations environment are short forms for
using a dot, a comma or disabling punctuation.

\begin{example}
\eqnlinesset{skip=6pt}
\begin{scanexample}
\eqnlinesset{punct=.}
The equation
\[ x = \cos\phi \eqnpunct{} \]
can also be written as
\eqnpunct,
\[ x = (z+z^{-1})/2 \]
where we assume
\[ z = \exp(i\phi) \]
\end{scanexample}
\showexampleh
\end{example}

\DescribeInterfaceMacro{\eqnpunctapply}
In situations, where the punctuation must appear before the end
of the block, e.g.\ before a ``QED'',
it can be invoked manually by |\eqnpunctapply|.
Further automatic punctuation is suppressed within the current display.

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

\DescribeKey{punctcol}
\DescribeKey{punctline}
\DescribeKey{punctall}
\DescribeKey{`}
For multi-line equations, there are two further levels of default punctuation
for terminating columns and lines
which are specified via the option |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*|.
Several levels of punctuation can be specified simultaneously by |punctall|
or via the modifier `|`|':
%
\begin{center}
|punctall={|[[\textit{col}]\textit{line}]\textit{main}|}|
\qquad
|\[`{|[[\textit{col}]\textit{line}]\textit{main}|}|\,\ldots|\]|
\end{center}
%
The special value `|~|' represents no punctuation
and |\relax| hands down.
An empty argument for |punctall| or `|`|' removes all levels of punctuation.

\begin{example}
\begin{scanexample}
\<`{,;.}
   x &= \cos\phi &
\phi &= \arccos x \\
   x &= (z+z^{-1})/2 &
\phi &= -i\log z \>
\end{scanexample}
\showexampleh[0.4]
\end{example}

The package offers means to adjust
a standard punctuation (such as |punctall={,,.}|) to the particular situation:
\DescribeInterfaceMacro{\\}
\DescribeInterfaceMacro{\]}
\DescribeInterfaceMacro{\>}
\DescribeEnv{equations}
%
\begin{center}
|\\|\textit{mod}\texttt{\textvisiblespace}
\qquad
|\[|\,\ldots|\]|\textit{mod}\texttt{\textvisiblespace}
\qquad
|\<|\,\ldots|\>|\textit{mod}\texttt{\textvisiblespace}
\qquad
\ldots|\end{equations}|\textit{mod}\texttt{\textvisiblespace}
\end{center}
%
The newline command with tilde `|\\~|' describes a break
within a continued equation for which punctuation should be suppressed.
Furthermore, the |equations| and |equationsbox| environments
as well as the short forms |\[|\,\ldots|\]| and |\<|\,\ldots|\>|
allow trailing punctuation modifiers \textit{mod}
which place the modified punctuation closer to its natural location
than at the beginning of the block.
These can take values:
%
\begin{center}
\begin{tabular}{rcccc}
\textit{mod}: & |~| & |.| & |,| & |`{|\textit{punct}|}|
\\\hline
punctuation: & none & dot & comma & \textit{punct}
\end{tabular}
\end{center}
%
Note that the trailing modifiers only work for scanned environments;
|equationsbox| and the single-line |equation| with deactivated |scanequation|
do not accept trailing modifiers.
These option can be used
to stack several independent continued equations within a block
and to adjust the final punctuation to the flow of the surrounding phrase.

\begin{example}
\begin{scanexample}
\eqnlinesset{punctall={,.}}
\< x &= \cos\phi \\~
     &= (z+z^{-1})/2 \\
\phi &= \arccos x \\~
     &= -i\log z \>`{\ldots}
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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 \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, |\\&+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 source readability.

\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| (|ampeq| for short or `|<|' as modifier).
The optional argument |class=eqamp| (|eqamp| for short or `|>|' as modifier)
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.
For example, the following two expressions produce (almost) identical output:

\begin{example}
\begin{scanexample}
\<< a &= b+c \\
      &= d-e \\
      &\mathrel{}\phantom{=} +f \>
\end{scanexample}
\showexampleh
\begin{scanexample}
\<> a =& b+c \\
      =& d-e \\
       & +f \>
\end{scanexample}
\showexampleh
\end{example}

\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| alternatively |classin*|
determines the math class just after the alignment
if the cell before alignment is empty.
The spacing at the alignment is determined by the pairing
of the last/first character and the selected math class at the alignment:
%
\<[classin={},classout={},classlead={}]
\framebox[1em]{\bstrut}\ \framebox[1em]{\bstrut}\
\framebox[1em]{\bstrut a}\ \underline{\makebox[3em]{\itshape a-out}}
\ \vrule&
\ \underline{\makebox[3em]{\itshape in-b}}\ \framebox[1em]{\bstrut b}
\ \framebox[1em]{\bstrut}\ \framebox[1em]{\bstrut}
\\
\vrule&
\ \underline{\makebox[3em]{\itshape lead-c}}\ \framebox[1em]{\bstrut c}
\ \framebox[1em]{\bstrut}\ \framebox[1em]{\bstrut}
\>

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

Display equations in \tex/ are considered to be part
of the surrounding paragraph of text.
Hence, the vertical spacing depends on the surrounding text,
in particular on the width and depth of the line of text
directly preceding the equation.
Due to this influence it can be difficult to manually adjust
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 is determined by combination of several aspects:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Baselines.}

First, \tex/ inserts some glue between lines of text
to make them appear as regular as possible.
The amount of inserted glue is determined by \tex/'s rules
which depend on height, depth and intended baseline separation.
This interline spacing also applies to the lines of displayed equations
as well as the interfaces between text and displayed equations.

\DescribeKey{spread}
The spacing between the lines of a multi-line equation environment
can be adjusted via |spread={|\textit{dimen}|}|
which defaults to |\jot|$\equiv$|3pt| above the normal baseline skip.
\DescribeKey{strut}
\DescribeKey{strutdepth}
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 switch |strut|
which takes the values `|on|' (default), `|cells|', `|tags|' or `|off|'.
The relative depth of such a strut is determined by |strutdepth|
(default |0.3|).

While the height/depth of text typically takes rather uniform values,
the height/depth of math content can range wildly with the context
(plain equations vs.\ fractions and matrices).
As displayed 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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Vertical Situation.}

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.

\begin{example}
\begin{scanexample}
example of a long text line:
\[ \mbox{long mode} \]
vs.\ short:
\[ \mbox{short mode} \]
following line
\end{scanexample}
\showexampleh
\end{example}

\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}
\textit{mode} & reduced glue \\
\hline
|off| & disabled \\
|above| & above short equations (package default) \\
|belowone| & also below short single-line equations \\
|belowall| & also below all short multi-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|.

\begin{example}
\begin{scanexample}
example of a long text line:
\[[short] \mbox{forced short} \]
and short:
\[[long] \mbox{forced long} \]
following line
\end{scanexample}
\showexampleh
\end{example}

There are three special situations |cont|, |par| and |top|
which trigger different spacings:
|cont| describes the situation
at the start of an empty horizontal list
(invoked by |\noindent|)
or when an equation block directly follows another one;
here, the space above the equation should be minimal
(or even negative to remove the space below the previous equation block).
|par| describes the situation at the beginning of a paragraph
(invoked by |\par|);
here, the space above the equation adds to the space between paragraphs.
|top| describes the situation at the top of a vertical list
(invoked by |\nointerlineskip|);
here, one would typically want no space.

\begin{example}
\eqnlinesset{belowtopmode=long}
\begin{scanexample}
\hrule\begin{minipage}{\linewidth}
\[ \mbox{top} \]
some text\par
\[ \mbox{par} \]
\[ \mbox{cont} \]
\end{minipage}\hrule
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Explicit Spacing.}

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|.

\begin{example}
\begin{scanexample}
\hrule
\[[long] \mbox{long default} \]
\hrule
\[[medskip] \mbox{medium space} \]
\hrule
\[[noskip] \mbox{no space} \]
\hrule
\end{scanexample}
\showexampleh
\end{example}

\DescribeKey{par}
By default, equation environments end in horizontal mode without indentation.
The key |par| controls whether
the equation environments end in horizontal mode as usual (value |cont|)
or in vertical mode (value |par|, default)
with a dedicated amount of glue |belowparskip|.
An environment can also be made to end in vertical mode
without interline skip (value |top|)
using the glue |belowtopskip|.
The key |par| can be used for situations when vertical mode is preferred,
e.g.\ for lists following equations
where the vertical space above the list is excessive.
In the following example,
|\hrule| will leave an empty line when not in vertical mode.

\begin{example}
\begin{scanexample}
\hrule some text
\[ \mbox{cont} \]
\hrule some text
\[[par] \mbox{par} \]
\hrule
\end{scanexample}
\showexampleh
\end{example}

\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 \latex/ |\vspace| mechanism
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|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Glue Dimensions.}

The package also maintains several global vertical space settings
|above|\textit{pos}|skip| and |below|\textit{pos}|skip|
(sometimes \textit{pos}|skip| for both):
%
\DescribeKey{...skip}
\begin{center}
\begin{tabular}{lll}
\ldots\textit{pos}|skip| & both & description \\
\hline
|...long...|   & |longskip| & regular amount of glue \\
|...short...|  & -- & reduced glue for short equations \\
|...cont...|   & -- & glue when issued from an empty |\noindent| paragraph \\
|...par...|    & -- & glue when starting a paragraph (in vertical mode)\\
|...top...|    & -- & glue when issued at the top of vertical list \\
|...med...|    & |medskip| & medium amount of glue \\\hline
|...tag...|    & |tagskip| & minimum glue for outer raised/lowered tags \\
\end{tabular}
\end{center}
%
\DescribeKey{...mode}
The situations \textit{pos}=|cont|, |par| and |top|
use the respective amount of glue |above|\textit{pos}|skip|
above the equations and the regular amount of glue |belowlongskip| below.
These behaviours may be adjusted by the global options
|above|\textit{pos}|mode| and |below|\textit{pos}|mode|
with the values:
%
\begin{center}
\begin{tabular}{lll}
value & reduced glue \\
\hline
|long| & regular amount of glue \\
|short| & reduced glue for short equations \\
|cont| & amount for empty paragraph \\
|par| & amount for paragraph (and end the paragraph) \\
|top| & amount for top (and end the paragraph without interline skip) \\
|noskip| & no glue \\
|medskip| & medium amount of glue \\
\end{tabular}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Page Breaks.}

\DescribeKey{prebreak}
\DescribeKey{postbreak}
\DescribeKey{allowbreaks}
\DescribeKey{prepenalty}
\DescribeKey{postpenalty}
\DescribeKey{interpenalty}
\DescribeInterfaceMacro{\displaybreak}
Finally, the breaking of multi-line equations across pages
can be controlled as follows:
The setting |allowbreaks| (or |allowdisplaybreaks|)
taking values |0| (never) through |4| (permissive)
controls the permittivity of page breaks within multi-line equations.
The optional arguments |prebreak| and |postbreak|
taking values |0| (do not) through |4| (enforce)
suggest a break just above or below the equation environment.
The command |\displaybreak[|\textit{val}|]|
with values |0| through |4| (default)
suggests a break below the current line or below the equation environment.

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

The package supplies some additional environments and features:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Equation Boxes.}

\DescribeEnv{equationsbox}
\DescribeInterfaceMacro{\<...\string\>}
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
(yet, the |lines| mode accepts multiple columns here).
It can also be invoked by the symbolic short form |\<|\,\ldots|\>|
when called within math mode.

\DescribeKey{top,t}
\DescribeKey{center,c}
\DescribeKey{bottom,b}
The equations box accepts several arguments:
|top|, |center|, |bottom| (or |t|, |c|, |b|)
specify the vertical alignment of the box.
\DescribeKey{margin}
\DescribeKey{marginleft}
\DescribeKey{marginright}
|margin|, |marginleft|, |marginright|
specify additional margin space around the equations box.
\DescribeKey{colsep}
|colsep| specifies the amount of separation between the columns.
\DescribeKey{frame}
\DescribeKey{wrap}
|frame|[|=|\textit{cmd}] encloses the equations box
by a \textit{cmd} such as |\fbox| which accepts one argument
(or a command sequence which ends with a macro accepting one argument).
|wrap={{|\textit{cmdl}|}{|\textit{cmdr}|}}|
surrounds the equations box by the two commands
\textit{cmdl} and \textit{cmdr}.

\begin{example}
\begin{scanexample}
\[ \left\{
\begin{equationsbox}[margin=1em]
   x &= \cos\phi \\
\phi &= \arccos x
\end{equationsbox}
\right\}\]
\end{scanexample}
\showexampleh

\begin{scanexample}
$\Longrightarrow \<=[shape=l,frame]
   x = \cos\phi &
\phi = \arccos x \\
   x = (z+z^{-1})/2 &
\phi = -i\log z
\> \Longleftarrow$
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Cases and Matrix Environments.}

\DescribeEnv{cases}
\DescribeKey{cases}
\DescribeKey{condsep}
The |cases| environment is reimplemented
using the special mode |cases| of |equationsbox|
with two left-aligned cells
whose separation may be adjusted by the option |condsep|.
\DescribeKey{braces}
The equations box is wrapped by a left brace by default;
this behaviour may be adjusted by the option |braces|
taking the values |off|, |l|, |r|, |lr|.
\DescribeKey{intro}
\DescribeKey{introtext}
Furthermore, a common intro \textit{text} for all conditions
may be added by the option |intro={|\textit{text}|}|;
|introtext| sets \textit{text} in text mode with a trailing space.
\DescribeKey{textcond}
Finally, the option |textcond| determines that right cells are given in mode.
All features of |equationsbox|, such as punctuation,
are equally available for |cases|.

\begin{example}
\begin{scanexample}
\[ x = \begin{cases}[introtext={if},braces=lr]
1 & \phi = 0 \\
0 & \phi = \pi/2
\end{cases} \]
\end{scanexample}
\showexampleh[0.7]
\begin{scanexample}
\[`{,.} x = \<[cases,textcond]
\cos\phi & one way \\
(z+z^{-1})/2 & or the other
\eqnpunctapply \> \]
\end{scanexample}
\showexampleh[0.6]
\end{example}

\DescribeEnv{?matrix}
The set of |matrix| environments are reimplemented
using particular combinations of options for |equationsbox|:
The matrix is arranged in |lines| mode
with centred cells |shape=center|.
\DescribeKey{spread*}
The line spread is reset by |spread*|.
Punctuation is turned off by |punctall={}|.
\DescribeKey{style}
The cells are rendered in |\textstyle|
using the option |style=text|.
\DescribeKey{colsep*}
A small column separation |colsep*|
is selected by |colsep=short|.
\DescribeKey{delim}
Finally, the equations box is wrapped by a pair of delimiters
\textit{l} and \textit{r}
using the option |delim={|\textit{l}\textit{r}|}|.
Again, all features of |equationsbox|, such as punctuation,
are equally available for the |matrix| environments.
\DescribeKey{matrix}
Altogether, the combination is achieved by the shortcut option
|matrix={|\textit{l}\textit{r}|}|,
where \textit{l}\textit{r} may take the following abbreviations:
%
\begin{center}
\begin{tabular}{cccccccc}
\textit{lr} & `|.|' & |r| & |s| & |a| & |c| & |v| & |d|
\\\hline
brackets & none & round & square & angle & curly & bars & double bars
\\\hline
result & $\ldots$ & $(\ldots)$ & $[\ldots]$ & $\langle\ldots\rangle$
& $\lbrace\ldots\rbrace$ & $\vert\ldots\vert$ & $\Vert\ldots\Vert$
\end{tabular}
\end{center}

\begin{example}
\begin{scanexample}
\[ \begin{pmatrix}
\cos\phi & -\sin\phi \\
\sin\phi & \cos\phi
\end{pmatrix} \]
\end{scanexample}
\showexampleh
\begin{scanexample}
\[ \<[matrix=v,shape=r]
\cos\phi & -\sin\phi &  0 \\
\sin\phi &  \cos\phi &  0 \\
0        &  0        & -1
\> \]
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Collective Numbering.}

\DescribeEnv{subequations}
\DescribeKey{subeqtemplate}
The environment |subequations| groups 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 (|#1|)
is achieved by:
%
\begin{center}
|subeqtemplate={#1\alph{#2}}|
\end{center}

\begin{example}
\begin{scanexample}
\eqnlinesset
  {subeqtemplate={#1-\roman{#2}}}
\begin{subequations}
\[! x = \cos\phi \]
and
\[! \phi = \arccos x \]
\end{subequations}
\end{scanexample}
\showexampleh[0.55]
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Text Intermissions.}

\DescribeEnv{intertext}
\DescribeInterfaceMacro{\intertext}
The environment |intertext| (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.

\begin{example}
\begin{scanexample}
\< x &= \cos\phi
\intertext[medskip]{and}
\phi &= \arccos x \>
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Injection.}

\DescribeKey{inject}
\DescribeKey{inject*}
At a lower level, the control |\eqncontrol{inject={|\textit{cmd}|}}|
injects some command sequence \textit{cmd} after the present equation line
but before interline spacing.
The control |\eqncontrol{inject*={|\textit{cmd}|}}|
injects after interline spacing instead.

\begin{example}
\begin{scanexample}
\< x &= \cos\phi
\eqncontrol{inject=\hrule} \\
\phi &= \arccos x \>
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Line Marks.}

\DescribeKey{markline}
\DescribeKey{qed}
The package provides a mechanism to mark an equation line
at the end of the present line or just below.
This mechanism can be used to display a QED mark:
%
\begin{center}
\begin{tabular}{l}
|\eqncontrol{markline={symbol=|\textit{sym}|,|\textit{opts}|}|
\\
|\eqncontrol{qed|[|={|\textit{opts}|}|]|}|
\end{tabular}
\end{center}
%
The QED symbol may as well be invoked
by |\qedhere[|\textit{opts}|]| of \ctanpkg{amsthm}.
The starred variants |markline*|, |qed*| and |\qedhere*|
should be used for long lines
where the mark would otherwise smash equation content
(equation numbers are avoided automatically).

\begin{example}
\begin{scanexample}
\<[n=l]! x &= \cos\phi
\eqncontrol{markline={symbol=$\sqrt{}$}} \\
\phi &= \arccos x
\eqncontrol{qed={shift=.5ex}} \>
\end{scanexample}
\showexampleh[0.6]
\end{example}

The options \textit{opts} can be used
to adjust the placement
by |below| (placed on a separate line below the present line),
|baseline| (smashed at the current baseline),
|bottom| (smashed at the bottom of the present line),
to fine-tune the vertical position by |shift=|\textit{dimen}
or to adjust the symbol by |symbol=|\textit{sym}.
The default position and symbol can be adjusted by
the global settings |markpos|, |marksymbol| and |qedsymbol|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Frames.}

\DescribeInterfaceMacro{\framecell}
\DescribeKey{framecell}
The package allows to frame cells of an equation block
via issuing a simple command within the cell:
%
\begin{center}
|\framecell[|\textit{cmd}|]|
\qquad or\qquad
|\eqncontrol{framecell|[|={|\textit{cmd}|}|]|}|
\end{center}
%
This command corresponds to |\Aboxed| of \ctanpkg{mathtools}.
In particular, when used within columns or aligned mode,
the frame will extend over both right and left alignment components
of a cell; in order to allocate the right amount of space,
it should be issued within the first cell of the pair.
The layout of the frame can be adjusted
by the optional argument \textit{cmd} which defaults to |\fbox|:
it must be a macro which accepts one argument
(or a command sequence which ends with a macro accepting one argument).
Note:
Any semi-automatic punctuation is included within the frame,
see \secref{sec:punctuation}.
Parts of a cell can be framed by the \amsmath/ macro |\boxed|,
which will not include semi-automatic punctuation.
Furthermore, the height and depth of the box are bounded from below
by a strut, see \secref{sec:vspace}.

\DescribeKey{frametag}
Similarly, the package allows to frame tags:
%
\begin{center}
|\eqncontrol{frametag|[|={|\textit{cmd}|}|]|}|
\end{center}
%

\begin{example}
\begin{scanexample}
\< x &= \cos\phi \\
\framecell \phi &= \arccos x \>
\end{scanexample}
\showexampleh[0.55]
\begin{scanexample}
\[ \framecell[\fboxrule2pt\fbox]
  \mbox{important} \eqnpunct! \]
\end{scanexample}
\showexampleh[0.55]
\begin{scanexample}
\[! \framecell[\fcolorbox{white}{yellow}]
  \eqncontrol{frametag=\fboxsep2pt\fbox}
  \mbox{highlight}\]
\end{scanexample}
\showexampleh[0.55]
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Single-Line Composition.}

\DescribeInterfaceMacro{\\}
\DescribeInterfaceMacro{\eqnbreak}
\DescribeInterfaceMacro{\eqnsep}
\DescribeInterfaceMacro{\eqnjoin}
Several short pieces of math content
may well fit within a single equation line,
typically separated by some amount of space like |\qquad| or |\qquad|.
The package provides several context-aware commands for this purpose:
the commands |\eqnsep| and |\eqnbreak| insert some horizontal glue,
whereas |\eqnjoin| joins two parts of an equation with some conjunction.
The glue typically includes some amount of shrink
in order to accommodate the content when space is sparse.
Furthermore, |\eqnsep| and |\eqnbreak| also automatically insert
the punctuation for columns and lines, respectively.
For convenience,
the newline command `|\\|' maps to |\eqnbreak|
in single equation mode where it serves no other purpose.
The commands have several optional arguments:
%
\begin{center}
|\eqnsep|\textbar|\eqnbreak|\textbar|\\|\,%
[|~|][|*|\textbar|[|\textit{skip}|]|]
\qquad
|\eqnjoin|[|*|\textbar|[|\textit{skip}|]|]|{|\textit{conjunction}|}|
\end{center}
%
The modifier `|~|' suppresses punctuation
and `|*|' chooses a shorter glue,
whereas the optional argument \textit{skip}
specifies the amount of glue explicitly.
\DescribeKey{linesep}
\DescribeKey{colsep}
The default amounts of glue for |\eqnbreak| or `|\\|' and |\eqnsep|
are determined by the settings |linesep| and |colsep|, respectively.
The starred variants |linesep*| and |colsep*|
determine the short amount of glue.

\begin{example}
\begin{scanexample}
\[ x = \cos\phi \\[4em]
\phi = \arccos x \]
\end{scanexample}
\showexampleh
\begin{scanexample}
\[`{,.} x = (z+z^{-1})/2 \\
\phi = -i \log z \]
\end{scanexample}
\showexampleh
\begin{scanexample}
\[ x = \cos\phi \eqnjoin*{\iff}
\phi = \arccos x \]
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Alternative Content Description.}

\DescribeKey{alt}
\DescribeInterfaceMacro{\eqnalt}
The package provides a basic interface to describe the equation content
in an alternative form for the purposes of accessibility or documentation
(corresponding to the |alt| tag in HTML):
%
\begin{center}
|alt={|\textit{alt text}|}|
\qquad or \qquad
|\eqnalt[|\textit{opt}|]{|\textit{alt}|}|
\end{center}
%
At the moment the alternative text \textit{alt} is not processed further,
but an accessibility extension may implement the feature in tagged PDFs
or HTML conversion. The comma-separated optional arguments \textit{opt}
may specify the content further:
|line| and |cell| restrict the applicability
to the current equation line or cell, respectively.
Other keys might specify the content format and language.

\begin{example}
\begin{scanexample}
\<[alt={example equations}]
x &= \cos\phi \\
\eqnalt[line]{reverse relationship}
\phi &= \arccos x \>
\end{scanexample}
\showexampleh
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{General Options}
\label{sec:auxiliary}

\DescribeInterfaceMacro{\eqnlinesset}
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 package supplies the following general settings:
\begin{center}
\begin{tabular}{ll}
option & description \\
\hline
|defaults=classic|
  & mimic classic \latex//\amsmath/ (layout and dimensions) \\
|defaults=eqnlines|
  & \ctanpkg{eqnlines} layout with fontsize-relative dimensions \\
|rescan| & rescan environment body for special commands (e.g.\ |\verb|) \\
|linesfallback| & single column in align mode reverts to lines mode \\
                & value |reuse| avoids third measuring pass \\
|ampproof| & equip optional argument parsing with protection for `|&|' \\
|equationcr| & determine overloading of `|\\|' for single equations \\
             & |off|: native \latex/ error; |error|: package error; \\
             & |break|: insert horizontal glue (see \secref{sec:further}) \\
|modifierwarning| & invoke a warning for unknown environment modifiers \\
|scanpar| & allow scanning of |\par| within equation body \\
          & (e.g., for use in nested |\parbox| or |minipage|) \\
|verbose| & track code location in log file for debugging purposes \\
|scanequation| & scan single-line environments |equation| and |\[|\,\ldots|\]| \\
|native| & native processing of single-line equations (reduced functionality) \\
\end{tabular}
\end{center}

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

The following few settings can only be specified when loading the package,
not via |\eqnlinesset|:
%
\begin{center}
\begin{tabular}{ll}
option & description \\
\hline
|env=none| & provide only |equations| and |equationsbox| environments \\
|env=equation| & provide/overwrite |equation|,
                 |displaymath| and |\[|\,\ldots|\]| \\
|env=amsmath| & provide/overwrite \amsmath/ environments
                (including |equation|) \\
|amsmathends|=\textit{bool}  & patch \amsmath/ environments
                   with individual endings \\
|backup|=\textit{bool}  & backup original \amsmath/ environments
                   as |ams...| \\
|ang|=\textit{bool} & provide |\<|\,\ldots|\>| \\
|eqref|=\textit{bool} & provide |\eqref| \\
|matrix|=\textit{bool} & provide \amsmath/ |?matrix|
                         and |cases| environments \\
\end{tabular}
\end{center}

If the above settings are explicitly 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|, |equation*|, |displaymath|, |subequations| \\
& |gather|, |multline|, |align|, |flalign|, |xalign|, |xxalign| \\
& |gather*|, |multline*|, |align*|, |flalign*|, |xalign*| \\
& |multlined|, |gathered|, |aligned| \\
\textit{env}|=|\textit{name} &
   provide environment \textit{env} as \textit{name} \\
|sqr| & provide |\[|\,\ldots|\]| \\
|ang| & provide |\<|\,\ldots|\>| \\
|eqref| & provide/overwrite macro |eqref| \\
|tagform| & provide/overwrite macro |\tagform@|\\
|maketag| & provide/overwrite macro |\maketag@@@|\\
\end{tabular}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\iffalse
\TODO
\section{List of Options}
\label{sec:lists}

\fi


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

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

Copyright \copyright{} \thecopyright/

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|,
|eqnlines.tex|, |eqnlines.pdf|, |eqnlines-src.tex|, |eqnlines-src.pdf|.

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

This package is based on the \latex/ package \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 \amsmath/
in accordance with the LPPL, particularly paragraph 6.
The original package \amsmath/ is available
at CTAN within \ctanpkg{latex-amsmath}.
It uses the basic mechanisms for processing
numbered multi-line equations as developed in \amsmath/
(environments |equation|, |align|, |gather|, |multline|, |gathered|, |aligned|
and related), as well as code implementing these mechanisms.
It differs from \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 \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.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|.
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 \amsmath/.
The present code is based on \amsmath/ v2.17t (2024/11/05).
Compatibility with the \amsmath/ package is maintained
whether \ctanpkg{eqnlines} is loaded before or after \amsmath/.
By default, \ctanpkg{eqnlines} overwrites
most math environments of \amsmath/ with its own implementations.
It can also preserve them as |ams...| if needed.
Alternatively, \ctanpkg{eqnlines} may assign individual names
to the maths environments and preserve the ones of \amsmath/.
The other features provided by \amsmath/
can be used.
\item
The package \ctanpkg{mathtools}
is a popular extension of the \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 \ctanpkg{eqnlines}
is loaded before or after \ctanpkg{mathtools}.
Some features like emphasising equations via \ctanpkg{empheq}
do not (yet) work.
\item
This package has several overlapping goals and considerations
with the package \ctanpkg{breqn} in handling
long equations more conveniently.
However, the approach is very different from \ctanpkg{breqn}
which mainly aims at automation.
\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 cooperates with the package \ctanpkg{beamer}
in assigning default colours for math content.
Compatibility with the \ctanpkg{beamer} package
has been tested with v3.74 (2025/06/15).
\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).
\item
This package supports placement of QED symbols within |proof|s
through the |\qedhere| interface of the package \ctanpkg{amsthm}.
Compatibility with the \ctanpkg{amsthm} package
has been tested with v2.20.6 (2020/05/29).
\item
This package supports PDF tagging
using the framework defined in \ctanpkg{tagpdf} and \ctanpkg{luamml}
(when using the |lualatex| engine).
It uses and adjusts some methods from
the development framework \ctanpkg{latex-lab} (|math| and |amsmath| modules).
Compatibility has been tested with the package versions
\ctanpkg{tagpdf} v0.99w (2025/10/31),
\ctanpkg{luamml} v0.7.0 (2025-10-20) and
\ctanpkg{latex-lab} (2025/11/01).
Support for PDF tagging is preliminary, partial and fragile;
it may break due to future developments of the PDF tagging framework.
\item
This package is currently not compatible
with the package \ctanpkg{cleveref}
(thanks to Jon\'a\v s Dujava for pointing out).
The command |\Cref| will not refer properly to equation numbers
recorded by the |equations| environment.
Further features of either package and/or/in combination with \amsmath/
may fail due to the patching by the package.
The alternative package \ctanpkg{zref-clever} appears to work as intended.
Incompatibility with the \ctanpkg{cleveref} package
has been observed for v0.21.4 (2018/03/27).
Compatibility with the \ctanpkg{zref-clever} package
has been tested with v0.5.1 (2024/11/28).
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\iffalse
\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.

Documentation:
%
\begin{itemize}
\item
complete code documentation
%
\item
list of all option keys with scope, defaults and special values
%
\end{itemize}

Additional functionality:
%
\begin{itemize}
\item
alignment for columns mode (two columns as before)
%
\item
extended columns mode, allow alignment in lines mode
%
\item
reduce intercolumn space below zero if indentation permits
%
\item
single column compressible lines in columns mode
(determine alignment line first)
%
\item
flexible columns mode (note math classes, punctuation, intercolumn space)
%
\item
tool palette depending on mode (|\eqnsep|, |\eqnbreak|)
%
\end{itemize}

Fix or complete functionality:
%
\begin{itemize}
\item
|\vspace| for |equationsbox| (required line contained)
%
\item
adjust PDF tagging with development in kernel,
describe functionality when ready
%
\item
|\intertext| might not collaborate correctly with PDF tagging
%
\end{itemize}

Some technical and/or internal items to be done include:
%
\begin{itemize}
\item
test files
%
\item
check documentation for all features
%
\item
change |\@ifpackageloaded| to |\IfPackageLoaded...|
when command is less recent.
%
\item
change bool registers to |char| 0 and 1 and |\||ifodd|
%
\end{itemize}
\fi

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

\iffalse

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{vN.N.N+:} 20YY/MM/NN

\begin{itemize}
\item
\ldots
\end{itemize}

\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.14:} 2026/01/28

\begin{itemize}
\item
second release candidate for v1.0
\item
added |cases| and |matrix| environments
\item
added punctuation modifiers `|.|' and `|,|'
to |\eqnsep|, |\eqnbreak|, |\\| and |equationsbox|
\item
made |\eqnpunctapply| work within cells and embedded groups
\item
made |\eqnpunct| work for left cells in a column
\item
added modifiers `|<|' and `|>|' for class options |ampeq| and |eqamp|
\item
added option |delim| for delimiter selection
\item
added option |style| for text and display math styles
\item
added option |spread*| to reduce line spread
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.13:} 2026/01/14

\begin{itemize}
\item
release candidate for v1.0
\item
added trailing modifiers to conveniently adjust punctuation
\item
added |verbose| mode for debugging purposes,
removed |eqnlines-dev| package version
\item
fixed spacing issues with `|\\~|'
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.12.2:} 2026/01/13

\begin{itemize}
\item
registered environments with luamml for label processing
\item
use |\eqnlinesprovide| for starred variants separately
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.12.1:} 2025/12/28

\begin{itemize}
\item
fixed unwanted deferring of numbering when using |\\~| in continuous mode
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.12:} 2025/12/27

\begin{itemize}
\item
split off source code documentation into separate document |eqnlines-src|
\item
added modified newline `|\\~|' to indicate continued equation
with deferred numbering and punctuation suppressed
\item
added |\eqnsep|,  |\eqnbreak|, |\eqnjoin| for single-line compositions,
mapped `|\\|' for single equations to |\eqnbreak|
\item
added modifier `|`|' to |equationsbox|
\item
removed faulty option |crerror|
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.11:} 2025/10/25

\begin{itemize}
\item
added option |punctall| and modifier `|`|'
to specify several levels of punctuation at once
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.10.1:} 2025/06/23

\begin{itemize}
\item
fix for setting default colours (|math text|) in \ctanpkg{beamer}
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.10:} 2025/05/29

\begin{itemize}
\item
added |numberline| modes |center|, |median|, |top| and |bottom|
with continuous vertical adjustments
(thanks to Jon\'a\v s Dujava for testing)
\item
fixed spacing following |\paragraph|
(thanks to Jon\'a\v s Dujava for report)
\item
added control |inject| to add free-style content after the present line
\item
added control |markline| and |qed| to display a (QED) mark
\item
added support for \ctanpkg{amsthm} through |\qedhere|
(thanks to Jon\'a\v s Dujava for suggestion)
\item
fixed minor issues
\item
internal structure and minor interface changes
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.9:} 2025/05/18

\begin{itemize}
\item
option |transpose| to transpose rows and columns in columns mode
(thanks to Christophe Bal for suggestion)
\item
added |\eqncontrol| interface for control within lines and cells
\item
internal structure and interface changes
\item
added |\vspace*| for persistent glue at page breaks
\item
added framed tags (|frametag|)
\item
added |\raisetag!| to enforce raising (or lowering) of tags
even if space is sufficient
\item
added modifiers, relaxed order, changed lines mode modifier from `|~|' to `|=|'
\item
fixed minor issues
\item
thanks to Jon\'a\v s Dujava for various reports and suggestions
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.8:} 2025/04/30

\begin{itemize}
\item
added framed cells (|\framecell|)
\item
added automatic best line selection for tag placement
(|best| and |evadetag|)
\item
symbolic environment |\<|\,\ldots|\>| forwards to |equationsbox| in math mode
\item
added wrapping for |equationsbox| (|frame|, |wrap|)
\item
horizontal adjustment reworked and completed; |\shoveby| added
\item
extended |\label| to assign names to labels for |\namedref|
\item
interface for alternative representations (|alt| and |\eqnalt|)
\item
options to adjust line width and margins
(|linewidth|, |marginleft|, |marginright|)
\item
added option |scanpar| to allow |\par| appearing in equation body
\item
added continuous penalties (|prepenalty|, |postpenalty|, |interpenalty|)
\item
added overloading for |displaymath| and remaining \amsmath/ math environments
\item
minor interface changes (rename, recombine, values)
\item
documentation expanded
\item
several issues fixed
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.7.1:} 2025/04/09

\begin{itemize}
\item
improvements for PDF tagging
\item
backup all available math environments at the start using |backup| switch
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.7:} 2025/04/03

\begin{itemize}
\item
manual expanded, examples added
\item
fixes for numbering, tagging, options, |linesfallback|, zero lines
\item
expansions for vertical spacing modes, tag display, |subeqtemplate|
\item
some consolidations
\item
internal rearrangements
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.6.1:} 2025/03/27

\begin{itemize}
\item
|\eqnpunct| can place punctuation within the current equation cell
\item
|numberline=none| now acts as |numberline=all| and |nonumber|
\item
fixed and extended |tagmargin|
with |tagmarginratio| and |tagmarginthreshold|
\item
padding now applies to single-line equations as well
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.6:} 2025/03/11

\begin{itemize}
\item
preliminary PDF tagging support
(\url{https://latex3.github.io/tagging-project/};
\amsmath/ \emph{must} be loaded \emph{before} \ctanpkg{eqnlines}
to avoid errors
\item
classic \latex//\amsmath/ vs.\ \ctanpkg{eqnlines} presets
\item
changed vertical spacing schemes and added further options
\item
supplied dimensions processed by |\glueexpr|
\item
more independent of \amsmath/ structures
\item
internal reorganisations
\end{itemize}

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

\begin{itemize}
\item
preview version published on CTAN
\item
thanks to Till Bargheer for testing and reports
\end{itemize}

%</main|manual>
%<*main>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\appendix
%</main>
%<*main|source>
\raggedright
\settowidth\MacroIndent{\rmfamily\scriptsize 0000\ }

\DocInput{eqnlines.dtx}
%</main|source>

\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</main|manual|source>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \iffalse
%<*package>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
%
% This appendix documents the implementation
% for the various components of the \markpkg{eqnlines} package.
%
% The code for the package is based on the \amsmath/ package,
% see the reference manual for details.
% 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 \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{Debugging Messages}
%
% The package offers a verbose mode for debugging purposes.
% It outputs extra information on the current location
% within the code in order to track progress:
% \TODO describe
%    \begin{macrocode}
\def\eql@verbose@on{%
  \def\eql@verbose@info##1{\PackageInfo{eqnlines}{##1}}
  \def\eql@verbose@infoarg##1##2{\eql@verbose@info{##1##2}}
}
\def\eql@verbose@off{%
  \let\eql@verbose@info\@gobble
  \let\eql@verbose@infoarg\@gobbletwo
}
\eql@verbose@off
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@verbose@msg@enterenv{entering \@currenvir}
\def\eql@verbose@msg@leaveenv{ leaving \@currenvir}
\def\eql@verbose@msg@start#1{starting \string#1}
\def\eql@verbose@msg@end#1{ \space ending \string#1}
\def\eql@verbose@msg@within#1{ \space within \string#1}
\def\eql@verbose@msg@enter#1{entering \string#1}
\def\eql@verbose@msg@leave#1{ leaving \string#1}
\def\eql@verbose@msg@startline{starting line \the\eql@row@}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \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}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@append#1#2{\edef#1{\unexpanded\expandafter{#1#2}}}
\def\eql@appendexpand#1#2{\edef#1{\unexpanded\expandafter{#1}#2}}
\def\eql@appendmacro#1#2{\eql@appendexpand#1{\unexpanded\expandafter{#2}}}
\def\eql@letcs#1{\expandafter\let\csname#1\endcsname}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Dollardollar Abstraction}
%
%   \macro{\eql@dollardollar@begin}
%   \macro{\eql@dollardollar@end}
% As of 2025 \latex/ defines |\dollardollar@begin| and |\dollardollar@end|
% to represent (and adjust) the beginning and end of
% bare \tex/ display equations (`|$$|').
% For the time being, we make sure to revert to `|$$|' if these
% macros are not yet available:
%    \begin{macrocode}
\ifdefined\dollardollar@begin
  \def\eql@dollardollar@begin{\dollardollar@begin}
  \def\eql@dollardollar@end{\dollardollar@end}
\else
  \def\eql@dollardollar@begin{$$}
  \def\eql@dollardollar@end{$$}
\fi
%    \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 clarity, 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}
%
%   \macro{\eql@atxi}
%   \macro{\eql@atxii}
% Capture `|@|' as a character (catcode 12)
% rather than a letter (catcode 11) as |\eql@atxii|
% so that we can look-ahead for `|@|' with both
% |\makeatother| and |\makeatletter| modes:
%    \begin{macrocode}
\let\eql@atxi=@
\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}}}
\long\def\eql@teststaroropt@loose#1#2#3{%
  \eql@ifstar@loose{#1}{\eql@testopt@loose{#2}{#3}}}
\long\def\eql@teststaroropt@tight#1#2#3{%
  \eql@ifstar@tight{#1}{\eql@testopt@tight{#2}{#3}}}
\long\def\eql@gobbleopt[#1]{}
\long\def\eql@gobbleoptone[#1]#2{}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@testopt@default{\eql@testopt@default}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@parseopt@warn@main\@empty
\let\eql@parseopt@warn@aux\@empty
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@parseopt@main{%
  \let\eql@parseopt@warn\eql@parseopt@warn@main\eql@parseopt}
\def\eql@parseopt@aux{%
  \let\eql@parseopt@warn\eql@parseopt@warn@aux\eql@parseopt}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@parseopt#1#2{%
  \def\eql@parseopt@case{#1}%
  \def\eql@parseopt@end{#2}%
  \eql@parseopt@peek
}
\def\eql@parseopt@peek{%
  \futurelet\eql@parseopt@token\eql@parseopt@select
}
\def\eql@parseopt@select{%
  \let\eql@parseopt@next\eql@parseopt@other
  \ifx\eql@parseopt@token\@sptoken
    \let\eql@parseopt@next\eql@parseopt@end
  \fi
  \eql@parseopt@case
  \eql@parseopt@next
}
\def\eql@parseopt@other{\eql@parseopt@warn\eql@parseopt@end}
\def\eql@parseopt@gobble#1{\eql@parseopt@peek}
%    \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@mathmode}
% Error messages concerning math mode:
%    \begin{macrocode}
\def\eql@warn@here#1{\eql@warning{\string#1 not allowed outside equations}}
\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}
%   \macro{\eql@warn@name@unused}
%   \macro{\eql@warn@name@multiple}
%   \macro{\eql@warn@ref@unused}
%   \macro{\eql@warn@ref@multiple}
% Warning messages concerning unused and multiply declared labels and tags:
%    \begin{macrocode}
\def\eql@warn@tags@unused#1#2{\eql@warning{Unused equation #1:
    #2 will be lost}}
\def\eql@warn@tags@multiple#1#2#3{\eql@warning{Multiple equation #1:
    previous #2 will be lost#3}}
\def\eql@warn@label@unused{\eql@warn@tags@unused{\string\label}
    {label '\eql@tags@label'}}
\def\eql@warn@label@multiple#1{\eql@warn@tags@multiple{\string\label's}
    {label '\eql@tags@label'}{ and replaced by '#1'}}
\def\eql@warn@name@unused{\eql@warn@tags@unused{label name}
    {name declaration}}
\def\eql@warn@name@multiple{\eql@warn@tags@multiple{label names}
    {name declaration}{}}
\def\eql@warn@tag@unused{\eql@warn@tags@unused{\string\tag}
    {tag declaration}}
\def\eql@warn@tag@multiple{\eql@warn@tags@multiple{\string\tag's}
    {tag declaration will be lost}{}}
\def\eql@warn@ref@unused{\eql@warn@tags@unused{tag label}
    {tag label declaration}}
\def\eql@warn@ref@multiple{\eql@warn@tags@multiple{tag labels}
    {tag label declaration}{}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@warn@parseopt{\eql@warning{Unknown modifier token:
    modifier parsing stopped}}
\def\eql@warn@parseopt@verbose{\eql@warning{Unknown modifier token:
    '\meaning\eql@parseopt@token'}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{amsmath Integration}
%
%   \macro{\eql@amsmath@after}
%   \macro{\eql@amsmath@before}
%   \macro{\eql@amsmath@undefine}
%   \macro{\eql@amsmath@let}
% We need to overwrite certain macros from \amsmath/.
% The method |\eql@amsmath@after| executes argument |#1|
% after loading \amsmath/ is loaded.
% It also runs the code if \amsmath/ has already been loaded.
% Furthermore, loading \amsmath/ requires
% certain macros to be undefined. To this end
% |\eql@amsmath@before| will execute argument |#1|
% before any future loading of \amsmath/.
% |\eql@amsmath@undefine| undefines a macro
% in this way and |\eql@amsmath@let| overwrites
% a macro of |\amsmath/|:
%    \begin{macrocode}
\def\eql@amsmath@after#1{\AddToHook{package/amsmath/after}{#1}}
\def\eql@amsmath@before#1{%
  \@ifpackageloaded{amsmath}{}{\AddToHook{package/amsmath/before}{#1}}}
\def\eql@amsmath@undefine#1{\eql@amsmath@before{\let#1\@undefined}}
\def\eql@amsmath@let#1#2{\eql@amsmath@undefine#1\let#1#2}
%    \end{macrocode}
%
% \TODO temporary fix for development stages
%    \begin{macrocode}
\@ifpackageloaded{amsmath}{}{
  \DeclareHookRule{package/amsmath/after}
    {eqnlines}{after}{latex-lab-testphase-math}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{PDF Tagging Support}
%
%   \macro{\eql@tagging@...}
% Proper PDF tagging
% \unskip\footnote{see \url{https://latex3.github.io/tagging-project/}}
% support requires a \latex/ version at least of 2025.
% For the time being, we define an abstraction layer so that
% the package will collaborate with \latex/ versions around 2020:
% \TODO adjust to further developments
%    \begin{macrocode}
\let\eql@tagging@on\eql@false
\IfFormatAtLeastTF{2025-06-01}{%
  \csname tag_if_active:T\endcsname{\let\eql@tagging@on\eql@true}}{}
\ifdefined\eql@tagging@on
  \def\eql@tagging@mathsave{%
    \UseTaggingSocket{math/luamml/save/nNn}{{}\displaystyle{mtd}}}
  \def\eql@tagging@mathaddlast{%
    \UseTaggingSocket{math/luamml/mtable/finalizecol}{last}}
  \def\eql@tagging@tagbegin{%
    \UseTaggingSocket{math/display/tag/begin}}
  \def\eql@tagging@tagend{%
    \UseTaggingSocket{math/display/tag/end}}
  \def\eql@tagging@tagsave{%
    \UseTaggingSocket{math/luamml/mtable/tag/save}}
  \def\eql@tagging@tagaddbox{%
    \setbox\z@\copy\eql@tagbox@%
    \UseTaggingSocket{math/luamml/mtable/tag/set}}
  \def\eql@tagging@tablesaveinner{%
    \UseExpandableTaggingSocket{math/luamml/mtable/innertable/save}}
  \def\eql@tagging@tableaddinner{%
    \UseTaggingSocket{math/luamml/mtable/innertable/finalize}}
  \def\eql@tagging@tablesavelines{%
    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{gather}}
  \def\eql@tagging@tablesavealign{%
    \UseExpandableTaggingSocket{math/luamml/mtable/finalize}{align}}
  \def\eql@tagging@alignleft{%
    \UseTaggingSocket{math/luamml/mtable/aligncol}{left}}
  \def\eql@tagging@aligncenter{%
    \UseTaggingSocket{math/luamml/mtable/aligncol}{center}}
  \def\eql@tagging@alignright{%
    \UseTaggingSocket{math/luamml/mtable/aligncol}{right}}
%    \end{macrocode}
% We need to get hold of the equation body in all cases
% so that we can feed it into the tagging mechanism:
%    \begin{macrocode}
  \let\eql@single@doscan\eql@true
  \let\eql@scan@body\eql@scan@body@rescan
%    \end{macrocode}
%   \macro{\eql@tagging@start}
%   \macro{\eql@tagging@end}
% We need to activate tagging for display equations
% for environments and for enclosures |\[|\,\ldots|\]| and |\<|\,\ldots|\>|.
% The tagging interface registration macro |\RegisterMathEnvironment|
% will work only partially for our cases, hence we
% replicate code from |\math_register_halign_env:nn|.
% Make sure collection is not yet active (|\l__math_collected_bool|).
% Then feed collected environment name,
% options and body into |\__math_process:nn|.
% Indicate the start of a display equation:
%    \begin{macrocode}
  \def\eql@tagging@start{%
    \csname bool_if:NF\expandafter\endcsname
      \csname l__math_collected_bool\endcsname{%
      \edef\eql@tmp{{\@currenvir}{[\unexpanded\expandafter{\eql@tagging@opt}]%
        \the\eql@scan@reg@}}%
      \csname __math_process:nn\expandafter\endcsname\eql@tmp
      \@kernel@math@registered@begin
      \csname bool_set_true:N\expandafter\endcsname
        \csname l__math_collected_bool\endcsname
    }%
  }
  \def\eql@tagging@end{}
  \def\eql@tagging@register@luamml#1{%
    \AddToHook{package/luamml/after}{%
      \eql@letcs{c__luamml_label_#1_tl}\@empty}}
  \def\eql@tagging@register@env{\csname math_register_env:n\endcsname}
%    \end{macrocode}
% When tagging is deactivated, provide empty definitions:
%    \begin{macrocode}
\else
  \let\eql@tagging@mathsave\@empty
  \let\eql@tagging@mathaddlast\@empty
  \let\eql@tagging@tagbegin\@empty
  \let\eql@tagging@tagend\@empty
  \let\eql@tagging@tagsave\@empty
  \let\eql@tagging@tagaddbox\@empty
  \let\eql@tagging@tablesaveinner\@empty
  \let\eql@tagging@tableaddinner\@empty
  \let\eql@tagging@tablesavelines\@empty
  \let\eql@tagging@tablesavealign\@empty
  \let\eql@tagging@alignleft\@empty
  \let\eql@tagging@aligncenter\@empty
  \let\eql@tagging@alignright\@empty
  \let\eql@tagging@start\@empty
  \let\eql@tagging@end\@empty
  \let\eql@tagging@register@luamml\@gobble
  \let\eql@tagging@register@env\@gobble
\fi
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Key-Value Processing}
%
% 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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Value Selection.}
%
%   \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|}|.
% \]
% The (single) value |\relax| matches everything
% (can be used for handling generic values after specific ones).
% 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@relax{\eql@tmpb:=\relax}
\def\eql@decide@select#1#2#3#4{%
  \def\eql@tmpa{#3}%
  \let\eql@tmpd\@undefined
  \@for\eql@tmpc:=#4\do{%
    \ifdefined\eql@tmpd\else
      \edef\eql@tmpb{\noexpand\eql@tmpb:=\expandafter\@firstoftwo\eql@tmpc}%
      \ifx\eql@tmpb\eql@decide@relax
        \def\eql@tmpa{\relax}%
      \fi
      \expandafter\@for\eql@tmpb\do{%
        \ifx\eql@tmpa\eql@tmpb
          \edef\eql@tmpd{\unexpanded\expandafter\expandafter\expandafter{%
            \expandafter\@secondoftwo\eql@tmpc}}%
        \fi
      }%
    \fi
  }%
  \ifdefined\eql@tmpd
    \eql@tmpd
  \else
    \eql@error{undefined value '#3' for option '#2' of '#1'}%
  \fi
}
%    \end{macrocode}
%
% Decide between |true| and |false| or related pairs of values:
%    \begin{macrocode}
\def\eql@decide@true{on,true,yes,enabled}
\def\eql@decide@false{off,false,no,disabled}
%    \end{macrocode}
%
%   \macro{\eql@decide@if}
%    \begin{macrocode}
\def\eql@decide@if#1#2#3#4#5{%
  \eql@decide@select{#1}{#2}{#3}{%
    {\eql@decide@true{#4}},%
    {\eql@decide@false{#5}}}}
%    \end{macrocode}
%
%   \macro{\eql@decide@bool}
% Store a boolean value into a conditional register:
%    \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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Key Declaration.}
%
%   \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 we can hide it
% 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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Options and Control Interface.}
%
%   \macro{\eql@nextopt}
%   \macro{\eql@nextopt@process}
% 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{%
  \eql@setkeys{#1}\eql@nextopt
  \let\eql@tagging@opt\eql@nextopt
  \global\let\eql@nextopt\@empty
}
%    \end{macrocode}
%
%   \imacro{\eqnaddopt}
%    \begin{macrocode}
\newcommand{\eqnaddopt}[1]{%
  \ifx\eql@nextopt\@empty
    \eql@append\eql@nextopt{#1}%
  \else
    \eql@append\eql@nextopt{,#1}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eqnlinesset}
% Process global configuration options
% including the package options:
%    \begin{macrocode}
\newcommand{\eqnlinesset}[1]{%
  \eql@setkeys{setup}{#1}%
  \ignorespaces
}
%    \end{macrocode}
%
%   \macro{\eql@control@default}
%    \begin{macrocode}
\protected\def\eql@control@default{%
  \eql@warn@here\eqncontrol
  \@gobble
}
\let\eqncontrol\eql@control@default
%    \end{macrocode}
%
%   \imacro{\eqncontrol}
% Macro for general-purpose control within equations using key-value pairs:
%    \begin{macrocode}
\newcommand{\eql@control}[1]{%
  \relax
  \eql@setkeys{control}{#1}%
  \ignorespaces
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Parameters and Registers}
%
% In the following, we collect parameter and register definitions.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Parameters}
%
% \TODO describe
%
% \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@layoutleft}
% The boolean parameter |\eql@layoutleft|
% specifies whether to use left or central alignment layout:
%    \begin{macrocode}
\let\eql@layoutleft\eql@false
%    \end{macrocode}
%
%   \macro{\eql@layoutleftmargin}
%   \macro{\eql@layoutleftmarginmin}
%   \macro{\eql@layoutleftmarginmax}
% The default width of the left margin in left alignment layout
% is specified by |\eql@layoutleftmargin|.
% It may be pushed down to |\eql@layoutleftmarginmin|
% and up to |\eql@layoutleftmarginmax|:
%    \begin{macrocode}
\def\eql@layoutleftmargin{\leftmargini}
\def\eql@layoutleftmarginmax{.5\maxdimen}
\def\eql@layoutleftmarginmin{\z@}
%    \end{macrocode}
%
%   \macro{\eql@mathstyle}
% The math style to be used within cells
% is specified by |\eql@mathstyle|:
%    \begin{macrocode}
\let\eql@mathstyle\displaystyle
%    \end{macrocode}
%
%   \ldimen{\eql@tagmargin@}
%   \ldimen{\eql@tagmargin@ratio@}
%   \macro{\eql@tagmargin@val}
%   \macro{\eql@tagmargin@threshold}
% The intended margin width for tags in centeral alignment layout
% is stored in |\eql@tagmargin@| which is sourced by |\eql@tagmargin@val|.
% An undefined |\eql@tagmargin@val| will compute the margin width
% as the maximum width of tags (without separation).
% |\eql@tagmargin@ratio@| describes the maximum ratio
% of lines with tags to total number of lines
% for which |\eql@tagmargin@| is set to zero:
% \TODO threshold
%    \begin{macrocode}
\newdimen\eql@tagmargin@
\let\eql@tagmargin@val\@undefined
\newdimen\eql@tagmargin@ratio@
\eql@tagmargin@ratio@\p@
\def\eql@tagmargin@threshold{0.5}
%    \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@
\let\eql@paddingleft@val\@undefined
\let\eql@paddingright@val\@undefined
%    \end{macrocode}
%
%   \macro{\eql@display@linewidth}
%   \macro{\eql@display@marginleft}
%   \macro{\eql@display@marginright}
% \TODO describe
%    \begin{macrocode}
\let\eql@display@linewidth\@undefined
\let\eql@display@marginleft\@undefined
\let\eql@display@marginright\@undefined
%    \end{macrocode}
%
%   \macro{\eql@box@colsep}
%   \macro{\eql@box@shortsep}
%   \macro{\eql@box@condsep}
% The macro |\eql@box@colsep| specifies the intercolumn separation
% for equation boxes:
% \TODO describe
%    \begin{macrocode}
\def\eql@box@colsep{2em}
\def\eql@box@shortsep{1em}
\def\eql@box@condsep{\eql@box@shortsep}
%    \end{macrocode}
%
%   \macro{\eql@break@line@sep}
%   \macro{\eql@break@line@shortsep}
%   \macro{\eql@break@col@sep}
%   \macro{\eql@break@col@shortsep}
% \TODO describe
%    \begin{macrocode}
\def\eql@break@line@sep{2em minus 1em}
\def\eql@break@line@shortsep{1em}
\def\eql@break@col@sep{2em minus 1em}
\def\eql@break@col@shortsep{1em}
%    \end{macrocode}
%
%   \macro{\eql@spread@val}
% The extra spread of equation lines is specified by |\eql@spread@val|:
%    \begin{macrocode}
\let\eql@spread@reset\eql@false
\def\eql@spread@val{\jot}
\newdimen\eql@spread@
%    \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}
%
%   \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:
%    \begin{macrocode}
\def\eql@display@height\@undefined
\def\eql@display@depth\@undefined
%    \end{macrocode}
%
%   \macro{\eql@skip@mode@short}
% The setting |\eql@skip@mode@short| 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}
\def\eql@skip@mode@short{2}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@skip@mode@cont@above{2}
\def\eql@skip@mode@cont@below{0}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@skip@mode@par@above{3}
\def\eql@skip@mode@par@below{0}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@skip@mode@top@above{4}
\def\eql@skip@mode@top@below{0}
%    \end{macrocode}
%
%    \begin{macrocode}
\newcount\eql@skip@mode@leave@
\let\eql@skip@force@leave\@undefined
%    \end{macrocode}
%
%   \macro{\eql@skip@force@above}
%   \macro{\eql@skip@force@below}
%   \tcounter{\eql@skip@mode@above@}
%   \tcounter{\eql@skip@mode@below@}
% 0: short, 1: long, 2: cont, 3: par, 4: top, 5: no, 6: med, 7: custom
%    \begin{macrocode}
\newcount\eql@skip@mode@above@
\newcount\eql@skip@mode@below@
\let\eql@skip@force@above\@undefined
\let\eql@skip@force@below\@undefined
\let\eql@skip@custom@above\@undefined
\let\eql@skip@custom@below\@undefined
%    \end{macrocode}
%
%   \macro{\eql@skip@cont@above}
% The glue when an equation is at the top of a horizontal list
% is specified by |\eql@skip@cont@above|:
%   \macro{\eql@skip@top@above}
%   \macro{\eql@skip@top@below}
% The glue when an equation is at the top of a vertical list
% is specified by |\eql@skip@top@above|
% and |\eql@skip@top@below|:
%   \macro{\eql@skip@par@above}
% The glue when an equation starts a paragraph
% is specified by |\eql@skip@par@above|:
%   \macro{\eql@skip@med@above}
%   \macro{\eql@skip@med@below}
% The surrounding glue for an equation with reduced spacing
% is given by |\eql@skip@med@above| and |\eql@skip@med@below|:
%
%    \begin{macrocode}
\def\eql@skip@long@above{\abovedisplayskip}
\def\eql@skip@long@below{\belowdisplayskip}
\def\eql@skip@short@above{\abovedisplayshortskip}
\def\eql@skip@short@below{\belowdisplayshortskip}
\def\eql@skip@cont@above{\eql@skip@short@above}
\def\eql@skip@cont@below{\eql@skip@short@below}
\def\eql@skip@par@above{\eql@skip@long@above}
\def\eql@skip@par@below{\eql@skip@long@below}
\def\eql@skip@top@above{\eql@skip@long@above}
\def\eql@skip@top@below{\eql@skip@long@below}
\def\eql@skip@med@above{\abovedisplayskip/2}
\def\eql@skip@med@below{\belowdisplayskip/2}
\def\eql@skip@tag@above{\z@skip}
\def\eql@skip@tag@below{\z@skip}
%    \end{macrocode}
%
%   \ldimen{\eql@colsepmin@}
%   \macro{\eql@colsepmin@val}
%   \macro{\eql@colsepmax@val}
% The minimum intercolumn separatation is specified by |\eql@colsepmin@|.
% This dimension register is set to |\eql@colsepmin@val|
% when entering the equation environments to allow font-dependent values.
% Furthermore, |\eql@colsepmax@val|
% specifies the maximum intercolumn separation:
%    \begin{macrocode}
\newdimen\eql@colsepmin@
\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
% \unskip\footnote{another half of a quad
% is left empty at the other end of the line.}
% in font number 2.
% As the tag is processed in text mode, we use |0.5em| instead.
%    \begin{macrocode}
\newdimen\eql@tagsepmin@
\def\eql@tagsepmin@val{.5\fontdimen6\textfont\tw@}
%    \end{macrocode}
%
%   \macro{\eql@equations@sqr@opt}
%   \macro{\eql@equations@ang@opt}
%   \macro{\eql@box@ang@opt}
% Store the default arguments for |\[|\,\ldots|\]| and |\<|\,\ldots|\>|,
% respectively:
%    \begin{macrocode}
\def\eql@equations@sqr@opt{equation,nonumber}
\def\eql@equations@ang@opt{align,nonumber}
\def\eql@box@ang@opt{align}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Multi-Line Align Mode.}
%
%    \begin{macrocode}
\let\eql@columns@fulllength\eql@false
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Registers}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{General.}
%
% \TODO describe
%    \begin{macrocode}
\newcount\eql@count@
\newdimen\eql@dimen@
\newskip\eql@skip@
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@display@container\@empty
%    \end{macrocode}
%
%   \lbox{\eql@cellbox@}
%   \lbox{\eql@tagbox@}
%   \ldimen{\eql@cellwidth@}
%   \ldimen{\eql@prevwidth@}
%   \ldimen{\eql@tagwidth@}
%   \ldimen{\eql@prevdepth@}
%   \tcounter{\eql@prevgraf@}
% The box |\eql@cellbox@| holds the present alignment component
% and |\eql@tagbox@| the tag for the present line.
% The corresponding dimensions |\eql@cellwidth@| and |\eql@tagwidth@|
% hold their widths.
% |\eql@prevwidth@| holds the width of the previous alignment component:
% \TODO adjust
%    \begin{macrocode}
\newbox\eql@cellbox@
\newbox\eql@tagbox@
\newdimen\eql@cellwidth@
\newdimen\eql@prevwidth@
\newdimen\eql@tagwidth@
\newdimen\eql@prevdepth@
\newcount\eql@prevgraf@
%    \end{macrocode}
%
%   \ldimen{\eql@totalwidth@}
%   \ldimen{\eql@tagwidth@max@}
%   \ldimen{\eql@totalheight@}
%    \begin{macrocode}
\newdimen\eql@totalwidth@
\newdimen\eql@tagwidth@max@
\newdimen\eql@totalheight@
\newdimen\eql@topheight@
\newdimen\eql@bottomdepth@
%    \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}
%
%   \ldimen{\eql@line@width@}
%   \ldimen{\eql@line@avail@}
%   \ldimen{\eql@line@pos@}
%   \tcounter{\eql@line@widthsep@}
%   \tcounter{\eql@line@availsep@}
%   \tcounter{\eql@line@possep@}
%   \ldimen{\eql@line@offset@}
%   \ldimen{\eql@line@prevdepth@}
%   \ldimen{\eql@line@interline@}
%    \begin{macrocode}
\newdimen\eql@line@width@
\newdimen\eql@line@avail@
\newdimen\eql@line@pos@
\newcount\eql@line@availsep@
\newcount\eql@line@widthsep@
\newcount\eql@line@possep@
\newdimen\eql@line@offset@
\newdimen\eql@line@prevdepth@
\newdimen\eql@line@interline@
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Rows and Columns.}
%
%   \tcounter{\eql@row@}
%   \tcounter{\eql@totalrows@}
%   \tcounter{\eql@tagrows@}
% \TODO tagrows
% |\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@
\newcount\eql@tagrows@
%    \end{macrocode}
%
%   \macro{\eql@column@}
%   \macro{\eql@totalcolumns@}
%    \begin{macrocode}
\newcount\eql@column@
\newcount\eql@totalcolumns@
%    \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}
%
%   \tcounter{\eql@intercolumns@}
%    \begin{macrocode}
\newcount\eql@intercolumns@
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Vertical Spacing Adjustments.}
%
%   \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@appendexpand\eql@display@container{%
      \eql@display@firstavail@\the#1\relax}%
  \fi
}
%    \end{macrocode}
%
% 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:
% \TODO adjust
%    \begin{macrocode}
\newdimen\eql@display@aboveextend@
\newdimen\eql@display@belowextend@
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Shared Registers.}
%
%   \lcond{\ifmeasuring@}
% All display environments get typeset twice -- once during a
% ``measuring'' phase and then again during a ``production'' phase.
% We reuse the original \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 \amsmath/ and not being catered for:
%    \begin{macrocode}
\ifdefined\measuring@true\else
  \expandafter\newif\csname ifmeasuring@\endcsname
\fi
\AddToHook{package/hyperref/after}{
  \ifdefined\Hy@ifnotmeasuring
    \renewcommand\Hy@ifnotmeasuring[1]{\ifmeasuring@\else#1\fi}
  \fi
}
%    \end{macrocode}
%
%   \lcond{\if@display}
% \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 \amsmath/ is absent,
% and initialise it:
%    \begin{macrocode}
\ifdefined\@displaytrue\else
  \expandafter\newif\csname if@display\endcsname
  \everydisplay\expandafter{\the\everydisplay\@displaytrue}
\fi
%    \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{Features}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{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}
%   \macro{\eql@punct@next}
%   \macro{\eql@punct@term}
%   \macro{\eql@punct@main}
% These macros store the punctuation character for columns, lines and blocks.
% An undefined value indicates that the punctuation should be handed
% down to the next lower level:
% \TODO update
%    \begin{macrocode}
\let\eql@punct@col\@empty
\let\eql@punct@line\@undefined
\let\eql@punct@block\@undefined
\let\eql@punct@next\@undefined
\let\eql@punct@term\@undefined
\let\eql@punct@main\@undefined
%    \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\@empty
%    \end{macrocode}
%
%   \macro{\eql@punct@term@set}
%   \macro{\eql@punct@term@stop}
% \TODO describe
%    \begin{macrocode}
\def\eql@punct@term@set{%
  \let\eql@punct@term\eql@punct@block}
\def\eql@punct@term@stop{%
  \global\let\eql@punct@term\relax}
%    \end{macrocode}
%
%   \macro{\eql@punct@set}
% \TODO describe
%    \begin{macrocode}
\def\eql@punct@relax{\relax}
\def\eql@punct@tilde{~}
\def\eql@punct@set#1#2{%
  \def#1{#2}%
  \ifx#1\eql@punct@relax
    \let#1\@undefined
  \fi
  \ifx#1\eql@punct@tilde
    \let#1\@empty
  \fi
}
\def\eql@punct@clear{%
  \let\eql@punct@col\@empty
  \let\eql@punct@line\@empty
  \let\eql@punct@main\@empty
}
%    \end{macrocode}
%
%   \imacro{\eqnpunct}
% Set the punction for columns, lines and blocks.
% Note that the macro |\eqnpunct| sets the punctuation for the
% following equation block or for the current cell.
% Starred versions clear the punctuation for the respectively levels:
%\TODO check operation of starred form, also for control
%    \begin{macrocode}
\newcommand{\eqnpunct}{%
  \eql@ifstar@tight\eql@punct@next@setrelax\eql@punct@next@set}
\def\eql@punct@next@set#1{%
  \ifmmode
    \eql@punct@set\eql@punct@next{#1}%
  \else
    \eqnaddopt{punct={#1}}%
  \fi
  \ignorespaces}
\def\eql@punct@next@setrelax{%
  \ifmmode
    \let\eql@punct@block\@undefined
  \else
    \eqnaddopt{punct*}%
  \fi
  \ignorespaces}
%    \end{macrocode}
%
%   \macro{\eql@punct@fill@next}
% Fill the next punctuation:
%    \begin{macrocode}
\def\eql@punct@fill@next#1{%
  \ifdefined\eql@punct@next\else
    \ifx\eql@punct@term\relax\else
      \let\eql@punct@next#1%
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@punct@output@next}
% Output the next punctuation.
% If non-empty, prepend some separation:
%    \begin{macrocode}
\def\eql@punct@output@next{%
  \ifx\eql@punct@next\@empty\else
    \eql@punct@sep
    \eql@punct@next
  \fi
  \let\eql@punct@next\@undefined
}
%    \end{macrocode}
%
%   \macro{\eql@punct@print@next}
% Print the next punctuation if available:
%    \begin{macrocode}
\def\eql@punct@print@next{%
  \ifdefined\eql@punct@next
    \eql@punct@output@next
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@punct@apply@next}
% Print the next punctuation if available.
% Stop further punctuation within the current group:
%    \begin{macrocode}
\def\eql@punct@apply@next{%
  \ifdefined\eql@punct@next
    \eql@punct@output@next
    \let\eql@punct@term\relax
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@punct@print@col}
% Print the punctuation for the present column:
%    \begin{macrocode}
\def\eql@punct@print@col{%
  \eql@punct@fill@next\eql@punct@col
  \eql@punct@print@next
}
%    \end{macrocode}
%
%   \macro{\eql@punct@apply@col}
% Output the punctuation for the present column.
% Stop further punctuation within the current group:
%    \begin{macrocode}
\def\eql@punct@apply@col{%
  \eql@punct@fill@next\eql@punct@col
  \eql@punct@apply@next
}
%    \end{macrocode}
%
% Output the punctuation for the present line unless disabled:
%   \macro{\eql@punct@print@line}
%    \begin{macrocode}
\def\eql@punct@print@line{%
  \eql@punct@fill@next\eql@punct@line
  \eql@punct@print@next
}
%    \end{macrocode}
%
% Output the punctuation for the present line unless disabled.
% Stop further punctuation within the current group:
%   \macro{\eql@punct@apply@line}
%    \begin{macrocode}
\def\eql@punct@apply@line{%
  \eql@punct@fill@next\eql@punct@line
  \eql@punct@apply@next
}
%    \end{macrocode}
%
%   \macro{\eql@punct@apply@block}
% Output the punctuation for the present block unless disabled.
% Stop further punctuation within the current group:
%    \begin{macrocode}
\def\eql@punct@apply@block{%
  \eql@punct@fill@next\eql@punct@block
  \eql@punct@apply@next
}
%    \end{macrocode}
%
%   \imacro{\eqnpunctapply}
% Output the terminal punctuation unless disabled.
% Stop further punctuation globally:
%    \begin{macrocode}
\newcommand{\eqnpunctapply}{%
  \ifmmode\else\unskip\fi
  \eql@punct@fill@next\eql@punct@term
  \eql@punct@print@next
  \global\let\eql@punct@term\relax
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{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@prevwidth@=\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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Framed Cells}
%
% \TODO describe
% \TODO warn if issued in even cells
%    \begin{macrocode}
\let\eql@frame@cmd\@undefined
\newdimen\eql@frame@margin@
\def\eql@frame@set[#1]{%
  \global\eql@append\eql@cell@container{\def\eql@frame@cmd{#1}}}
\protected\def\framecell{\eql@testopt@tight@ampsafe\eql@frame@set\fbox}
\def\eql@frame@measure{%
  \setbox\z@\hbox{\eql@frame@cmd{}}%
  \eql@frame@margin@.5\wd\z@
}
\def\eql@frame@print{%
  \setbox\eql@cellbox@\hbox{%
    \eql@frame@cmd{\unhbox\eql@cellbox@}%
  }%
}
\def\eql@frame@adjust{%
  \setbox\eql@cellbox@\hbox{%
    \eql@frame@cmd{%
      \unhbox\eql@cellbox@
      \unkern
      \unskip
    }%
    \hfil
    \kern\z@
  }%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Single-Line Composition}
%
% \TODO describe
%
%   \macro{\eql@break@line}
%   \macro{\eql@break@col}
%    \begin{macrocode}
\def\eql@break@line{%
  \let\eql@break@sep\eql@break@line@sep
  \let\eql@break@shortsep\eql@break@line@shortsep
  \let\eql@break@print\eql@punct@print@line
  \eql@ampprotect\eql@break@testall\eql@break@process}
\def\eql@break@col{%
  \let\eql@break@sep\eql@break@col@sep
  \let\eql@break@shortsep\eql@break@col@shortsep
  \let\eql@break@print\eql@punct@print@col
  \eql@ampprotect\eql@break@testall\eql@break@process}
%    \end{macrocode}
%
%   \macro{\eql@break@testall}
%   \macro{\eql@break@parse}
% \TODO describe
%    \begin{macrocode}
\def\eql@break@testall{\eql@parseopt@aux\eql@break@parse}
\def\eql@break@parse{%
  \ifx\eql@parseopt@token[%
    \let\eql@parseopt@next\eql@break@parse@val
  \fi
  \ifx\eql@parseopt@token*%
    \let\eql@parseopt@next\eql@break@parse@star
  \fi
  \ifx\eql@parseopt@token.%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token,%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token~%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token`%
    \let\eql@parseopt@next\eql@parseopt@punctnext
  \fi
}
\def\eql@break@parse@val[#1]{\def\eql@break@sep{#1}\eql@parseopt@peek}
\def\eql@break@parse@star#1{%
  \let\eql@break@sep\eql@break@shortsep\eql@parseopt@peek}
%    \end{macrocode}
%
%   \macro{\eql@break@process}
%    \begin{macrocode}
\def\eql@break@process{%
  \eql@break@print
  \hspace{\glueexpr\eql@break@sep\relax}}
%    \end{macrocode}
%
%   \macro{\eql@break@join}
%    \begin{macrocode}
\def\eql@break@join{\eql@srbgroup
  \eql@ifstar@tight
    {\eql@break@join@opt[\eql@break@col@shortsep]}%
    {\eql@testopt@tight\eql@break@join@opt\eql@break@col@sep}}
\def\eql@break@join@opt[#1]#2{\eql@sregroup%
  \hspace{\glueexpr#1\relax}#2\hspace{\glueexpr#1\relax}}
%    \end{macrocode}
%
%   \macro{\eqnsep}
%   \macro{\eqnbreak}
%   \macro{\eqnjoin}
% \TODO expand to lines and columns mode
%    \begin{macrocode}
\newcommand{\eqnsep}{\eql@break@col}
\newcommand{\eqnbreak}{\eql@break@line}
\newcommand{\eqnjoin}{\eql@break@join}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Alternative Content Description}
%
% \TODO describe
% \TODO would be nice to provide as environments as well
% \TODO implement for PDF tagging
%
%    \begin{macrocode}
\DeclareRobustCommand{\eqnalt}[2][]{}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Equation Numbering}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Supporting Definitions}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Parameters.}
%
%    \begin{macrocode}
\let\eql@tags@autolabel\eql@false
\let\eql@tags@autotag\eql@true
\let\eql@tags@warn\eql@true
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tags@name@generic{[equation]}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@tagpos@doconvert\eql@false
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tagpos@snap{4pt}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Registers.}
%
%    \begin{macrocode}
\let\eql@numbering@mode\@undefined
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@numbering@active\eql@true
\let\eql@numbering@multi\eql@true
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@tags@container\@undefined
\def\eql@tags@container@clear{%
  \let\eql@tags@label\@undefined
  \let\eql@tags@name\@undefined
  \let\eql@tags@tag\@undefined
  \let\eql@tags@ref\@undefined
  \let\eql@tags@anchor\@empty
  \eql@tagpos@shift@\z@
  \eql@tagpos@smashup@\z@
  \eql@tagpos@smashdown@\z@
  \let\eql@tagpos@reserve\eql@true
}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@tags@label\@undefined
\let\eql@tags@name\@undefined
\let\eql@tags@tag\@undefined
\let\eql@tags@ref\@undefined
\let\eql@tags@frame@cmd\@firstofone
%    \end{macrocode}
%
%   \tcounter{\eql@tags@glabel@}
%    \begin{macrocode}
\newcount\eql@tags@glabel@
\eql@tags@glabel@\z@
\def\eql@tags@glabel{equation.eql-\the\eql@tags@glabel@}
\def\eql@tags@glabel@step{\global\advance\eql@tags@glabel@\@ne}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@tagpos@continuous\eql@false
%    \end{macrocode}
%
%    \begin{macrocode}
\newcount\eql@tagpos@row@
\newcount\eql@tagpos@prevrow@
\newdimen\eql@tagpos@shift@
\newdimen\eql@tagpos@smashup@
\newdimen\eql@tagpos@smashdown@
\newdimen\eql@tagpos@current@
\newdimen\eql@tagpos@plain@
\newdimen\eql@tagpos@raised@
\newdimen\eql@tagpos@target@
\newdimen\eql@tagpos@headroom@
\newdimen\eql@tagpos@footroom@
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Schemes}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Table.}
%
%    \begin{macrocode}
\def\eql@numbering@tab@sub{sub}
\def\eql@numbering@tab@all{all}
\def\eql@numbering@tab@first{first}
\def\eql@numbering@tab@last{last}
\def\eql@numbering@tab@in{in}
\def\eql@numbering@tab@out{out}
\def\eql@numbering@tab@middle{middle}
\def\eql@numbering@tab@best{best}
\def\eql@numbering@tab@here{here}
\def\eql@numbering@tab@top{top}
\def\eql@numbering@tab@bottom{bottom}
\def\eql@numbering@tab@center{center}
\def\eql@numbering@tab@centerone{centerone}
\def\eql@numbering@tab@median{median}
\def\eql@numbering@tab@baseline{baseline}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@numbering@mode\eql@numbering@tab@all
\let\eql@numbering@mode@multi\eql@numbering@tab@all
\let\eql@numbering@mode@single\eql@numbering@tab@out
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\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@mid\eql@numbering@tab@middle
\let\eql@numbering@tab@outside\eql@numbering@tab@out
\let\eql@numbering@tab@inside\eql@numbering@tab@in
\let\eql@numbering@tab@within\eql@numbering@tab@in
\let\eql@numbering@tab@opt\eql@numbering@tab@best
\let\eql@numbering@tab@optimal\eql@numbering@tab@best
\let\eql@numbering@tab@pick\eql@numbering@tab@here
\let\eql@numbering@tab@med\eql@numbering@tab@median
\eql@letcs{eql@numbering@tab@center*}\eql@numbering@tab@baseline
\eql@letcs{eql@numbering@tab@center!}\eql@numbering@tab@centerone
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@tab@a\eql@numbering@tab@all
\let\eql@numbering@tab@s\eql@numbering@tab@sub
\let\eql@numbering@tab@f\eql@numbering@tab@first
\let\eql@numbering@tab@l\eql@numbering@tab@last
\let\eql@numbering@tab@o\eql@numbering@tab@out
\let\eql@numbering@tab@i\eql@numbering@tab@in
\let\eql@numbering@tab@h\eql@numbering@tab@here
\let\eql@numbering@tab@t\eql@numbering@tab@top
\let\eql@numbering@tab@b\eql@numbering@tab@bottom
\let\eql@numbering@tab@c\eql@numbering@tab@center
\let\eql@numbering@tab@m\eql@numbering@tab@median
\eql@letcs{eql@numbering@tab@+}\eql@numbering@tab@best
\eql@letcs{eql@numbering@tab@m*}\eql@numbering@tab@middle
\eql@letcs{eql@numbering@tab@c*}\eql@numbering@tab@baseline
\eql@letcs{eql@numbering@tab@c!}\eql@numbering@tab@centerone
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Implementations.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@init@all{\let\eql@numbering@multi\eql@true}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@init@sub{%
  \let\eql@numbering@multi\eql@true
  \ifdefined\eql@subequations@active
    \let\eql@numbering@mode\eql@numbering@tab@all
  \else
    \let\eql@numbering@subeq@use\eql@true
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@numbering@init@first{\eql@tagpos@row@\@ne}
\def\eql@numbering@init@last{\eql@tagpos@row@\@MM}
\def\eql@numbering@init@here{\eql@tagpos@row@\m@ne}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@init@in{%
  \ifdefined\eql@tagsleft
    \eql@numbering@init@last
  \else
    \eql@numbering@init@first
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@init@out{%
  \ifdefined\eql@tagsleft
    \eql@numbering@init@first
  \else
    \eql@numbering@init@last
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@eval@middle{%
  \ifnum\eql@tagpos@row@=\z@
    \eql@tagpos@row@\numexpr(\eql@totalrows@
        +\ifdefined\eql@tagsleft\z@\else\@ne\fi)/\tw@\relax
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@eval@best{%
  \ifnum\eql@tagpos@row@=\z@
    \let\eql@numbering@best@use\eql@true
    \eql@numbering@init@out
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@init@continuous{\let\eql@tagpos@continuous\eql@true}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@init@top\eql@numbering@init@continuous
\def\eql@tagpos@eval@top{%
  \eql@tagpos@current@\z@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@init@bottom\eql@numbering@init@continuous
\def\eql@tagpos@eval@bottom{%
  \eql@tagpos@current@\dimexpr\eql@totalheight@
      -\eql@tagheight@block@-\eql@tagdepth@block@\relax
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@init@center\eql@numbering@init@continuous
\def\eql@tagpos@eval@center{%
  \ifnum\eql@totalrows@=\@ne
    \eql@tagpos@row@\@ne
  \fi
  \eql@tagpos@current@\dimexpr(\eql@totalheight@
      -\eql@tagheight@block@-\eql@tagdepth@block@)/\tw@\relax
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@init@centerone\eql@numbering@init@continuous
\def\eql@tagpos@eval@centerone{%
  \eql@tagpos@current@\dimexpr(\eql@totalheight@
      -\eql@tagheight@block@-\eql@tagdepth@block@)/\tw@\relax
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@init@baseline\eql@numbering@init@continuous
\def\eql@tagpos@eval@baseline{%
  \eql@tagpos@current@\dimexpr(\eql@totalheight@
      +\eql@topheight@-\eql@bottomdepth@)/\tw@-\eql@tagheight@block@\relax
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@init@median\eql@numbering@init@continuous
\def\eql@tagpos@eval@median{%
  \ifnum\eql@tagpos@row@=\z@
    \ifodd\eql@totalrows@
      \eql@tagpos@row@\numexpr(\eql@totalrows@+\@ne)/\tw@\relax
    \else
      \eql@tagpos@row@\numexpr(\eql@totalrows@+\tw@)/\tw@\relax
      \eql@dimensions@get\eql@tagpos@row@
      \advance\eql@tagpos@shift@\dimexpr\eql@line@height@
          +(\eql@line@interline@-\eql@tagheight@block@
          +\eql@tagdepth@block@)/\tw@\relax
    \fi
    \ifnum\eql@totalrows@=\@ne
      \eql@tagpos@row@\@ne
    \else
      \eql@tagpos@adjust@eval@convert
      \eql@tagpos@row@\z@
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Selection.}
%
%    \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
    \ifx\eql@numbering@mode\eql@numbering@tab@all
      \let\eql@numbering@mode@multi\eql@numbering@mode
    \else\ifx\eql@numbering@mode\eql@numbering@tab@sub
      \let\eql@numbering@mode@multi\eql@numbering@mode
    \else
      \let\eql@numbering@mode@single\eql@numbering@mode
    \fi\fi
  \else
    \eql@error{numbering mode '#1' unknown: setting mode to 'all'}%
    \let\eql@numbering@mode\eql@numbering@tab@all
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@init{%
  \let\eql@numbering@multi\eql@false
  \let\eql@tagpos@continuous\eql@false
  \let\eql@numbering@subeq@use\eql@false
  \let\eql@numbering@best@use\eql@false
  \eql@tagpos@row@\z@
  \csname eql@numbering@init@\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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Interface}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Activation.}
%
% \TODO note |\nonumber| already defined, modifications by amsmath
%
%    \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}
\protected\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 reconsider operation
%   \imacro{\numberhere}
%    \begin{macrocode}
\protected\def\eql@numberhere{%
  \ifdefined\eql@numbering@multi
    \global\@eqnswtrue
  \else
    \global\eql@tagpos@row@\eql@row@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%   \imacro{\numbernext}
%    \begin{macrocode}
\protected\def\eql@numbernext{%
  \ifdefined\eql@numbering@multi
    \global\@eqnswfalse
  \else
    \ifdefined\eql@tagpos@continuous\else
      \ifnum\eql@tagpos@row@=\eql@row@
        \global\advance\eql@tagpos@row@\@ne
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Activation Trigger.}
%
%    \begin{macrocode}
\def\eql@tags@autoenable{%
  \global\@eqnswtrue
  \ifnum\eql@tagpos@row@=\m@ne
    \numberhere
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Labels.}
%
% \TODO describe
%
%   \macro{\eql@label@org}
%    \begin{macrocode}
\let\eql@label@org\label
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@label@gobble{\eql@ampprotect\eql@testopt@tight\eql@gobbleoptone{}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\protected\def\eql@label{%
  \eql@ampprotect\eql@testopt@tight\eql@tags@add@labelname\eql@testopt@default
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@add@labelname[#1]#2{%
  \def\eql@tmp{#1}%
  \ifx\eql@tmp\eql@testopt@default\else
    \eql@tags@add@name{#1}%
  \fi
  \eql@tags@add@label{#2}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@set@label#1{%
  \ifdefined\eql@tags@warn
    \ifdefined\eql@tags@label
      \eql@warn@label@multiple{#1}%
    \fi
  \fi
  \def\eql@tags@label{#1}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@set@name#1{%
  \ifdefined\eql@tags@warn
    \ifdefined\eql@tags@name
      \eql@warn@name@multiple
    \fi
  \fi
  \def\eql@tags@name{#1}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@add@label#1{%
  \ifdefined\eql@tags@autolabel
    \eql@tags@autoenable
  \fi
  \global\eql@appendexpand\eql@tags@container{%
    \noexpand\eql@tags@set@label{#1}}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@add@name#1{%
  \protected@edef\eql@tmp{\noexpand\eql@tags@set@name{#1}}%
  \global\eql@appendmacro\eql@tags@container\eql@tmp
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@addblock@label#1{%
  \eql@appendexpand\eql@tags@container@block{%
    \noexpand\eql@tags@set@label{#1}}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@addblock@name#1{%
  \protected@edef\eql@tmp{\noexpand\eql@tags@set@name{#1}}%
  \eql@appendmacro\eql@tags@container@block\eql@tmp
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tags.}
%
% \TODO describe
%
%   \macro{\eql@tag@default}
%    \begin{macrocode}
\protected\def\eql@tag@default{%
  \eql@warn@here\tag
  \eql@tag@gobble
}
\let\tag\eql@tag@default
%    \end{macrocode}
%
%   \macro{\eql@tag@gobble}
%    \begin{macrocode}
\def\eql@tag@gobble{%
  \eql@ampprotecttwo\eql@teststaropt@tight\eql@gobbleoptone\eql@gobbleoptone{}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\protected\def\eql@tag{%
  \eql@ampprotecttwo\eql@teststaropt@tight
    {\eql@tags@add@tagform@off\eql@tags@add@tagref}{\eql@tags@add@tagref}
    \eql@testopt@default
}
%    \end{macrocode}
%
%   \macro{\eql@tags@add@tagref}
%    \begin{macrocode}
\def\eql@tags@add@tagref[#1]#2{%
  \def\eql@tmp{#1}%
  \ifx\eql@tmp\eql@testopt@default\else
    \eql@tags@add@ref{#1}%
  \fi
  \eql@tags@add@tag{#2}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@set@tag#1{%
  \ifdefined\eql@tags@warn
    \ifdefined\eql@tags@tag
      \eql@warn@tag@multiple
    \fi
  \fi
  \def\eql@tags@tag{#1}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@set@ref#1{%
  \ifdefined\eql@tags@warn
    \ifdefined\eql@tags@ref
      \eql@warn@ref@multiple
    \fi
  \fi
  \def\eql@tags@ref{#1}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@add@tag#1{%
  \ifdefined\eql@tags@autotag
    \eql@tags@autoenable
  \fi
  \protected@edef\eql@tmp{\noexpand\eql@tags@set@tag{#1}}%
  \global\eql@appendmacro\eql@tags@container\eql@tmp
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@add@ref#1{%
  \protected@edef\eql@tmp{\noexpand\eql@tags@set@ref{#1}}%
  \global\eql@appendmacro\eql@tags@container\eql@tmp
}
%    \end{macrocode}
%
%   \macro{\eql@tags@add@tagform@off}
%    \begin{macrocode}
\def\eql@tags@add@tagform@off{%
  \global\eql@append\eql@tags@container{\let\eql@tags@tagform\@firstofone}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@addblock@tag#1{%
  \protected@edef\eql@tmp{\noexpand\eql@tags@set@tag{#1}}%
  \eql@appendmacro\eql@tags@container@block\eql@tmp
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@addblock@ref#1{%
  \protected@edef\eql@tmp{\noexpand\eql@tags@set@ref{#1}}%
  \eql@appendmacro\eql@tags@container@block\eql@tmp
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@addblock@tagform@off{%
  \eql@append\eql@tags@container@block{\let\eql@tags@tagform\@firstofone}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Raise Tags.}
%
%   \macro{\raisetag}
%    \begin{macrocode}
\def\eql@raisetag@default{%
  \eql@warn@here\raisetag
  \eql@raisetag@gobble
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@raisetag@gobble{%
  \eql@ampprotecttwo\eql@ifstar@tight\@gobble\@gobble
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@amsmath@let\raisetag\eql@raisetag@default
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@raisetag{%
  \eql@ampprotecttwo\eql@ifstar@tight\eql@tags@add@raiseshift\eql@raisetag@test
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@raisetag@test#1{%
  \def\eql@tmpa{#1}\def\eql@tmpb{!}%
  \ifx\eql@tmpa\eql@tmpb
    \eql@tags@add@forceraise
  \else
    \eql@tags@add@raisesmash{#1}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tags@add@raiseshift#1{%
  \global\eql@appendexpand\eql@tags@container{%
    \advance\eql@tagpos@shift@\the\glueexpr#1\relax\relax}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tags@add@raisesmash#1{%
  \dimen@\glueexpr#1\relax
  \ifdim\dimen@<\z@
    \global\eql@appendexpand\eql@tags@container{%
      \advance\eql@tagpos@smashdown@-\the\dimen@\relax}%
  \else
    \global\eql@appendexpand\eql@tags@container{%
      \advance\eql@tagpos@smashup@\the\dimen@\relax}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@tags@add@forceraise{%
  \global\eql@append\eql@tags@container{\let\eql@tagpos@reserve\eql@false}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Integration}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Support.}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@settools{%
  \let\label\eql@label
  \let\tag\eql@tag
  \let\raisetag\eql@raisetag
  \let\numberhere\eql@numberhere
  \let\numbernext\eql@numbernext
}
%    \end{macrocode}
%
% \TODO not necessary anymore
%    \begin{macrocode}
\def\eql@numbering@settools@gobble{%
  \let\label\eql@label@gobble
  \let\tag\eql@tag@gobble
  \let\raisetag\eql@raisetag@gobble
  \let\numberhere\relax
  \let\numbernext\relax
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@numbering@autoblock{%
  \begingroup
    \let\eql@tags@warn\eql@false
    \eql@tags@container@block
    \ifdefined\eql@tags@autolabel
      \ifdefined\eql@tags@label
        \global\@eqnswtrue
      \fi
    \fi
    \ifdefined\eql@tags@autotag
      \ifdefined\eql@tags@tag
        \global\@eqnswtrue
      \fi
    \fi
  \endgroup
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@numbering@warnunused{%
  \ifdefined\eql@tags@label
    \eql@warn@label@unused
  \fi
  \ifdefined\eql@tags@name
    \eql@warn@name@unused
  \fi
  \ifdefined\eql@tags@tag
    \eql@warn@tag@unused
  \fi
  \ifdefined\eql@tags@erf
    \eql@warn@ref@unused
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Single Line.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@single@init{%
  \let\eql@numbering@multi\eql@false
  \eql@numbering@settools
  \eql@numbering@eqnswinit
  \eql@numbering@autoblock
  \global\let\eql@tags@container\eql@tags@container@block
  \let\eql@tags@warn\eql@true
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@numbering@single@eval{%
  \ifnum\eql@tagpos@row@=\m@ne
    \@eqnswfalse
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Multi-Line Measuring Pass.}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@measure@init{%
  \eql@numbering@settools
  \ifdefined\eql@numbering@multi\else
    \eql@numbering@eqnswinit
    \eql@numbering@autoblock
  \fi
  \global\let\eql@tags@container\eql@tags@container@block
  \let\eql@tags@warn\eql@true
}
%    \end{macrocode}
%
% \TODO might select only relevant routines in init
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@measure@line@begin{%
  \ifdefined\eql@numbering@multi
    \global\eql@numbering@eqnswinit
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@measure@blocktag{%
  \ifdefined\eql@numbering@multi
    \@eqnswfalse
  \else
    \ifnum\eql@tagpos@row@=\m@ne
      \@eqnswfalse
    \fi
    \ifnum\eql@totalrows@=\z@
      \@eqnswfalse
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Multi-Line Print Pass.}
%
% \TODO describe
%
% \TODO can we be absolutely sure about all values being preserved
% global might pick up a value from a higher level block and
% restore it globally!
%    \begin{macrocode}
\def\eql@numbering@print@init{%
  \let\eql@tags@warn\eql@false
  \ifdefined\eql@numbering@multi
    \eql@numbering@settools
    \global\let\eql@tags@container\eql@tags@container@block
  \else
    \let\eql@tags@container@block\eql@tags@container
    \eql@numbering@settools@gobble
  \fi
}
%    \end{macrocode}
%
% \TODO might select only relevant routines in init
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@print@block@begin{%
  \ifdefined\eql@numbering@multi\else
    \ifnum\eql@tagpos@row@>\z@
      \eql@tags@makeblockanchor
      \global\eql@appendexpand\eql@tags@container@block{%
        \def\noexpand\eql@tags@anchor{%
          \unexpanded\expandafter{\eql@tags@anchor}}}%
    \fi
  \fi
  \ifdefined\eql@numbering@subeq@use
    \eql@tags@printsubeqlabel
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@print@line@begin{%
  \ifdefined\eql@numbering@multi
    \global\eql@numbering@eqnswinit
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@print@line@eval{%
  \ifdefined\eql@numbering@multi
    \if@eqnsw
      \eql@tags@container
    \fi
  \else
    \ifnum\eql@tagpos@row@=\eql@row@
      \@eqnswtrue
      \eql@tags@container@block
    \else
      \@eqnswfalse
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Positioning}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@single@eval{%
  \if@eqnsw
    \csname eql@tagpos@eval@\eql@numbering@mode\endcsname
    \ifnum\eql@tagpos@row@>\@ne
      \eql@tagpos@row@\@ne
    \fi
    \ifdefined\eql@tagpos@doconvert
      \let\eql@tagpos@continuous\eql@true
    \fi
    \ifdefined\eql@tagpos@continuous
      \eql@tagpos@single@eval@continuous
    \fi
  \else
    \eql@tagpos@row@\z@
  \fi
  \eql@tagpos@prevrow@\z@
  \eql@tagpos@headroom@\z@
  \eql@tagpos@footroom@\z@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@single@eval@continuous{%
  \ifnum\eql@tagpos@row@>\z@
    \eql@tagpos@target@\eql@tagpos@shift@
  \else
    \eql@tagpos@target@\dimexpr\eql@line@height@
        -\eql@tagpos@current@+\eql@tagpos@shift@-\eql@tagheight@block@\relax
  \fi
  \eql@tagpos@row@\@ne
  \ifdim\ifdim\eql@tagpos@target@<\z@-\fi
      \eql@tagpos@target@<\glueexpr\eql@tagpos@snap\relax
    \eql@tagpos@target@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@adjust@eval{%
  \if@eqnsw
    \csname eql@tagpos@eval@\eql@numbering@mode\endcsname
    \ifnum\eql@tagpos@row@>\eql@totalrows@
      \eql@tagpos@row@\eql@totalrows@
    \fi
    \ifdefined\eql@tagpos@doconvert
      \let\eql@tagpos@continuous\eql@true
    \fi
    \ifdefined\eql@tagpos@continuous
      \ifnum\eql@tagpos@row@>\z@
        \eql@tagpos@adjust@eval@convert
      \fi
      \eql@tagpos@adjust@eval@continuous
    \fi
  \else
    \eql@tagpos@row@\z@
    \eql@tagpos@prevrow@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@adjust@eval@convert{%
  \eql@tagpos@current@\z@
  \eql@dimensions@for{%
    \ifnum\eql@row@<\eql@tagpos@row@
      \advance\eql@tagpos@current@\dimexpr\eql@line@interline@
          +\eql@line@height@+\eql@line@depth@\relax
    \fi
    \ifnum\eql@row@=\eql@tagpos@row@
      \advance\eql@tagpos@current@\dimexpr\eql@line@interline@
          +\eql@line@height@-\eql@tagheight@block@\relax
    \fi
  }%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@adjust@eval@continuous{%
  \dimen@\dimexpr\eql@tagpos@current@-\eql@tagpos@shift@\relax
  \eql@tagpos@row@\eql@totalrows@
  \eql@tagpos@prevrow@\z@
  \eql@tagpos@headroom@\z@
  \eql@tagpos@footroom@\z@
  \eql@dimensions@for{%
    \ifnum\eql@tagpos@row@=\eql@totalrows@
      \eql@tagpos@headroom@\eql@line@interline@
      \eql@tagpos@target@\dimexpr\eql@line@interline@
          +\eql@line@height@-\dimen@-\eql@tagheight@block@\relax
      \ifdim\ifdim\eql@tagpos@target@<\z@-\fi
          \eql@tagpos@target@<\glueexpr\eql@tagpos@snap\relax
        \advance\dimen@\eql@tagpos@target@
        \eql@tagpos@target@\z@
      \fi
      \ifdim\eql@tagpos@target@>%
          \ifdefined\eql@tagsleft-1sp\relax\else\z@\fi
        \eql@tagpos@row@\eql@row@
        \eql@tagpos@prevrow@\numexpr\eql@row@-\@ne\relax
      \fi
      \advance\dimen@-\dimexpr\eql@line@interline@
          +\eql@line@depth@+\eql@line@height@\relax
    \fi
    \ifnum\eql@row@=\numexpr\eql@tagpos@row@+\@ne\relax
      \eql@tagpos@footroom@\eql@line@interline@
    \fi
  }%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@print@line@eval{%
  \ifdefined\eql@tagpos@continuous
    \eql@tagpos@print@line@eval@continuous
  \else
    \eql@tagpos@print@line@eval@discrete
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@print@line@eval@continuous{%
  \if@eqnsw
    \ht\eql@tagbox@\dimexpr\ht\eql@tagbox@-\eql@tagpos@smashup@\relax
    \dp\eql@tagbox@\dimexpr\dp\eql@tagbox@-\eql@tagpos@smashdown@\relax
    \eql@tagpos@plain@\eql@tagpos@target@
    \@tempdima\dimexpr\eql@line@height@+\eql@tagpos@headroom@
        -\ht\eql@tagbox@\relax
    \@tempdimb\dimexpr-\eql@line@depth@-\eql@tagpos@footroom@
        +\dp\eql@tagbox@\relax
    \ifnum\eql@row@=\@ne
      \@tempdima.5\maxdimen
    \fi
    \ifnum\eql@row@=\eql@totalrows@
      \@tempdimb-.5\maxdimen
    \fi
    \ifdim\eql@tagpos@plain@>\@tempdima
      \ifdim\eql@tagpos@plain@>\@tempdimb
        \ifdim\@tempdima>\@tempdimb
          \eql@tagpos@plain@\@tempdima
        \else
          \eql@tagpos@plain@\@tempdimb
        \fi
      \fi
    \else
      \ifdim\eql@tagpos@plain@<\@tempdimb
        \ifdim\@tempdima>\@tempdimb
          \eql@tagpos@plain@\@tempdimb
        \else
          \eql@tagpos@plain@\@tempdima
        \fi
      \fi
    \fi
    \ifnum\eql@tagpos@prevrow@>\z@
      \eql@tagpos@raised@\dimexpr\eql@line@height@+\dp\eql@tagbox@\relax
      \ifdim\eql@tagpos@raised@>\eql@tagpos@plain@\else
        \eql@tagpos@raised@\eql@tagpos@plain@
        \let\eql@tagpos@reserve\eql@false
      \fi
    \else
      \ifdim\eql@tagpos@target@>%
          \ifdefined\eql@tagsleft-1sp\relax\else\z@\fi
        \eql@tagpos@raised@\dimexpr\eql@line@height@+\dp\eql@tagbox@\relax
        \ifdim\eql@tagpos@raised@>\eql@tagpos@plain@\else
          \eql@tagpos@raised@\eql@tagpos@plain@
          \let\eql@tagpos@reserve\eql@false
        \fi
      \else
        \eql@tagpos@raised@\dimexpr-\eql@line@depth@
            -\ht\eql@tagbox@\relax
        \ifdim\eql@tagpos@raised@<\eql@tagpos@plain@\else
          \eql@tagpos@raised@\eql@tagpos@plain@
          \let\eql@tagpos@reserve\eql@false
        \fi
      \fi
    \fi
  \else
    \ifnum\eql@tagpos@prevrow@=\eql@row@
      \eql@tagwidth@\eql@tagwidth@block@
    \else
      \let\eql@tagpos@reserve\eql@false
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@print@line@eval@discrete{%
  \if@eqnsw
    \ht\eql@tagbox@\dimexpr\ht\eql@tagbox@-\eql@tagpos@smashup@\relax
    \dp\eql@tagbox@\dimexpr\dp\eql@tagbox@-\eql@tagpos@smashdown@\relax
    \eql@tagpos@plain@\eql@tagpos@shift@
    \eql@tagpos@headroom@\z@
    \eql@tagpos@footroom@\z@
    \ifdim\eql@tagpos@shift@>%
          \ifdefined\eql@tagsleft-1sp\relax\else\z@\fi
      \eql@tagpos@raised@\dimexpr\eql@line@height@+\dp\eql@tagbox@\relax
    \else
      \eql@tagpos@raised@\dimexpr-\eql@line@depth@-\ht\eql@tagbox@\relax
    \fi
  \else
    \let\eql@tagpos@reserve\eql@false
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagpos@print@line@end{%
  \ifdefined\eql@tagpos@continuous
    \ifnum\eql@tagpos@prevrow@=\eql@row@
      \ifdefined\eql@tagpos@reserve
        \global\eql@appendexpand\eql@tags@container@block{%
          \advance\eql@tagpos@headroom@\the\dimexpr\eql@line@height@
              +\eql@line@depth@\relax\relax}%
        \eql@displaybreak@star\@M
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Component Display}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Showkeys Integration.}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@SK@loaded\eql@false
\let\eql@SK@label\@gobble
\let\eql@SK@clearlabel\@empty
\let\eql@SK@setlabel\@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@loaded\eql@true
  \def\eql@SK@label#1{\SK@\SK@@label#1}
  \def\eql@SK@clearlabel{\let\eql@SK@lab\relax}
  \eql@SK@clearlabel
  \def\eql@SK@@label#1>#2\SK@{%
    \def\eql@SK@lab{\smash{\SK@labelcolor\showkeyslabelformat{#2}}}%
  }
  \def\eql@SK@setlabel#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@clearlabel
    \fi
  }
  \def\eql@SK@printlabel@left{%
    \ifx\eql@SK@lab\relax\else
      \llap{\eql@SK@lab\kern\marginparsep}%
      \eql@SK@clearlabel
    \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@clearlabel
      \else
        \rlap{%
          \dimen@\displaywidth
          \advance\dimen@\marginparsep
          \kern\dimen@
          \eql@SK@lab
        }%
      \fi
      \eql@SK@clearlabel
      \prevdepth\dimen@
    \fi
  }
  \let\eql@label@org\label
  \def\eql@label@clean{\let\SK@\@gobbletwo\eql@label@org}
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Labels.}
%
%   \macro{\eql@composetag@label}
% \TODO describe
%    \begin{macrocode}
\def\eql@composetag@label{%
  \eql@SK@clearlabel
  \ifdefined\eql@tags@label
    \eql@SK@setlabel\eql@tags@label
    \ifdefined\eql@tags@name
      \let\@currentlabelname\eql@tags@name
    \else
      \let\@currentlabelname\eql@tags@name@generic
    \fi
    \expandafter\eql@label@clean\expandafter{\eql@tags@label}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@printsubeqlabel{%
  \eql@tags@container@parent
  \ifdefined\eql@tags@label
    \eql@tags@makeblockanchor
    \eql@SK@setlabel\eql@tags@label
    \begingroup
      \def\@currentcounter{equation}%
      \eql@tags@anchor
      \let\@currentlabelname\eql@tags@name@generic
      \protected@edef\@currentlabel{\p@equation\theparentequation}%
      \expandafter\eql@label@clean\expandafter{\eql@tags@label}%
    \endgroup
    \eql@SK@printlabel@line
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Hyperref Anchors.}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@Hy@anchor\@gobble
\AddToHook{package/hyperref/after}{
  \def\eql@Hy@anchor#1{%
    \Hy@raisedlink{\hyper@anchor{#1}}%
  }%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@makeblockanchor{%
  \eql@tags@glabel@step
  \eql@Hy@anchor\eql@tags@glabel
  \edef\eql@tags@anchor{%
    \def\noexpand\thepage{\thepage}%
    \def\noexpand\@currentHref{\eql@tags@glabel}%
  }%
}
%    \end{macrocode}
%
% \TODO describe
%
%   \macro{\eql@composetag@anchor}
%    \begin{macrocode}
\def\eql@composetag@anchor{%
  \ifdefined\eql@tags@tag
    \def\@currentcounter{equation}%
    \ifdefined\eql@tags@ref
      \let\@currentlabel\eql@tags@ref
    \else
      \protected@edef\@currentlabel{\p@equation\eql@tags@tag}%
    \fi
    \eql@tags@glabel@step
    \edef\@currentHref{\eql@tags@glabel}%
    \eql@Hy@anchor\@currentHref
  \else
    \refstepcounter{equation}%
    \protected@edef\eql@tags@tag{\theequation}%
  \fi
  \eql@tags@anchor
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tag Layout.}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@tags@taglayout@set@direct#1{%
  \def\eql@tags@taglayout##1{#1}%
}
\def\eql@tags@taglayout@set#1{%
  \def\eql@tags@taglayout##1{\hbox{\m@th\normalfont#1}}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tags@tagform@set@direct#1{%
  \def\eql@tags@tagform##1{#1}%
}
\def\eql@tags@tagform@set#1#2#3{%
  \def\eql@tags@tagform##1{#1\ignorespaces#2\unskip\@@italiccorr#3}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\eql@tags@taglayout@set{#1}
\eql@tags@tagform@set({#1})
\def\eql@tags@tagcompose#1{\eql@tags@taglayout{\eql@tags@tagform{#1}}}
%    \end{macrocode}
%
%    \begin{macrocode}
\protected\def\tagform{\eql@tags@tagform}
\protected\def\tagbox{\eql@tags@taglayout}
\protected\def\tagboxed{\eql@tags@tagcompose}
%    \end{macrocode}
%
%   \macro{\eqref}
% \amsmath/ defines the macro |\eqref|
% to refer to equation labels in a proper format.
% We provide it for completeness:
%    \begin{macrocode}
\protected\def\eql@eqref#1{\textup{\eql@tags@tagcompose{\ref{#1}}}}
%    \end{macrocode}
%
%   \macro{\eql@composetag@tag}
% \TODO describe
%    \begin{macrocode}
\def\eql@composetag@tag{%
  \eql@tagging@tagbegin
  \eql@tags@frame@cmd{%
    \eql@tags@taglayout{%
      \eql@tags@tagform\eql@tags@tag
      \eql@tagging@tagsave
    }%
  }%
  \eql@tagging@tagend
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Tag Composition}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@composetag@measure{%
  \ifdefined\eql@tags@tag\else
    \stepcounter{equation}%
    \let\eql@tags@tag\theequation
  \fi
  \eql@tags@frame@cmd{\eql@tags@taglayout{\eql@tags@tagform\eql@tags@tag}}%
  \ifdefined\eql@numbering@multi
    \global\let\eql@tags@container\eql@tags@container@clear
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@composetag@print{%
  \eql@composetag@anchor
  \eql@composetag@label
  \ifdefined\eql@tagsleft
    \eql@SK@printlabel@left
    \eql@composetag@tag
  \else
    \eql@composetag@tag
    \eql@SK@printlabel@right
  \fi
  \global\let\eql@tags@container\eql@tags@container@clear
}
%    \end{macrocode}
%
% \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@adjustheadroom{%
  \dimen@\dimexpr\ht\eql@tagbox@+\eql@tagpos@current@-\eql@line@height@\relax
  \ifdim\dimen@>\z@
    \ifdim\dimen@>\eql@tagpos@headroom@
      \ht\eql@tagbox@\dimexpr\ht\eql@tagbox@-\eql@tagpos@headroom@\relax
    \else
      \ht\eql@tagbox@\dimexpr\eql@line@height@-\eql@tagpos@current@\relax
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@adjustfootroom{%
  \dimen@\dimexpr\dp\eql@tagbox@-\eql@tagpos@current@-\eql@line@depth@\relax
  \ifdim\dimen@>\z@
    \ifdim\dimen@>\eql@tagpos@footroom@
      \dp\eql@tagbox@\dimexpr\dp\eql@tagbox@-\eql@tagpos@footroom@\relax
    \else
      \dp\eql@tagbox@\dimexpr\eql@line@depth@+\eql@tagpos@current@\relax
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@extendabove{%
  \dimen@\dimexpr\ht\eql@tagbox@+\eql@tagpos@current@-\eql@line@height@\relax
  \ifdim\dimen@>\z@
    \global\eql@appendexpand\eql@display@container{%
      \eql@display@aboveextend@\the\dimen@\relax}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@extendbelow{%
  \dimen@\dimexpr\dp\eql@tagbox@-\eql@tagpos@current@-\eql@line@depth@\relax
  \ifdim\dimen@>\z@
    \global\eql@appendexpand\eql@display@container{%
      \eql@display@belowextend@\the\dimexpr\dimen@\relax}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@prepare{%
  \ifdefined\eql@tagpos@reserve
    \eql@tagpos@current@\eql@tagpos@plain@
  \else
    \eql@tagpos@current@\eql@tagpos@raised@
  \fi
  \ifdim\eql@tagpos@headroom@>\z@
    \eql@tagbox@print@adjustheadroom
  \fi
  \ifdim\eql@tagpos@footroom@>\z@
    \eql@tagbox@print@adjustfootroom
  \fi
  \ifnum\eql@row@=\@ne
    \eql@tagbox@print@extendabove
  \fi
  \ifnum\eql@row@=\eql@totalrows@
    \eql@tagbox@print@extendbelow
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@tagsright{%
  \eql@tagbox@print@prepare
  \kern-\wd\eql@tagbox@
  \raise\eql@tagpos@current@\box\eql@tagbox@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@tagbox@print@tagsleft{%
  \eql@display@firstavail@set\z@
  \eql@tagbox@print@prepare
  \wd\eql@tagbox@\z@
  \raise\eql@tagpos@current@\box\eql@tagbox@
}
%    \end{macrocode}
%
%   \macro{\eql@tagbox@print@cell}
%    \begin{macrocode}
\def\eql@tagbox@print@cell{%
  \eql@tagging@tagaddbox
  \ifdefined\eql@tagsleft
    \ifdefined\eql@tagpos@reserve
      \ifdim\eql@tagwidth@>\dimexpr\eql@line@avail@+\eql@tagfuzz@\relax
        \let\eql@tagpos@reserve\eql@false
      \fi
    \fi
    \if@eqnsw
      \eql@tagbox@print@tagsleft
    \fi
    \kern\displaywidth
  \else
    \kern\displaywidth
    \ifdefined\eql@tagpos@reserve
      \ifdim\eql@tagwidth@>%
          \dimexpr\displaywidth-\eql@line@width@+\eql@tagfuzz@\relax
        \let\eql@tagpos@reserve\eql@false
      \fi
    \fi
    \if@eqnsw
      \eql@tagbox@print@tagsright
    \fi
  \fi
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Subequation Numbering}
%
% We replicate the \amsmath/ functionality to
% number a block of equations with a common number and
% a sub-numbering.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Definitions}
%
%   \lcounter{parentequation}
% We define a counter to store the main equation number
% while in subequation mode.
% It makes sense to share this definition
% with \amsmath/ as |parentequation|,
% and we need to undefine it when \amsmath/
% is loaded at a later stage:
%    \begin{macrocode}
\eql@amsmath@undefine\c@parentequation
\eql@amsmath@undefine\theparentequation
\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}%
  \eql@tags@container@block
  \ifdefined\eql@tags@tag
    \eql@tags@glabel@step
    \protected@edef\theHparentequation{\eql@tags@glabel}%
    \protected@edef\theparentequation{\eql@tags@tag}%
  \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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Environment}
%
%   \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@tags@printsubeqlabel|
%    \begin{macrocode}
\def\eql@subequations@start{%
  \let\eql@tags@container@block\eql@tags@container@clear
  \eql@nextopt@process{subequations}%
  \eql@subequations@init
  \eql@tags@glabel@step
  \edef\eql@subequations@currentHref{\eql@tags@glabel}%
  \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}%
  \eql@tags@container@block
  \ifdefined\eql@tags@name
    \let\@currentlabelname\eql@tags@name
  \else
    \let\@currentlabelname\eql@tags@name@generic
  \fi
  \let\eql@subequations@active\eql@true
  \ifdefined\eql@tags@label
    \eql@SK@label\eql@tags@label
  \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@
    \eql@tags@container@block
    \ifdefined\eql@tags@label
      \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}%
        \ifdefined\eql@tags@name
          \let\@currentlabelname\eql@tags@name
        \else
          \let\@currentlabelname\eql@tags@name@generic
        \fi
        \expandafter\eql@label@clean\expandafter{\eql@tags@label}%
      \endgroup
    \fi
  \fi
  \eql@subequations@close
}
%    \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}{%
  \eql@verbose@info\eql@verbose@msg@enterenv
  \eql@subequations@testall\eql@subequations@start%
}{%
  \eql@subequations@end
  \ignorespacesafterend
  \eql@verbose@info\eql@verbose@msg@leaveenv
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@subequations@testall{\eql@parseopt@main\eql@subequations@parse}
\def\eql@subequations@parse{%
  \ifx\eql@parseopt@token[%]
    \let\eql@parseopt@next\eql@parseopt@opt
  \fi
  \ifx\eql@parseopt@token\eql@atxi
    \let\eql@parseopt@next\eql@parseopt@label
  \fi
  \ifx\eql@parseopt@token\eql@atxii
    \let\eql@parseopt@next\eql@parseopt@label
  \fi
  \ifx\eql@parseopt@token\label
    \let\eql@parseopt@next\eql@parseopt@end
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Subequation Scheme}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@numbering@subeq@init{%
  \let\eql@save@theequation\theequation
  \let\eql@save@theHequation\theHequation
  \eql@subequations@init
  \let\eql@tags@container@parent\eql@tags@container@block
  \let\eql@tags@container@block\eql@tags@container@clear
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@subeq@test{%
  \ifnum\eql@tagrows@<\tw@
    \let\eql@tags@container@block\eql@tags@container@parent
    \let\eql@numbering@subeq@use\eql@false
    \let\theequation\eql@save@theequation
    \let\theHequation\eql@save@theHequation
    \eql@subequations@restorecounter
  \fi
}
%    \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
%
%    \begin{macrocode}
\let\eql@display@injectbefore\@undefined
\let\eql@display@injectafter\@undefined
\let\eql@interline@container\@undefined
\def\eql@interline@container@clear{%
  \eql@displaybreak@pen@\@MM
  \eql@vspaceskip@\z@skip
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \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}
\protected\def\eql@displaybreak@default{%
  \eql@warning{Invalid use of \string\displaybreak}{}%
  \eql@teststaroropt@loose\@gobble\eql@gobbleopt{}}
\eql@amsmath@after{\let\eql@displaybreak@default\displaybreak}
\eql@amsmath@let\displaybreak\eql@displaybreak@default
%    \end{macrocode}
%
%    \begin{macrocode}
\newcount\eql@displaybreak@pen@
\newcount\eql@displaybreak@prepen@
\newcount\eql@displaybreak@postpen@
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\protected\def\eql@displaybreak{%
  \relax
  \eql@ampprotecttwo\eql@teststaroropt@tight
    \eql@displaybreak@star\eql@displaybreak@level{4}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@displaybreak@star#1{%
  \global\eql@appendexpand\eql@interline@container{%
    \eql@displaybreak@pen@\the\numexpr#1\relax\relax}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@displaybreak@level[#1]{%
  \ifnum#1<\z@
    \global\eql@append\eql@interline@container{\eql@displaybreak@pen@\@MM}%
  \else
    \global\eql@appendexpand\eql@interline@container{%
      \eql@displaybreak@pen@-\@getpen{#1}\relax}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@displaybreak@pre#1{%
  \ifnum#1<\z@
    \eql@displaybreak@prepen@\@MM
  \else
    \eql@displaybreak@prepen@-\@getpen{#1}\relax
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@displaybreak@post#1{%
  \ifnum#1<\z@
    \eql@displaybreak@postpen@\@MM
  \else
    \eql@displaybreak@postpen@-\@getpen{#1}\relax
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@displaybreak@inter#1{%
  \ifnum#1<\z@
    \interdisplaylinepenalty\@M
  \else
    \interdisplaylinepenalty\eql@getdsp@pen{#1}\relax
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Explicit Vertical Space}
%
% \TODO describe
%
%   \lskip{\eql@vspaceskip@}
%    \begin{macrocode}
\newskip\eql@vspaceskip@
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@vspace@org\vspace
\def\eql@vspace{%
  \ifvmode
    \expandafter\eql@vspace@immediate
  \else
    \expandafter\eql@vspace@line
  \fi
}
%    \end{macrocode}
%
% \TODO |\eql@vspace@addfixedafter| on last line has no effect.
% should apply outside environment
%    \begin{macrocode}
\def\eql@vspace@line{%
  \eql@ifstar@loose\eql@vspace@addfixedbefore\eql@vspace@add
}
\def\eql@vspace@add#1{%
  \global\eql@appendexpand\eql@interline@container{%
    \advance\eql@vspaceskip@\the\glueexpr#1\relax\relax}}
\def\eql@vspace@addfixedbefore#1{%
  \global\eql@appendexpand\eql@interline@container{%
    \noexpand\eql@append\noexpand\eql@display@injectbefore{%
      \skip@\the\glueexpr#1\relax\relax
      \penalty\@M
      \vskip\skip@
      \global\advance\eql@line@interline@\skip@
    }%
  }%
}
\def\eql@vspace@addfixedafter#1{%
  \global\eql@appendexpand\eql@interline@container{%
    \noexpand\eql@append\noexpand\eql@display@injectafter{%
      \dimen@\prevdepth
      \hrule\@height\z@
      \skip@\the\glueexpr#1\relax\relax
      \penalty\@M
      \vskip\skip@
      \global\advance\eql@line@interline@\skip@
      \prevdepth\dimen@
    }%
  }%
}
%    \end{macrocode}
%
% \TODO careful to not expand |\eql@display@container| after measure
%    \begin{macrocode}
\def\eql@vspace@immediate{%
  \noalign\bgroup
    \eql@ifstar@loose\eql@vspace@fixed\eql@vspace@discardable
}
\def\eql@vspace@fixed#1{%
    \skip@\glueexpr#1\relax
    \ifnum\eql@row@=\@ne
      \global\eql@appendexpand\eql@display@container{%
        \advance\eql@abovespace@\the\skip@\relax}%
    \else\ifnum\eql@row@>\eql@totalrows@
      \global\eql@appendexpand\eql@display@container{%
        \advance\eql@belowspace@\the\skip@\relax}%
    \else
      \dimen@\prevdepth
      \hrule\@height\z@
      \penalty\@M
      \vskip\skip@
      \global\advance\eql@line@interline@\skip@
      \prevdepth\dimen@
    \fi\fi
  \egroup
}
\def\eql@vspace@discardable#1{%
    \skip@\glueexpr#1\relax
    \ifnum\eql@row@=\@ne
      \global\eql@appendexpand\eql@display@container{%
        \advance\eql@abovespace@\the\skip@\relax}%
    \else\ifnum\eql@row@>\eql@totalrows@
      \global\eql@appendexpand\eql@display@container{%
        \advance\eql@belowspace@\the\skip@\relax}%
    \else
      \vskip\skip@
      \global\advance\eql@line@interline@\skip@
    \fi\fi
  \egroup
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Default Vertical Spacing}
%
% \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@depth{.3}
\def\eql@strut{\copy\eql@strutbox@}
\let\eql@strut@cell\eql@strut
\let\eql@strut@tag\eql@strut
\def\eql@strut@make{%
  \setbox\eql@strutbox@\hbox{%
    \@tempdimb\dimexpr
        \eql@strut@depth\normalbaselineskip+.5\normallineskiplimit\relax
    \@tempdima\dimexpr
        \normalbaselineskip-\normallineskiplimit-\@tempdimb\relax
    \vrule\@height\@tempdima\@depth\@tempdimb\@width\z@
  }
}
\AtBeginDocument{\eql@strut@make}
%    \end{macrocode}
%
% \TODO describe
% \TODO uses amsmath |\spread@equation|
%    \begin{macrocode}
\def\eql@spread@set{%
  \ifdefined\eql@spread@reset
    \lineskip\normallineskip
    \lineskiplimit\normallineskiplimit
    \baselineskip\normalbaselineskip
  \fi
  \eql@spread@\dimexpr\glueexpr\eql@spread@val\relax
      +\normalbaselineskip-\baselineskip\relax
  \ifdim\eql@spread@>\z@
    \openup\eql@spread@
    \ifdefined\spread@equation
      \let\spread@equation\@empty
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Entry and Exit}
%
% \TODO describe
%
%    \begin{macrocode}
\let\eql@beamerbasecolor@fix\@empty
\AddToHook{package/beamerbasecolor/after}{%
  \def\eql@beamerbasecolor@fix{%
    \donotcolorouterdisplaymaths
    \donotcoloroutermaths
    \beamer@setdisplaymathcolor
  }%
}
%    \end{macrocode}
%
%   \lskip{\eql@abovespace@}
%   \lskip{\eql@belowspace@}
%    \begin{macrocode}
\newskip\eql@abovespace@
\newskip\eql@belowspace@
%    \end{macrocode}
%
%   \macro{\eql@display@enter}
%    \begin{macrocode}
\def\eql@display@enter{%
  \if@noskipsec\leavevmode\par\fi
  \ifvmode
    \eql@prevdepth@\prevdepth
    \nointerlineskip
    \noindent
  \else
    \eql@prevdepth@\maxdimen
  \fi
  \eql@beamerbasecolor@fix
}
%    \end{macrocode}
%
%   \macro{\eql@display@adjust}
%    \begin{macrocode}
\def\eql@display@adjust{%
  \ifdefined\eql@display@linewidth
    \displaywidth\glueexpr\eql@display@linewidth\relax
    \advance\displaywidth-\displayindent
  \fi
  \ifdefined\eql@display@marginleft
    \advance\displaywidth\displayindent
    \displayindent\glueexpr\eql@display@marginleft\relax
    \advance\displaywidth-\displayindent
  \fi
  \ifdefined\eql@display@marginright
    \advance\displaywidth-\glueexpr\eql@display@marginright\relax
  \fi
  \ifdim\displaywidth<\z@
    \displaywidth\z@
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@display@init}
%    \begin{macrocode}
\def\eql@display@init{%
  \let\displaybreak\eql@displaybreak
  \let\eql@vspace@org\vspace
  \let\vspace\eql@vspace
  \let\eqncontrol\eql@control
  \let\eql@display@injectbefore\@empty
  \let\eql@display@injectafter\@empty
  \eql@spread@set
  \eql@strut@make
  \let\eql@frame@cmd\@undefined
}
%    \end{macrocode}
%
%   \macro{\eql@display@print}
%    \begin{macrocode}
\def\eql@display@print{%
  \let\eql@display@container\@empty
  \eql@display@firstavail@\z@
  \eql@display@aboveextend@\z@
  \eql@display@belowextend@\z@
  \eql@punct@term@set
  \global\let\eql@interline@container\eql@interline@container@clear
}
%    \end{macrocode}
%
%   \macro{\eql@display@halign@init}
% \TODO describe
%    \begin{macrocode}
\def\eql@display@halign@init#1{%
  \eql@row@\z@
  \eql@prevgraf@\prevgraf
  \everycr{\noalign{%
    \global\advance\eql@row@\@ne
    \prevgraf\numexpr\prevgraf+\@ne\relax
    #1%
  }}%
}
%    \end{macrocode}
%
% \TODO how about penalty here? not for entry into display
%    \begin{macrocode}
\def\eql@display@halign@start{%
  \prevgraf\numexpr\eql@prevgraf@+\@ne\relax
  \ifdim\eql@prevdepth@=\maxdimen\else
    \prevdepth\eql@prevdepth@
  \fi
  \ifdim\prevdepth=-\@m\p@\else
    \ifdefined\eql@display@height
      \skip@\baselineskip
      \advance\skip@-\glueexpr\eql@display@height\relax
      \advance\skip@-\prevdepth\relax
      \ifdim\skip@<\lineskiplimit
        \skip@\lineskip
      \fi
      \advance\skip@-\eql@spread@\relax
      \vskip\skip@
      \nointerlineskip
    \else
      \vskip-\eql@spread@\relax
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@display@vspace{%
  \advance\abovedisplayskip\eql@abovespace@
  \advance\belowdisplayskip\eql@belowspace@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@display@vspace@native{%
  \advance\abovedisplayskip\eql@abovespace@
  \advance\belowdisplayskip\eql@belowspace@
  \advance\abovedisplayshortskip\eql@abovespace@
  \advance\belowdisplayshortskip\eql@belowspace@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@display@penalty{%
  \ifnum\eql@displaybreak@postpen@=\@MM\else
    \postdisplaypenalty\eql@displaybreak@postpen@
  \fi
  \ifnum\eql@displaybreak@pen@=\@MM\else
    \postdisplaypenalty\eql@displaybreak@pen@
  \fi
  \ifnum\eql@displaybreak@prepen@=\@MM\else
    \predisplaypenalty\eql@displaybreak@prepen@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
% \TODO issue: |\vspace*{0pt}| has some effect if page is broken here
%    \begin{macrocode}
\def\eql@display@halign@end{%
  \eql@interline@container
  \eql@display@injectbefore
  \global\eql@prevgraf@\numexpr\prevgraf+\@ne\relax
  \ifdefined\eql@display@depth
    \prevdepth\glueexpr\eql@display@depth\relax
  \fi
}
%    \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
% \TODO do we actually need penalty adjustments
%   in case of paragraphs above or below?
%    \begin{macrocode}
\def\eql@display@close{%
  \eql@display@container
  \ifdim\eql@display@firstavail@<\z@
    \eql@display@firstavail@\z@
  \fi
  \eql@skip@mode@leave@\z@
  \ifdim\eql@prevdepth@=\maxdimen
    \ifdim\predisplaysize=-\maxdimen
      \eql@skip@mode@above@\eql@skip@mode@cont@above\relax
      \eql@skip@mode@below@\eql@skip@mode@cont@below\relax
    \else
      \eql@skip@mode@above@\z@
      \eql@skip@mode@below@\z@
      \advance\eql@display@firstavail@\displayindent
      \ifdim\eql@display@firstavail@>\predisplaysize
        \ifcase\eql@skip@mode@short\relax
        \or
          \eql@skip@mode@above@\@ne
        \or
          \eql@skip@mode@above@\@ne
          \ifnum\eql@totalrows@=\@ne
            \eql@skip@mode@below@\@ne
          \fi
        \or
          \eql@skip@mode@above@\@ne
          \eql@skip@mode@below@\@ne
        \fi
      \fi
    \fi
  \else
    \ifdim\eql@prevdepth@=-\@m\p@
      \eql@skip@mode@above@\eql@skip@mode@top@above\relax
      \eql@skip@mode@below@\eql@skip@mode@top@below\relax
    \else
      \eql@skip@mode@above@\eql@skip@mode@par@above\relax
      \eql@skip@mode@below@\eql@skip@mode@par@below\relax
    \fi
  \fi
  \ifcase\eql@skip@mode@above@
  \or\or\or
    \predisplaypenalty\z@
  \or
    \predisplaypenalty\z@
  \fi
  \ifcase\eql@skip@mode@below@
  \or\or\or
    \eql@skip@mode@leave@\@ne
  \or
    \eql@skip@mode@leave@\tw@
  \fi
  \ifdefined\eql@skip@force@above
    \eql@skip@mode@above@\eql@skip@force@above\relax
  \fi
  \ifdefined\eql@skip@force@below
    \eql@skip@mode@below@\eql@skip@force@below\relax
  \fi
  \ifdefined\eql@skip@force@leave
    \eql@skip@mode@leave@\eql@skip@force@leave\relax
  \fi
  \ifnum\eql@skip@mode@leave@>\z@
    \postdisplaypenalty\z@
  \fi
  \ifcase\eql@skip@mode@above@
    \abovedisplayskip\glueexpr\eql@skip@long@above\relax
  \or
    \abovedisplayskip\glueexpr\eql@skip@short@above\relax
  \or
    \abovedisplayskip\glueexpr\eql@skip@cont@above\relax
  \or
    \abovedisplayskip\glueexpr\eql@skip@par@above\relax
  \or
    \abovedisplayskip\glueexpr\eql@skip@top@above\relax
  \or
    \abovedisplayskip\z@skip
  \or
    \abovedisplayskip\glueexpr\eql@skip@med@above\relax
  \or
    \abovedisplayskip\glueexpr\eql@skip@custom@above\relax
  \fi
  \ifcase\eql@skip@mode@below@
    \belowdisplayskip\glueexpr\eql@skip@long@below\relax
  \or
    \belowdisplayskip\glueexpr\eql@skip@short@below\relax
  \or
    \belowdisplayskip\glueexpr\eql@skip@cont@below\relax
  \or
    \belowdisplayskip\glueexpr\eql@skip@par@below\relax
  \or
    \belowdisplayskip\glueexpr\eql@skip@top@below\relax
  \or
    \belowdisplayskip\z@skip
  \or
    \belowdisplayskip\glueexpr\eql@skip@med@below\relax
  \or
    \belowdisplayskip\glueexpr\eql@skip@custom@below\relax
  \fi
  \global\eql@skip@mode@leave@\eql@skip@mode@leave@
  \eql@interline@container
  \advance\eql@belowspace@\eql@vspaceskip@
  \eql@display@penalty
  \eql@display@vspace
  \skip@\glueexpr\eql@skip@tag@above\relax
  \ifdim\skip@>\abovedisplayskip
    \skip@\abovedisplayskip
  \fi
  \advance\abovedisplayskip-\eql@display@aboveextend@\relax
  \ifdim\abovedisplayskip<\skip@
    \abovedisplayskip\skip@
  \fi
  \skip@\glueexpr\eql@skip@tag@below\relax
  \ifdim\skip@>\belowdisplayskip
    \skip@\belowdisplayskip
  \fi
  \ifdim\eql@display@belowextend@>\z@
    \advance\belowdisplayskip-\eql@display@belowextend@\relax
    \ifdim\belowdisplayskip<\skip@
      \belowdisplayskip\skip@
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@display@leave{%
  \prevgraf\eql@prevgraf@
  \ifcase\eql@skip@mode@leave@
  \or
    \endgraf
  \or
    \endgraf
    \prevdepth-\@m\p@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@display@nest{%
  \let\displaybreak\eql@displaybreak@default
  \let\intertext\eql@intertext@default
  \let\vspace\eql@vspace@org
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@display@restore{%
  \let\label\eql@label@org
  \let\tag\eql@tag@default
  \let\raisetag\eql@raisetag@default
  \let\displaybreak\eql@displaybreak@default
  \let\intertext\eql@intertext@default
  \let\vspace\eql@vspace@org
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@append\@arrayparboxrestore{%
  \eql@display@restore
  \ifdefined\eql@ampproof@active
    \eql@amprevert
  \fi
  \@displayfalse
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Stack}
%
% \TODO describe
% \TODO for each global variable declare global nature at its definition!
% \TODO we must be consistent about global variables vs local variables
% global variables need to be saved at every level where they may be modified
% (even if modified only locally)
%
%    \begin{macrocode}
\def\eql@stack@enable{%
  \let\eql@stack@save@equations\eql@stack@save@equations@
  \let\eql@stack@save@box\eql@stack@save@box@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\let\eql@stack@save@equations\eql@stack@enable
\let\eql@stack@save@box\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 further global variables:
% global registers: |\eql@nextopt|, |\eql@tags@glabel@|
% used locally without possibility of change between setting and retrieving:
% |\eql@prevgraf@|, |\eql@skip@mode@leave@|,
% |\eql@shape@lastrow|, |\eql@frame@prevcmd|
% \TODO to be reviewed: |\eql@intertext@after|, |\eql@intertext@opt|
% \TODO describe
%    \begin{macrocode}
\def\eql@stack@save@equations@{%
  \let\eql@stack@numbering@eqnswinit\eql@numbering@eqnswinit
  \let\eql@stack@cell@container\eql@cell@container
  \let\eql@stack@tags@container\eql@tags@container
  \let\eql@stack@interline@container\eql@interline@container
  \let\eql@stack@block@container\eql@display@container
  \let\eql@stack@dimensions@tab\eql@dimensions@tab
  \edef\eql@stack@restore{%
    \global\if@eqnsw\noexpand\@eqnswtrue\else\noexpand\@eqnswfalse\fi
    \eql@stack@save@let\eql@stack@numbering@eqnswinit\eql@numbering@eqnswinit
    \eql@stack@save@let\eql@stack@cell@container\eql@cell@container
    \eql@stack@save@let\eql@stack@tags@container\eql@tags@container
    \eql@stack@save@let\eql@stack@interline@container\eql@interline@container
    \eql@stack@save@let\eql@stack@dimensions@tab\eql@dimensions@tab
    \eql@stack@save@let\eql@stack@block@container\eql@display@container
    \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@line@prevdepth@
    \eql@stack@save@reg\eql@line@interline@
    \eql@stack@save@reg\eql@totalheight@
    \eql@stack@save@reg\eql@tagwidth@max@
    \eql@stack@save@reg\eql@tagpos@row@
    \eql@stack@save@reg\eql@row@
    \eql@stack@save@reg\eql@tagrows@
  }%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@stack@save@box@{%
  \let\eql@stack@cell@container\eql@cell@container
  \edef\eql@stack@restore{%
    \eql@stack@save@let\eql@stack@cell@container\eql@cell@container
    \eql@stack@save@reg\eql@row@
  }%
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Multi-Line Support}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Measure Support}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@measure@init#1#2{%
  \eql@dimensions@reset
  \let\eql@display@container\@empty
  \eql@numbering@measure@init
  \eql@row@\z@
  \eql@totalheight@\z@
  \eql@totalrows@\@M
  \eql@line@prevdepth@-\@m\p@
  \eql@line@interline@\z@
  \tabskip\z@skip
  \everycr{\noalign{%
    \global\advance\eql@row@\@ne
    #1%
  }}%
  \eql@punct@term@set
  \global\let\eql@interline@container\eql@interline@container@clear
  \eql@measure@savestate
  \eql@display@halign@letcr{#2}%
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@measure@tag{%
  \eql@tagwidth@\z@
  \ifdefined\eql@numbering@multi
    \if@eqnsw
      \eql@tags@container
      \eql@tagbox@make\eql@composetag@measure
      \ifdefined\eql@tagpos@reserve\else
        \eql@tagwidth@\z@
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@measure@endrow{%
  \ifdim\eql@line@prevdepth@=-\@m\p@\else
    \dimen@\dimexpr\baselineskip-\eql@line@height@-\eql@line@prevdepth@\relax
    \ifdim\dimen@<\lineskiplimit
      \dimen@\lineskip
    \fi
    \advance\eql@line@interline@\dimen@
  \fi
  \eql@dimensions@endrow
  \ifdim\eql@tagwidth@>\eql@tagwidth@max@
    \global\eql@tagwidth@max@\eql@tagwidth@
  \fi
  \ifdim\eql@tagwidth@>\z@
    \global\advance\eql@tagrows@\@ne
  \fi
  \global\advance\eql@totalheight@\dimexpr
    \eql@line@interline@+\eql@line@height@+\eql@line@depth@
  \global\eql@line@interline@\z@
  \global\eql@line@prevdepth@\eql@line@depth@
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@measure@close{%
  \advance\eql@row@-\tw@
  \eql@totalrows@\eql@row@
  \ifnum\eql@totalrows@>\z@
    \eql@dimensions@get\@ne
    \eql@topheight@\dimexpr\eql@line@height@+\eql@line@interline@\relax
    \eql@dimensions@get\eql@totalrows@
    \eql@bottomdepth@\eql@line@depth@
  \fi
  \eql@numbering@measure@blocktag
  \begingroup
    \eql@tags@container
    \if@eqnsw
      \eql@tagbox@make\eql@composetag@measure
      \ifdefined\eql@tagpos@reserve\else
        \eql@tagwidth@\z@
      \fi
      \eql@dimensions@saveblocktag
    \else
      \eql@dimensions@savenoblocktag
      \eql@numbering@warnunused
    \fi
  \endgroup
  \eql@dimensions@get\z@
  \eql@measure@restorestate
}
%    \end{macrocode}
%
%   \macro{\eql@measure@restorestate}
%   \macro{\eql@measure@savestate}
%    \begin{macrocode}
\let\eql@measure@restorestate\@empty
\def\eql@measure@savestate{%
  \begingroup
    \def\@elt##1{%
      \global\csname c@##1\endcsname\the\csname c@##1\endcsname}%
    \global\edef\@gtempa{\cl@@ckpt}%
  \endgroup
  \let\eql@measure@restorestate\@gtempa
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Line Breaks}
%
% \TODO describe
%
%   \macro{\eql@display@cr}
%    \begin{macrocode}
\def\eql@display@cr{%
  \eql@ampprotect\eql@display@cr@testall\eql@display@cr@process}
%    \end{macrocode}
%
%   \macro{\eql@display@cr@testall}
%   \macro{\eql@display@cr@parse}
% \TODO describe
%    \begin{macrocode}
\def\eql@display@cr@testall{\eql@parseopt@aux\eql@display@cr@parse}
\def\eql@display@cr@parse{%
  \ifx\eql@parseopt@token[%
    \let\eql@parseopt@next\eql@display@cr@parse@vspace
  \fi
  \ifx\eql@parseopt@token*%
    \let\eql@parseopt@next\eql@display@cr@parse@star
  \fi
  \ifx\eql@parseopt@token.%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token,%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token~%
    \let\eql@parseopt@next\eql@display@cr@parse@cont
  \fi
  \ifx\eql@parseopt@token`%
    \let\eql@parseopt@next\eql@parseopt@punctnext
  \fi
  \ifx\eql@parseopt@token&%
    \let\eql@parseopt@next\eql@parseopt@end
  \fi
}
\def\eql@display@cr@parse@vspace[#1]{\eql@vspace@add{#1}\eql@parseopt@peek}
\def\eql@display@cr@parse@star#1{\eql@displaybreak@star\@M\eql@parseopt@peek}
\def\eql@display@cr@parse@cont#1{\numbernext\eqnpunct~\eql@parseopt@peek}
%    \end{macrocode}
%
%   \macro{\eql@display@cr@process}
%    \begin{macrocode}
\def\eql@display@cr@process{%
  \eql@display@endline
  \cr
%    \end{macrocode}
%
%    \begin{macrocode}
  \noalign{%
    \eql@interline@container
    \eql@display@injectbefore
    \ifnum\eql@displaybreak@pen@=\@MM
      \penalty\interdisplaylinepenalty
    \else
      \penalty\eql@displaybreak@pen@
    \fi
    \vskip\eql@vspaceskip@
    \global\advance\eql@line@interline@\eql@vspaceskip@
    \eql@display@injectafter
    \global\let\eql@interline@container\eql@interline@container@clear
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@display@halign@letcr}
%    \begin{macrocode}
\def\eql@display@halign@letcr#1{%
  \let\\\eql@display@cr
  \let\eql@display@endline#1%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Intertext}
%
% \TODO describe
%
% \TODO revert in everymath?
%    \begin{macrocode}
\def\eql@intertext@default{\eql@error{Invalid use of \string\intertext}}
\eql@amsmath@let\intertext\eql@intertext@default
%    \end{macrocode}
%
% \TODO why does it fail in measuring? total width?!
% determine total width otherwise!?
%    \begin{macrocode}
\def\eql@intertext@process{%
  \eql@display@endline
  \cr
  \ifmeasuring@
    \expandafter\@gobble
  \else
    \expandafter\eql@intertext@print
  \fi
}
%    \end{macrocode}
%
% \TODO describe
% \TODO prevdepth
% \TODO does this have to be in a vbox?
% \TODO vskip and penalty opposite order
% \TODO can we handle short? certainly needs two passes
%    \begin{macrocode}
\def\eql@intertext@print#1{%
  \noalign{%
    \eql@display@halign@end
    \let\eql@skip@force@below\z@
    \let\eql@skip@force@above\z@
    \eql@setkeys{intertext}\eql@intertext@opt
    \openup-\eql@spread@
    \penalty\postdisplaypenalty
    \ifcase\eql@skip@force@below\relax
      \advance\eql@vspaceskip@\glueexpr\eql@skip@long@below\relax
    \or
      \advance\eql@vspaceskip@\glueexpr\eql@skip@short@below\relax
    \or
      \advance\eql@vspaceskip@\glueexpr\eql@skip@cont@below\relax
    \or
      \advance\eql@vspaceskip@\glueexpr\eql@skip@par@below\relax
    \or
      \advance\eql@vspaceskip@\glueexpr\eql@skip@top@below\relax
    \or
      \advance\eql@vspaceskip@\z@skip
    \or
      \advance\eql@vspaceskip@\glueexpr\eql@skip@med@below\relax
    \or
      \advance\eql@vspaceskip@\glueexpr\eql@skip@custom@below\relax
    \fi
    \vskip\eql@vspaceskip@
    \global\let\eql@interline@container\eql@interline@container@clear
    \vbox{%
      \@parboxrestore
      \ifdim
        \ifdim\@totalleftmargin=\z@\linewidth\else-\maxdimen\fi=\columnwidth
      \else
        \parshape\@ne
        \@totalleftmargin\linewidth
      \fi
      \noindent
      \prevgraf\eql@prevgraf@
      \ignorespaces
      #1%
      \par
      \global\eql@prevgraf@\prevgraf
    }%
    \penalty\predisplaypenalty
    \ifcase\eql@skip@force@above\relax
      \vskip\glueexpr\eql@skip@long@above\relax
    \or
      \vskip\glueexpr\eql@skip@short@above\relax
    \or
      \vskip\glueexpr\eql@skip@cont@above\relax
    \or
      \vskip\glueexpr\eql@skip@par@above\relax
    \or
      \vskip\glueexpr\eql@skip@top@above\relax
    \or
      \vskip\z@skip
    \or
      \vskip\glueexpr\eql@skip@med@above\relax
    \or
      \vskip\glueexpr\eql@skip@custom@above\relax
    \fi
%    \eql@prevdepth@\maxdimen
    \eql@prevdepth@\z@
    \eql@display@halign@start
  }
}
%    \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{Line Marks}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@markline@pos@below{below}
\def\eql@markline@pos@bottom{bottom}
\def\eql@markline@pos@baseline{baseline}
\let\eql@markline@pos\eql@markline@pos@baseline
\let\eql@markline@shift\z@
\def\eql@markline@qed{\ifdefined\qedsymbol\qedsymbol\else QED\fi}
\def\eql@markline@symbol{}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@markline@select#1{%
  \let\eql@markline@shift\z@
  \eql@setkeys{markline}{#1}%
  \eql@markline@print
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@markline@print{%
  \dimen@\dimexpr\eql@markline@shift\relax
  \ifx\eql@markline@pos\eql@markline@pos@below
    \ifdim\dimen@=\z@\else
      \penalty\@M
      \vskip-\dimen@
    \fi
    \nointerlineskip
    \penalty\@M
    \vbox{\hfill\hbox{\eql@markline@symbol}}%
  \else
    \ifx\eql@markline@pos\eql@markline@pos@baseline
      \advance\dimen@\prevdepth
    \fi
    \setbox\z@\hbox{\raise\dimen@\hbox{\eql@markline@symbol}}%
    \dimen@\prevdepth
    \ht\z@\z@
    \dp\z@\z@
    \nointerlineskip
    \penalty\@M
    \vbox{\hfill\box\z@}%
    \prevdepth\dimen@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@markline@inject#1{%
  \let\eql@markline@push\eql@false
  \ifx\eql@markline@pos\eql@markline@pos@below\else
    \ifdefined\eql@tagsleft\else
      \ifx\eql@equations@main\eql@multi@main
        \ifdefined\eql@numbering@multi
          \if@eqnsw
            \let\eql@markline@push\eql@true
          \fi
        \else
          \ifnum\eql@row@=\eql@tagpos@row@
            \let\eql@markline@push\eql@true
          \fi
        \fi
      \else
        \if@eqnsw
          \let\eql@markline@push\eql@true
        \fi
      \fi
    \fi
  \fi
  \ifdefined\eql@markline@push
    \global\eql@append\eql@interline@container{%
      \eql@append\eql@display@injectbefore{\eql@markline@select{push,#1}}}%
  \else
    \global\eql@append\eql@interline@container{%
      \eql@append\eql@display@injectbefore{\eql@markline@select{#1}}}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@markline@amsthm@opt[#1]{\eql@markline@inject{qed,#1}}
\def\eql@markline@amsthm@staropt[#1]{\eql@markline@inject{qed,push,#1}}
\def\eql@markline@amsthm@qed{\eql@teststaropt@tight
  \eql@markline@amsthm@staropt\eql@markline@amsthm@opt{}}
\def\eql@markline@amsthm@register#1{\eql@letcs{#1@qed}\eql@markline@amsthm@qed}
\def\eql@markline@amsthm@move#1#2{%
  \AddToHook{package/amsthm/after}{%
    \eql@letcs{#1@qed\expandafter}\csname#2@qed\endcsname}}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Column Placement}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Supporting Definitions}
%
%   \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@
\let\eql@shape@lastrow\eql@false
%    \end{macrocode}
%
%   \ldimen{\eql@marginleft@}
%   \ldimen{\eql@marginleft@min@}
%   \ldimen{\eql@marginright@}
%   \ldimen{\eql@centeroffset@}
% The registers |\eql@marginleft@| and |\eql@marginright@|
% store the intended left and right margin for the equation lines:
% \TODO update
%    \begin{macrocode}
\newdimen\eql@marginleft@
\newdimen\eql@marginright@
\newdimen\eql@marginleft@min@
\newdimen\eql@centeroffset@
%    \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@layoutcenter@...}
%   \macro{\eql@shape@layoutleft@...}
% Define the uniform shape schemes |left|, |center|, |right| and |default|
% for the central and left alignment layout.
% The scheme functions determine the desired alignment and indentation
% for the current row:
%    \begin{macrocode}
\def\eql@shape@layoutcenter@left{\eql@shape@pos@\z@\eql@shape@amount@\z@}
\def\eql@shape@layoutcenter@center{\eql@shape@pos@\@ne\eql@shape@amount@\z@}
\def\eql@shape@layoutcenter@right{\eql@shape@pos@\tw@\eql@shape@amount@\z@}
\let\eql@shape@layoutcenter@default\eql@shape@layoutcenter@center
\def\eql@shape@layoutleft@left{\eql@shape@pos@\z@\eql@shape@amount@\z@}
\def\eql@shape@layoutleft@center{\eql@shape@pos@\@ne\eql@shape@amount@\z@}
\def\eql@shape@layoutleft@right{\eql@shape@pos@\tw@\eql@shape@amount@\z@}
\let\eql@shape@layoutleft@default\eql@shape@layoutleft@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@layoutcenter@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@layoutleft@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 centeral alignment layout all but the first line are indented
% while in left aligned layout the first line has negative indentation:
%    \begin{macrocode}
\def\eql@shape@layoutcenter@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@layoutleft@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 centeral alignment layout the shift operates on the alignment
% whereas in left alignment layout the shift uses indentation:
%    \begin{macrocode}
\def\eql@shape@layoutcenter@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@layoutleft@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@select}
%   \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@select{%
  \expandafter\let\expandafter\eql@shape@eval
    \csname eql@shape%
    @\ifdefined\eql@layoutleft layoutleft\else layoutcenter\fi
    @\eql@shape@mode\endcsname
}
%    \end{macrocode}
%
%   \macro{\eql@shape@alignleft}
%   \macro{\eql@shape@alignright}
%   \macro{\eql@shape@aligncenter}
% Adjust the alignment of the current equation line.
% The optional argument specifies the amount of indentation:
%    \begin{macrocode}
\protected\def\eql@shape@alignleft{%
  \global\eql@append\eql@cell@container{\eql@shape@pos@\z@}%
  \eql@ampprotect\eql@shape@align@testpar\eql@shape@alignamount@opt}
\protected\def\eql@shape@aligncenter{%
  \global\eql@append\eql@cell@container{\eql@shape@pos@\@ne}%
  \eql@ampprotect\eql@shape@align@testpar\eql@shape@alignamount@opt}
\protected\def\eql@shape@alignright{%
  \global\eql@append\eql@cell@container{\eql@shape@pos@\tw@}%
  \eql@ampprotect\eql@shape@align@testpar\eql@shape@alignamount@opt}
\def\eql@shape@align@testpar#1{%
  \eql@ifstar@tight{#1[\eql@indent@]}%
  {\eql@ifnextgobble@tight{!}{#1[-\eql@indent@]}%
  {\eql@testopt@tight{#1}\z@}}}
\def\eql@shape@alignamount@opt[#1]{\eql@shape@alignamount@set{#1}}
%    \end{macrocode}
%
%   \macro{\eql@shape@alignamount}
% \TODO describe
%    \begin{macrocode}
\protected\def\eql@shape@alignamount{%
  \eql@ampprotecttwo\eql@ifstar@tight
    \eql@shape@alignamount@set\eql@shape@alignamount@add}
\def\eql@shape@alignamount@add#1{%
  \global\eql@appendexpand\eql@cell@container{%
    \advance\eql@shape@amount@\the\glueexpr#1\relax\relax}}
\def\eql@shape@alignamount@set#1{%
  \global\eql@appendexpand\eql@cell@container{%
    \eql@shape@amount@\the\glueexpr#1\relax\relax}}
\def\eql@shape@align@enable{%
  \let\shoveleft\eql@shape@alignleft
  \let\shovecenter\eql@shape@aligncenter
  \let\shoveright\eql@shape@alignright
  \let\shoveby\eql@shape@alignamount
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\protected\def\eql@shape@align@default{%
  \eql@warn@here{\shove...}%
  \eql@ampprotect\eql@shape@align@testpar\eql@gobbleopt}
\protected\def\eql@shape@alignamount@default{%
  \eql@warn@here{\shove...}%
  \eql@ampprotecttwo\eql@ifstar@tight\@gobble\@gobble}
\def\eql@shape@align@disable{%
  \let\shoveleft\eql@shape@align@default
  \let\shovecenter\eql@shape@align@default
  \let\shoveright\eql@shape@align@default
  \let\shoveby\eql@shape@alignamount@default
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Width Data}
%
%   \ldimen{\eql@tagwidth@block@}
%    \begin{macrocode}
\newdimen\eql@tagwidth@block@
\newdimen\eql@tagheight@block@
\newdimen\eql@tagdepth@block@
%    \end{macrocode}
%
%   \macro{\eql@dimensions@tab}
% \TODO new
%    \begin{macrocode}
\let\eql@dimensions@tab\@empty
%    \end{macrocode}
%
%   \macro{\eql@dimensions@reset}
%    \begin{macrocode}
\def\eql@dimensions@reset{%
  \let\eql@dimensions@tab\@empty
  \eql@tagwidth@max@\z@
  \eql@tagrows@\z@
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@add}
%    \begin{macrocode}
\def\eql@dimensions@add#1{%
  \global\eql@appendexpand\eql@dimensions@tab{#1}%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@addreg}
%    \begin{macrocode}
\def\eql@dimensions@addreg#1{#1\the#1\relax}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@startrow}
%    \begin{macrocode}
\def\eql@dimensions@startrow{%
  \eql@dimensions@add{\eql@dimensions@addreg\eql@row@}%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@savecell}
%    \begin{macrocode}
\def\eql@dimensions@savecell{%
  \eql@dimensions@add{%
    \eql@dimensions@addreg\eql@shape@pos@
    \eql@dimensions@addreg\eql@cellwidth@
    \eql@dimensions@addreg\eql@shape@amount@
    \noexpand\eql@dimensions@cellcall
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@savesep}
%    \begin{macrocode}
\def\eql@dimensions@savesep{%
  \eql@dimensions@add{\noexpand\eql@dimensions@sepcall}%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@endrow}
%    \begin{macrocode}
\def\eql@dimensions@endrow{%
  \eql@dimensions@add{,%
    \eql@dimensions@addreg\eql@tagwidth@
    \eql@dimensions@addreg\eql@line@height@
    \eql@dimensions@addreg\eql@line@depth@
    \eql@dimensions@addreg\eql@line@interline@
    ;}%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@saveblocktag}
%    \begin{macrocode}
\def\eql@dimensions@saveblocktag{%
  \eql@dimensions@add{\eql@row@0\relax,%
    \eql@tagwidth@block@\the\eql@tagwidth@\relax
    \eql@tagheight@block@\the\ht\eql@tagbox@\relax
    \eql@tagdepth@block@\the\dp\eql@tagbox@\relax
    \eql@dimensions@addreg\eql@tagpos@shift@
    \let\noexpand\eql@tagpos@reserve\ifdefined\eql@tagpos@reserve
      \noexpand\eql@true\else\noexpand\eql@false\fi
  ;}%
  \global\eql@tagwidth@max@\eql@tagwidth@
  \global\eql@tagrows@\@ne
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@savenoblocktag}
%    \begin{macrocode}
\def\eql@dimensions@savenoblocktag{%
  \eql@dimensions@add{\eql@row@0\relax,;}%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@for}
%    \begin{macrocode}
\def\eql@dimensions@for#1{%
  \def\eql@dimensions@forcall{#1}%
  \expandafter\eql@dimensions@forstep\eql@dimensions@tab
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@forstep}
%    \begin{macrocode}
\def\eql@dimensions@forstep\eql@row@#1\relax#2,#3;{%
  \eql@row@#1\relax
  \ifnum\eql@row@=\z@\else
    #3%
    \def\eql@dimensions@cells{#2}%
    \eql@dimensions@forcall
    \expandafter\eql@dimensions@forstep
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@get}
%    \begin{macrocode}
\def\eql@dimensions@get#1{%
  \eql@row@#1\relax
  \expandafter\eql@dimensions@getdef\expandafter{\the\eql@row@}%
  \expandafter\eql@dimensions@getparse\eql@dimensions@tab\@nil
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@getdef}
%    \begin{macrocode}
\def\eql@dimensions@getdef#1{%
  \def\eql@dimensions@getparse
    ##1\eql@row@#1\relax##2,##3;##4\@nil{%
    ##3%
    \def\eql@dimensions@cells{##2}%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@colwidth@tab}
%    \begin{macrocode}
\let\eql@colwidth@tab\@empty
%    \end{macrocode}
%
%   \macro{\eql@colwidth@get}
%    \begin{macrocode}
\def\eql@colwidth@get#1{%
  \ifcase\expandafter#1\eql@colwidth@tab\else\z@\fi
}
%    \end{macrocode}
%
%   \macro{\eql@colwidth@save}
%    \begin{macrocode}
\def\eql@colwidth@save#1{%
  \edef\eql@colwidth@tab{%
    \noexpand\or\the#1%
    \unexpanded\expandafter{\eql@colwidth@tab}%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@calc}
% Compute the space that is available at the beginning and at the end
% of the row stored in |\eql@dimensions@cells|.
% The space available at the beginning is returned in |\eql@line@avail@|.
% and |\eql@line@availsep@| describes
% the number of unused intercolumn separations.
% The total used width is returned in |\eql@line@width@|
% and |\eql@line@widthsep@| describes
% the number of used intercolumn separations.
% The available space at the end of the row is given as the difference
% to |\eql@totalwidth@|:
%    \begin{macrocode}
\def\eql@dimensions@calc{%
  \eql@column@\z@
  \eql@line@pos@\z@
  \eql@line@possep@\z@
  \eql@line@avail@\eql@totalwidth@
  \eql@line@availsep@\eql@intercolumns@
  \eql@line@width@\z@
  \eql@line@widthsep@\z@
  \let\eql@dimensions@cellcall\eql@dimensions@calc@call
  \let\eql@dimensions@sepcall\eql@dimensions@calc@callsep
  \eql@dimensions@cells
}
%    \end{macrocode}
%
%   \macro{\eql@dimensions@calc@callsep}
% Callback for each intercolumn space.
%    \begin{macrocode}
\def\eql@dimensions@calc@callsep{%
  \advance\eql@line@possep@\@ne
}%
%    \end{macrocode}
%
%   \macro{\eql@dimensions@calc@call}
% Callback for each column.
% When a non-blank cell is encountered,
% the available space on the left will be fixed if it is still undetermined,
% and the total width is updated to the current position:
% \TODO implement an offset for central alignment (global?!)
%    \begin{macrocode}
\def\eql@dimensions@calc@call{%
  \advance\eql@column@\@ne
  \ifnum\eql@totalcolumns@=\@ne
    \dimen@\eql@totalwidth@
  \else
    \dimen@\eql@colwidth@get\eql@column@\relax
  \fi
  \ifdim\eql@cellwidth@>\z@
    \ifdim\eql@line@width@=\z@
      \eql@line@avail@\eql@line@pos@
      \eql@line@availsep@\eql@line@possep@
      \ifcase\eql@shape@pos@
      \or
        \advance\eql@line@avail@\dimexpr
            (\dimen@-\eql@cellwidth@+\eql@centeroffset@)/\tw@\relax
      \or
        \advance\eql@line@avail@\dimexpr\dimen@-\eql@cellwidth@\relax
      \fi
      \advance\eql@line@avail@\eql@shape@amount@
    \fi
    \eql@line@width@\eql@line@pos@
    \eql@line@widthsep@\eql@line@possep@
    \ifcase\eql@shape@pos@
      \advance\eql@line@width@\eql@cellwidth@
    \or
      \advance\eql@line@width@\dimexpr
          (\dimen@+\eql@cellwidth@+\eql@centeroffset@)/\tw@\relax
    \or
      \advance\eql@line@width@\dimen@
    \fi
    \advance\eql@line@width@\eql@shape@amount@
  \fi
  \advance\eql@line@pos@\dimen@
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Best Line Selection}
%
%   \macro{\eql@numbering@best@auto}
% \TODO describe
%    \begin{macrocode}
\let\eql@numbering@best@auto\eql@false
%    \end{macrocode}
%
%   \tcounter{\eql@numbering@best@row@}
%   \ldimen{\eql@numbering@best@space@}
%   \ebool{\eql@numbering@best@use}
%    \begin{macrocode}
\newcount\eql@numbering@best@row@
\newdimen\eql@numbering@best@space@
\let\eql@numbering@best@use\eql@false
%    \end{macrocode}
%
%   \macro{\eql@numbering@best@find}
% Determine the row with the largest available space
% on the side of the tags:
%    \begin{macrocode}
\def\eql@numbering@best@find{%
  \eql@numbering@best@row@\z@
  \eql@numbering@best@space@\z@
  \eql@dimensions@for{%
    \eql@dimensions@calc
    \ifdefined\eql@tagsleft
      \dimen@\eql@line@avail@
    \else
      \dimen@\dimexpr\eql@totalwidth@-\eql@line@width@\relax
    \fi
    \ifdim\dimen@>\eql@numbering@best@space@
      \eql@numbering@best@row@\eql@row@
      \eql@numbering@best@space@\dimen@
    \fi
  }%
  \ifnum\eql@numbering@best@row@>\z@
    \eql@tagpos@row@\eql@numbering@best@row@
    \let\eql@tagpos@continuous\eql@false
    \eql@tagpos@prevrow@\z@
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@numbering@best@test}
% \TODO describe
%    \begin{macrocode}
\def\eql@numbering@best@test#1{%
  \eql@dimensions@get#1%
  \eql@dimensions@calc
  \ifdefined\eql@tagsleft
    \dimen@\dimexpr\eql@line@avail@
        +\eql@marginleft@+\eql@line@availsep@\eql@colsep@\relax
  \else
    \dimen@\dimexpr\displaywidth-\eql@line@width@
        -\eql@marginleft@-\eql@line@widthsep@\eql@colsep@\relax
  \fi
  \ifdim\dimen@<\eql@tagwidth@block@
    \let\eql@numbering@best@use\eql@true
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@numbering@best@eval}
% \TODO describe
% \TODO to test both lines individually may cause undesired effects
%    \begin{macrocode}
\def\eql@numbering@best@eval{%
  \ifdefined\eql@numbering@best@auto
    \ifdefined\eql@numbering@best@use\else
      \ifdefined\eql@numbering@multi\else
        \ifnum\eql@tagpos@row@>\z@
          \eql@numbering@best@test\eql@tagpos@row@
        \fi
        \ifnum\eql@tagpos@prevrow@>\z@
          \eql@numbering@best@test\eql@tagpos@prevrow@
        \fi
      \fi
    \fi
  \fi
  \ifdefined\eql@numbering@best@use
    \eql@numbering@best@find
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Tag Margin}
%
% \TODO describe
% \TODO if a tag margin is installed for a single line,
% it will shift the center even if there is no tag
% or importantly if a tag has been raised.
%
%   \macro{\eql@adjust@calc@tagmargin}
%    \begin{macrocode}
\def\eql@adjust@calc@tagmargin{%
  \ifdefined\eql@tagmargin@val
    \eql@tagmargin@\glueexpr\eql@tagmargin@val\relax
  \else
    \eql@tagmargin@\eql@tagwidth@max@
    \ifdim\eql@tagmargin@>\z@
      \advance\eql@tagmargin@-\eql@tagsepmin@
    \fi
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \dimen@\eql@tagrows@\p@
  \ifnum\eql@totalrows@=\@ne
    \ifnum\eql@tagrows@=\@ne
      \advance\dimen@1sp\relax
    \fi
  \fi
  \ifdim\dimen@>\eql@totalrows@\eql@tagmargin@ratio@\else
    \eql@tagmargin@\z@
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \@tempdima\dimexpr\displaywidth
      -\eql@totalwidth@-\eql@intercolumns@\eql@colsepmin@\relax
  \@tempdimb\dimexpr\@tempdima-\tw@\eql@tagmargin@\relax
  \ifdim\@tempdimb>\z@
    \ifdim\eql@tagmargin@threshold\@tempdima<\@tempdimb
      \eql@tagmargin@\z@
    \fi
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Single Column}
%
%   \macro{\eql@adjust@calc@lines}
%    \begin{macrocode}
\def\eql@adjust@calc@lines{%
  \eql@totalcolumns@\@ne
  \eql@intercolumns@\z@
  \eql@colsep@\z@
  \ifdefined\eql@layoutleft
    \eql@marginleft@\glueexpr\eql@layoutleftmargin\relax
    \eql@marginleft@min@\glueexpr\eql@layoutleftmarginmin\relax
    \ifdim\eql@marginleft@<\eql@marginleft@min@
      \eql@marginleft@\eql@marginleft@min@
    \fi
    \dimen@\glueexpr\eql@layoutleftmarginmax\relax
    \ifdim\eql@marginleft@>\dimen@
      \eql@marginleft@\dimen@
    \fi
    \eql@marginright@\z@
    \eql@centeroffset@\z@
  \else
    \eql@adjust@calc@tagmargin
    \ifdefined\eql@paddingleft@val
      \eql@marginleft@\dimexpr
          (\displaywidth-\eql@totalwidth@-\eql@tagmargin@)/\tw@
          -\glueexpr\eql@paddingleft@val\relax\relax
      \ifdim\eql@marginleft@<\z@
        \eql@marginleft@\z@
      \fi
    \else
      \eql@marginleft@\z@
    \fi
    \ifdefined\eql@paddingright@val
      \eql@marginright@\dimexpr
          (\displaywidth-\eql@totalwidth@-\eql@tagmargin@)/\tw@
          -\glueexpr\eql@paddingright@val\relax\relax
      \ifdim\eql@marginright@<\z@
        \eql@marginright@\z@
      \fi
    \else
      \eql@marginright@\z@
    \fi
    \ifdim\eql@tagmargin@>\z@
      \ifdefined\eql@tagsleft
        \ifdim\eql@marginleft@<\eql@tagsepmin@
          \eql@marginleft@\eql@tagsepmin@
        \fi
        \advance\eql@marginleft@\eql@tagmargin@
        \advance\eql@centeroffset@\eql@tagmargin@
      \else
        \ifdim\eql@marginright@<\eql@tagsepmin@
          \eql@marginright@\eql@tagsepmin@
        \fi
        \advance\eql@marginright@\eql@tagmargin@
        \advance\eql@centeroffset@-\eql@tagmargin@
      \fi
    \fi
    \eql@marginleft@min@\z@
    \eql@centeroffset@\dimexpr\eql@marginright@-\eql@marginleft@
        \ifdefined\eql@tagsleft+\else-\fi\eql@tagmargin@\relax
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@totalwidth@\dimexpr\displaywidth
      -\eql@marginleft@-\eql@marginright@\relax
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Multiple Columns}
%
% The following code computes the horizontal placement of columns.
% It distributes the columns evenly according to the layout presets
% and then determines
% whether there is enough space to place an equation tag on each line.
% If not, the intercolumn spacing and the space at the opposite margin
% can be reduced.
%
%   \macro{\eql@adjust@calc@columns}
% Main method to adjust column placement and spacing:
%    \begin{macrocode}
\def\eql@adjust@calc@columns{%
%    \end{macrocode}
% If there is just a single alignment stucture,
% there will be no intercolumn space that might stretch
% to adjust the columns to the margins.
% We disable fulllength to avoid a division by zero.
% Also guard against no columns at all (empty body), just in case:
%    \begin{macrocode}
  \ifnum\eql@totalcolumns@<\thr@@
    \eql@totalcolumns@\tw@
    \let\eql@columns@fulllength\eql@false
  \fi
%    \end{macrocode}
% Determine the number of intercolumn spaces |\eql@intercolumns@|:
%    \begin{macrocode}
  \eql@intercolumns@\numexpr(\eql@totalcolumns@-\tw@)/\tw@\relax
%    \end{macrocode}
% Evaluate the minimum intercolumn space which we will need often:
%    \begin{macrocode}
  \eql@colsepmin@\glueexpr\eql@colsepmin@val\relax
%    \end{macrocode}
% Determine the left or target margin width depending on the layout:
%    \begin{macrocode}
  \ifdefined\eql@layoutleft
    \eql@marginleft@\glueexpr\eql@layoutleftmargin\relax
    \eql@marginleft@min@\glueexpr\eql@layoutleftmarginmin\relax
    \ifdim\eql@marginleft@<\eql@marginleft@min@
      \eql@marginleft@\eql@marginleft@min@
    \fi
  \else
%    \end{macrocode}
% Get the desired tag margin, increase by minimum tag separation
% if columns are aligned to the margins. Cancel tag margin if too wide:
%    \begin{macrocode}
    \eql@adjust@calc@tagmargin
    \ifdefined\eql@columns@fulllength
      \ifdim\eql@tagmargin@>\z@
        \advance\eql@tagmargin@\eql@tagsepmin@
      \fi
    \fi
    \ifdim\eql@tagmargin@>\dimexpr\displaywidth-\eql@totalwidth@
        -\eql@intercolumns@\eql@colsepmin@\relax
      \eql@tagmargin@\z@
    \fi
    \eql@marginleft@min@\z@
  \fi
%    \end{macrocode}
% Compute the intercolumn space |\eql@colsep@|:
%    \begin{macrocode}
  \ifnum\eql@intercolumns@>\z@
%    \end{macrocode}
% Distribute the available horizontal space
% evenly onto the intercolumn spaces and the margins.
% Unless the columns are aligned to the margins,
% there are two margins in central alignment layout
% but only the right margin in left alignment layout:
%    \begin{macrocode}
    \eql@colsep@\dimexpr\displaywidth-\eql@totalwidth@\relax
    \ifdefined\eql@layoutleft
      \advance\eql@colsep@-\eql@marginleft@
    \else
      \advance\eql@colsep@-\eql@tagmargin@
    \fi
    \count@\eql@intercolumns@
    \ifdefined\eql@columns@fulllength\else
      \ifdefined\eql@layoutleft
        \advance\count@\@ne
      \else
        \advance\count@\tw@
      \fi
    \fi
    \divide\eql@colsep@\count@
%    \end{macrocode}
% Ensure that the intercolumn separation is within the specified bounds.
% Disable the upper bound if columns are to be aligned to the margins:
%    \begin{macrocode}
    \ifdim\eql@colsep@<\eql@colsepmin@
      \eql@colsep@\eql@colsepmin@
    \else
      \ifdefined\eql@columns@fulllength\else
        \dimen@\glueexpr\eql@colsepmax@val\relax
        \ifdim\eql@colsep@>\dimen@
          \eql@colsep@\dimen@
        \fi
      \fi
    \fi
  \else
%    \end{macrocode}
% For a single column, set the column separation to the minimum amount:
%    \begin{macrocode}
    \eql@colsep@\eql@colsepmin@
  \fi
%    \end{macrocode}
% Compute the left margin |\eql@marginleft@| depending on the layout:
%    \begin{macrocode}
  \ifdefined\eql@layoutleft
%    \end{macrocode}
% Set the default value:
%    \begin{macrocode}
    \ifdim\eql@colsep@=\eql@colsepmin@
%    \end{macrocode}
% If in left alignment layout the intercolumn space has been adjusted,
% compute the available space, determine left margin
% and make sure it is between the minimum and the default value:
%    \begin{macrocode}
      \dimen@\dimexpr\displaywidth-\eql@totalwidth@
          -\eql@intercolumns@\eql@colsep@\relax
      \ifdim\dimen@<\eql@marginleft@
        \ifdim\dimen@<\eql@marginleft@min@
          \eql@marginleft@\eql@marginleft@min@
        \else
          \eql@marginleft@\dimen@
        \fi
      \fi
    \fi
  \else
%    \end{macrocode}
% In central alignment mode with column aligned to the margins,
% set margin to zero:
%    \begin{macrocode}
    \ifdefined\eql@columns@fulllength
      \eql@marginleft@\z@
%    \end{macrocode}
% In central alignment mode with margins,
% distribute the available space equally to both margins,
% or remove the left margin if insufficient:
%    \begin{macrocode}
    \else
      \eql@marginleft@\dimexpr(\displaywidth-\eql@totalwidth@
          -\eql@intercolumns@\eql@colsep@-\eql@tagmargin@)/\tw@\relax
      \ifdim\eql@marginleft@<\z@
        \eql@marginleft@\z@
      \fi
    \fi
%    \end{macrocode}
% Add tag margin in case of left tags:
%    \begin{macrocode}
    \ifdefined\eql@tagsleft
      \advance\eql@marginleft@\eql@tagmargin@
    \fi
  \fi
%    \end{macrocode}
% Find the best row for tag placement:
%    \begin{macrocode}
  \eql@numbering@best@eval
%    \end{macrocode}
% Next consider all rows with tags
% and adjust the intercolumn and margin space
% to make the tags fit into the available space
% at the corresponding side as far as possible.
% First, select code depending on tag placement:
%    \begin{macrocode}
  \ifdefined\eql@tagsleft
    \let\eql@adjust@columns@test\eql@adjust@columns@test@tagsleft
  \else
    \let\eql@adjust@columns@test\eql@adjust@columns@test@tagsright
  \fi
%    \end{macrocode}
% Loop over all rows or select the single row containing the tag.
% Fetch the width data for the current row.
% If a tag is present, compute the available space and try
% to adjust spaces if needed:
% \TODO complete for prevrow, ideally join treatment
%    \begin{macrocode}
  \ifdefined\eql@numbering@multi
    \eql@dimensions@for{%
      \ifdim\eql@tagwidth@>\z@
        \eql@dimensions@calc
        \eql@adjust@columns@test
      \fi
    }%
  \else
    \ifnum\eql@tagpos@row@>\z@
      \ifnum\eql@tagpos@row@>\eql@totalrows@\else
        \eql@dimensions@get\eql@tagpos@row@
        \eql@tagwidth@\eql@tagwidth@block@
        \eql@dimensions@calc
        \eql@adjust@columns@test
      \fi
    \fi
    \ifnum\eql@tagpos@prevrow@>\z@
      \eql@dimensions@get\eql@tagpos@prevrow@
      \eql@tagwidth@\eql@tagwidth@block@
      \eql@dimensions@calc
      \eql@adjust@columns@test
    \fi
  \fi
%    \end{macrocode}
% From now on |\eql@totalwidth@| will include
% the left margin and the total intercolumn separation:
%    \begin{macrocode}
  \advance\eql@totalwidth@\dimexpr
      \eql@intercolumns@\eql@colsep@+\eql@marginleft@\relax
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Placement for Right Tags.}
%
%   \macro{\eql@adjust@columns@test@tagsright}
% Test whether the spacing can be adjusted to make the current row fit:
%    \begin{macrocode}
\def\eql@adjust@columns@test@tagsright{%
%    \end{macrocode}
% The register |\@tempdima| will hold the amount of available space.
% \TODO does this apply equally to left alignment layout?
%    \begin{macrocode}
  \@tempdima\dimexpr\displaywidth-\eql@line@width@-\eql@tagwidth@\relax
%    \end{macrocode}
% Test whether the space at the end of the row
% is sufficient to hold the tag with the current settings.
%    \begin{macrocode}
  \ifdim\@tempdima<\dimexpr
      \eql@marginleft@+\eql@line@widthsep@\eql@colsep@\relax
%    \end{macrocode}
% If not, determine whether the row and tag may at all
% fit into the available space with minimal intercolumn spaces
% and minimal left margin (in left alignment layout).
%    \begin{macrocode}
    \ifdim\@tempdima<\dimexpr
        \eql@marginleft@min@+\eql@line@widthsep@\eql@colsepmin@\relax\else
%    \end{macrocode}
% If so, hand over to |\eql@adjust@columns@modify@tagsright|.
%    \begin{macrocode}
      \eql@adjust@columns@modify@tagsright
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@columns@modify@tagsright}
% Adjust the intercolumn space and left margin to make the row fit.
%    \begin{macrocode}
\def\eql@adjust@columns@modify@tagsright{%
%    \end{macrocode}
% If there are any intercolumn spaces that contribute to the available space,
% determine how much intercolumn separation would be needed
% while keeping the current left margin fixed (in left alignment layout).
% In central alignment layout,
% assume that the left margin will be adjusted
% to match the intercolumn separation
% by stepping the number of columns to divide by.
%    \begin{macrocode}
  \ifnum\eql@line@widthsep@>\z@
    \dimen@\@tempdima
    \count@\eql@line@widthsep@
    \ifdefined\eql@layoutleft
      \advance\dimen@-\eql@marginleft@
    \else
      \ifdefined\eql@columns@fulllength\else
        \advance\count@\@ne
      \fi
    \fi
    \divide\dimen@\count@
%    \end{macrocode}
% If smaller, reduce the intercolumn separation,
% but make sure to not exceed the minumum allowed value.
%    \begin{macrocode}
    \ifdim\dimen@<\eql@colsep@
      \ifdim\dimen@<\eql@colsepmin@
        \eql@colsep@\eql@colsepmin@
      \else
        \eql@colsep@\dimen@
      \fi
    \fi
  \fi
%    \end{macrocode}
% Now adjust the left margin as much as needed
% to fit the contents.
%    \begin{macrocode}
  \dimen@\dimexpr\@tempdima-\eql@line@widthsep@\eql@colsep@\relax
  \ifdim\eql@marginleft@>\dimen@
    \eql@marginleft@\dimen@
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Placement for Left Tags.}
%
%   \macro{\eql@adjust@columns@test@tagsleft}
% Test whether the spacing can be adjusted to make the current row fit:
%    \begin{macrocode}
\def\eql@adjust@columns@test@tagsleft{%
%    \end{macrocode}
% The register |\@tempdima| will hold the deficit amount of space
% at the beginning of the row without adjustable space,
% and the register |\count@| will hold the number of
% intercolumn spaces that would contribute to space adjustments.
%    \begin{macrocode}
  \count@\numexpr\eql@intercolumns@-\eql@line@availsep@\relax
  \@tempdima\dimexpr\eql@tagwidth@-\eql@line@avail@\relax
%    \end{macrocode}
% Test whether the space at the beginning of the row
% is sufficient to hold the tag with the current settings.
%    \begin{macrocode}
  \ifdim\@tempdima>\dimexpr
      \eql@marginleft@+\eql@line@availsep@\eql@colsep@\relax
%    \end{macrocode}
% If not, first verify that the tag will fit the line
% (or the maxumal left margin in left alignment layout).
%    \begin{macrocode}
    \ifdim\eql@tagwidth@<%
        \ifdefined\eql@layoutleft
          \glueexpr\eql@layoutleftmarginmax\relax
        \else
          \displaywidth
        \fi
%    \end{macrocode}
% If so, determine whether the row and tag may at all
% fit into the available space with minimal intercolumn spaces.
%    \begin{macrocode}
      \ifdim\@tempdima>\dimexpr
          \displaywidth-\eql@totalwidth@-\count@\eql@colsepmin@\relax\else
%    \end{macrocode}
% If so, hand over to |\eql@adjust@columns@modify@tagsleft|.
%    \begin{macrocode}
        \eql@adjust@columns@modify@tagsleft
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@adjust@columns@modify@tagsleft}
% Adjust the intercolumn space and left margin to make the row fit.
%    \begin{macrocode}
\def\eql@adjust@columns@modify@tagsleft{%
%    \end{macrocode}
% If there are any intercolumn spaces that contribute to the available space,
% determine how much intercolumn separation would be needed
% while keeping the current right margin fixed.
% In central alignment layout,
% assume that the right margin will be adjusted
% to match the intercolumn separation
% by stepping the number of columns to divide by.
%    \begin{macrocode}
  \ifnum\count@>\z@
    \dimen@\dimexpr\displaywidth-\eql@totalwidth@-\@tempdima\relax
    \ifdefined\eql@columns@fulllength\else
      \advance\count@\@ne
    \fi
    \divide\dimen@\count@
%    \end{macrocode}
% If smaller, reduce the intercolumn separation,
% but make sure to not exceed the minumum allowed value.
% Also adjust the left margin to keep the right margin fixed.
%    \begin{macrocode}
    \ifdim\dimen@<\eql@colsep@
      \ifdim\dimen@<\eql@colsepmin@
        \dimen@\eql@colsepmin@
      \fi
      \advance\dimen@-\eql@colsep@
      \advance\eql@marginleft@-\eql@intercolumns@\dimen@
      \advance\eql@colsep@\dimen@
    \fi
  \fi
%    \end{macrocode}
% Now adjust the left margin as much as needed
% to fit the contents.
%    \begin{macrocode}
  \dimen@\dimexpr\@tempdima-\eql@line@availsep@\eql@colsep@\relax
  \ifdim\eql@marginleft@<\dimen@
    \eql@marginleft@\dimen@
  \fi
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Single Column Arrangement}
%
% The following code adjusts individual lines of equations
% for the equation and lines mode
% according to the selected layout and shape.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Supporting Definitions}
%
%   \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}
%
%   \macro{\eql@alignbadness@}
%   \macro{\eql@tagbadness@}
% The registers |\eql@alignbadness@| and |\eql@tagbadness@|
% 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@alignbadness@
\newcount\eql@tagbadness@
\newcount\eql@arrange@badness@
\eql@alignbadness@\inf@bad
\eql@tagbadness@\inf@bad
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Arrangement Methods}
%
%   \macro{\eql@arrange@try}
% Try to fit the current equation line in the available space.
% Argument |#1| specifies the amount of reserved space.
% Unpack the box |\eql@cellbox@|, replace the previous kerning
% with the new reserved space, and save the box back into |\eql@cellbox@|:
%    \begin{macrocode}
\def\eql@arrange@try#1{%
  \ifdim#1>\dimexpr\displaywidth-\eql@cellwidth@\relax
    \setbox\eql@cellbox@\hbox to\displaywidth{%
      \unhbox\eql@cellbox@\unkern\kern#1}%
    \eql@arrange@badness@\badness
  \else
    \eql@arrange@badness@\m@ne
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@arrange@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|:
% \TODO adjust
%    \begin{macrocode}
\def\eql@arrange@print#1#2{%
  \eql@restore@hfuzz
  \if@eqnsw
    \ifdefined\eql@tagsleft
      \eql@tagbox@print@tagsleft
    \fi
  \fi
  \hbox to\displaywidth{%
    #1%
    \unhbox\eql@cellbox@\unkern
    #2%
    \eql@tagging@mathaddlast
  }%
  \if@eqnsw
    \ifdefined\eql@tagsleft\else
      \eql@tagbox@print@tagsright
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@arrange@print@alignleft}
%   \macro{\eql@arrange@print@aligncenter}
%   \macro{\eql@arrange@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@arrange@print@alignleft#1#2{%
  \eql@display@firstavail@set{\dimexpr#1\relax}%
  \eql@arrange@print{\kern#1}{\kern#2}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@arrange@print@alignright#1#2{%
  \eql@display@firstavail@set{\dimexpr\displaywidth-\eql@cellwidth@-#2\relax}%
  \eql@arrange@print{\kern#1\hfil}{\unskip\kern#2}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@arrange@print@aligncenter#1{%
  \eql@display@firstavail@set{\dimexpr
      (\displaywidth-\eql@cellwidth@+#1)/\tw@\relax}%
  \ifdim#1>\z@
    \eql@arrange@print{\kern#1\hfil}{}%
  \else
    \eql@arrange@print{\hfil}{\kern-#1}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@arrange@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@arrange@init{%
  \eql@save@hfuzz
  \hfuzz\maxdimen
  \eql@shape@select
}
%    \end{macrocode}
%
%   \macro{\eql@arrange@print@line}
% Select the appropriate adjustment method depending
% on the current alignment position,
% the selected tag placement if any:
% \TODO adjust
%    \begin{macrocode}
\def\eql@arrange@print@line{%
  \eql@tagging@tagaddbox
  \csname eql@arrange%
    @\ifcase\eql@shape@pos@ alignleft\or aligncenter\or alignright\fi
    @init\endcsname
  \csname eql@arrange%
    @\ifcase\eql@shape@pos@ alignleft\or aligncenter\or alignright\fi
    @\ifdefined\eql@tagpos@reserve
      \ifdefined\eql@tagsleft tagsleft\else tagsright\fi\else
      notag\fi\endcsname
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Central Alignment}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@arrange@aligncenter@init{%
  \eql@tagging@aligncenter
  \eql@line@offset@\dimexpr\tw@\eql@shape@amount@
       +\eql@marginleft@-\eql@marginright@+\eql@centeroffset@\relax
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@arrange@aligncenter@notag{%
  \ifdim\dimexpr\displaywidth-\eql@cellwidth@\relax>%
      \ifdim\eql@line@offset@<\eql@marginleft@min@
        \dimexpr\tw@\eql@marginleft@min@-\eql@line@offset@\relax
      \else
        \eql@line@offset@
      \fi
    \eql@arrange@print@aligncenter\eql@line@offset@
  \else
    \ifdim\eql@line@offset@<\eql@marginleft@min@
      \eql@arrange@print@alignleft\eql@marginleft@min@\z@
    \else
      \eql@arrange@print@alignright\eql@marginleft@min@\z@
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@arrange@aligncenter@tagsright{%
  \ifdim\dimexpr\displaywidth-\eql@cellwidth@\relax>%
      \ifdim\eql@line@offset@<\dimexpr\eql@marginleft@min@-\eql@tagwidth@\relax
        \dimexpr\tw@\eql@marginleft@min@-\eql@line@offset@\relax
      \else
        \dimexpr\tw@\eql@tagwidth@+\eql@line@offset@\relax
      \fi
    \eql@arrange@print@aligncenter\eql@line@offset@
  \else
    \eql@arrange@try{\dimexpr\eql@tagwidth@+\eql@marginleft@min@\relax}%
    \ifnum\eql@arrange@badness@<\eql@tagbadness@
      \ifdim\eql@line@offset@<\dimexpr\eql@marginleft@min@-\eql@tagwidth@\relax
        \eql@arrange@print@alignleft\eql@marginleft@min@\eql@tagwidth@
      \else
        \eql@arrange@print@alignright\eql@marginleft@min@\eql@tagwidth@
      \fi
    \else
      \let\eql@tagpos@reserve\eql@false
      \eql@arrange@aligncenter@notag
    \fi
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@arrange@aligncenter@tagsleft{%
  \ifdim\eql@tagwidth@>\eql@marginleft@min@
    \ifdim\dimexpr\displaywidth-\eql@cellwidth@\relax>%
        \ifdim\eql@line@offset@<\eql@tagwidth@
          \dimexpr\tw@\eql@tagwidth@-\eql@line@offset@\relax
        \else
          \eql@line@offset@
        \fi
      \eql@arrange@print@aligncenter\eql@line@offset@
    \else
      \eql@arrange@try\eql@tagwidth@
      \ifnum\eql@arrange@badness@<\eql@tagbadness@
        \ifdim\eql@line@offset@<\eql@tagwidth@
          \eql@arrange@print@alignleft\eql@tagwidth@\z@
        \else
          \eql@arrange@print@alignright\eql@tagwidth@\z@
        \fi
      \else
        \let\eql@tagpos@reserve\eql@false
        \eql@arrange@aligncenter@notag
      \fi
    \fi
  \else
    \eql@arrange@aligncenter@notag
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Left Alignment}
%
%    \begin{macrocode}
\def\eql@arrange@alignleft@init{%
  \eql@tagging@alignleft
  \eql@line@offset@\dimexpr\eql@marginleft@+\eql@shape@amount@\relax
  \ifdim\eql@line@offset@<\eql@marginleft@min@
    \eql@line@offset@\eql@marginleft@min@
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@arrange@alignleft@notag{%
  \ifdim\eql@line@offset@>\eql@marginleft@min@
    \eql@arrange@try\eql@line@offset@
    \ifnum\eql@arrange@badness@<\eql@alignbadness@
      \eql@arrange@print@alignleft\eql@line@offset@\z@
    \else
      \eql@arrange@print@alignright\eql@marginleft@min@\z@
    \fi
  \else
    \eql@arrange@print@alignleft\eql@marginleft@min@\z@
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@arrange@alignleft@tagsright{%
  \eql@arrange@try{\dimexpr\eql@line@offset@+\eql@tagwidth@\relax}%
  \ifnum\eql@arrange@badness@<\eql@alignbadness@
    \eql@arrange@print@alignleft\eql@line@offset@\eql@tagwidth@
  \else
    \ifdim\eql@line@offset@>\eql@marginleft@min@
      \eql@arrange@try{\dimexpr\eql@marginleft@min@+\eql@tagwidth@\relax}%
    \fi
    \ifnum\eql@arrange@badness@<\eql@tagbadness@
      \eql@arrange@print@alignright\eql@marginleft@min@\eql@tagwidth@
    \else
      \let\eql@tagpos@reserve\eql@false
      \eql@arrange@alignleft@notag
    \fi
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@arrange@alignleft@tagsleft{%
  \ifdim\eql@tagwidth@>\eql@marginleft@min@
    \ifdim\eql@line@offset@>\eql@tagwidth@
      \eql@arrange@try\eql@line@offset@
      \ifnum\eql@arrange@badness@<\eql@alignbadness@
        \eql@arrange@print@alignleft\eql@line@offset@\z@
      \else
        \eql@arrange@try\eql@tagwidth@
        \ifnum\eql@arrange@badness@<\eql@tagbadness@
          \eql@arrange@print@alignright\eql@tagwidth@\z@
        \else
          \let\eql@tagpos@reserve\eql@false
          \eql@arrange@print@alignright\eql@marginleft@min@\z@
        \fi
      \fi
    \else
      \eql@arrange@try\eql@tagwidth@
      \ifnum\eql@arrange@badness@<\eql@tagbadness@
        \eql@arrange@print@alignleft\eql@tagwidth@\z@
      \else
        \let\eql@tagpos@reserve\eql@false
        \eql@arrange@alignleft@notag
      \fi
    \fi
  \else
    \eql@arrange@alignleft@notag
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Right Alignment}
%
%    \begin{macrocode}
\def\eql@arrange@alignright@init{%
  \eql@tagging@alignright
  \eql@line@offset@\dimexpr\eql@marginright@-\eql@shape@amount@\relax
  \ifdim\eql@line@offset@<\z@
    \eql@line@offset@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@arrange@alignright@notag{%
  \ifdim\eql@line@offset@>\z@
    \eql@arrange@try{\dimexpr\eql@marginleft@min@+\eql@line@offset@\relax}%
    \ifnum\eql@arrange@badness@<\eql@alignbadness@
      \eql@arrange@print@alignright\eql@marginleft@min@\eql@line@offset@
    \else
      \eql@arrange@print@alignleft\eql@marginleft@min@\z@
    \fi
  \else
    \eql@arrange@print@alignright\eql@marginleft@min@\z@
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@arrange@alignright@tagsright{%
  \ifdim\eql@line@offset@>\eql@tagwidth@
    \eql@arrange@try{\dimexpr\eql@marginleft@min@+\eql@line@offset@\relax}%
    \ifnum\eql@arrange@badness@<\eql@alignbadness@
      \eql@arrange@print@alignright\eql@marginleft@min@\eql@line@offset@
    \else
      \eql@arrange@try{\dimexpr\eql@marginleft@min@+\eql@tagwidth@\relax}%
      \ifnum\eql@arrange@badness@<\eql@tagbadness@
        \eql@arrange@print@alignleft\eql@marginleft@min@\eql@tagwidth@
      \else
        \let\eql@tagpos@reserve\eql@false
        \eql@arrange@print@alignleft\eql@marginleft@min@\z@
      \fi
    \fi
  \else
    \eql@arrange@try{\dimexpr\eql@marginleft@min@+\eql@tagwidth@\relax}%
    \ifnum\eql@arrange@badness@<\eql@tagbadness@
      \eql@arrange@print@alignright\eql@marginleft@min@\eql@tagwidth@
    \else
      \let\eql@tagpos@reserve\eql@false
      \eql@arrange@alignright@notag
    \fi
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@arrange@alignright@tagsleft{%
  \ifdim\eql@tagwidth@>\eql@marginleft@min@
    \eql@arrange@try{\dimexpr\eql@line@offset@+\eql@tagwidth@\relax}%
    \ifnum\eql@arrange@badness@<\eql@alignbadness@
      \eql@arrange@print@alignright\eql@tagwidth@\eql@line@offset@
    \else
      \ifdim\eql@line@offset@>\z@
        \eql@arrange@try\eql@tagwidth@
      \fi
      \ifnum\eql@arrange@badness@<\eql@tagbadness@
        \eql@arrange@print@alignleft\eql@tagwidth@\z@
      \else
        \let\eql@tagpos@reserve\eql@false
        \eql@arrange@alignright@notag
      \fi
    \fi
  \else
    \eql@arrange@alignright@notag
  \fi
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Equations Box Environment}
%
% \TODO outline sequence of calls
%
% \TODO describe
%
% \TODO fixed width version (works only towards intercolumn stretch)?
%
% \TODO vspace?!
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Line Breaks}
%
% \TODO describe
%
%   \macro{\eql@box@cr}
%    \begin{macrocode}
\def\eql@box@cr{%
  \ifmmode\else\unskip\fi
  \eql@vspaceskip@\z@skip
  \eql@ampprotect\eql@box@cr@testall\eql@box@cr@process}
%    \end{macrocode}
%
%   \macro{\eql@box@cr@testall}
%   \macro{\eql@box@cr@parse}
% \TODO describe
%    \begin{macrocode}
\def\eql@box@cr@testall{\eql@parseopt@aux\eql@box@cr@parse}
\def\eql@box@cr@parse{%
  \ifx\eql@parseopt@token[%
    \let\eql@parseopt@next\eql@parseopt@vspace
  \fi
  \ifx\eql@parseopt@token*%
    \let\eql@parseopt@next\eql@parseopt@gobble
  \fi
  \ifx\eql@parseopt@token.%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token,%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token~%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token`%
    \let\eql@parseopt@next\eql@parseopt@punctnext
  \fi
  \ifx\eql@parseopt@token&%
    \let\eql@parseopt@next\eql@parseopt@end
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@box@cr@process}
%    \begin{macrocode}
\def\eql@box@cr@process{%
  \eql@box@endline
  \expandafter\eql@box@cr@vskip\expandafter{\the\eql@vspaceskip@}%
}
%    \end{macrocode}
%
%   \macro{\eql@box@endline}
%    \begin{macrocode}
\def\eql@box@endline{%
  \eql@punct@apply@line
  \eql@hook@lineout
}
%    \end{macrocode}
%
%   \macro{\eql@box@cr@vskip}
%    \begin{macrocode}
\def\eql@box@cr@vskip#1{%
  \eql@box@lastcell
  \cr
  \noalign{%
    \vskip#1\relax
  }%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Stacked Mode}
%
%    \begin{macrocode}
\def\eql@box@lastcell@stacked{&\omit\kern-2\eql@colsep@}
%    \end{macrocode}
%
% \TODO templates
%    \begin{macrocode}
\def\eql@box@open@stacked{%
  \eql@shape@align@enable
  \let\eql@box@lastcell\eql@box@lastcell@stacked
  \everycr{\noalign{%
    \eql@verbose@info\eql@verbose@msg@startline
    \global\advance\eql@row@\@ne
  }}%
  \tabskip\z@skip
  \halign\bgroup
    &%
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \ifdefined\eql@shape@lastrow
        \eql@totalrows@\eql@row@
      \fi
      \eql@shape@eval
      \eql@cell@container
      \ifdefined\eql@frame@cmd
        \ifcase\eql@shape@pos@
          \eql@frame@measure
          \advance\eql@shape@amount@-\eql@frame@margin@
        \or\or
          \eql@frame@measure
          \advance\eql@shape@amount@+\eql@frame@margin@
        \fi
        \eql@frame@print
      \fi
      \ifcase\eql@shape@pos@
        \kern\eql@shape@amount@
        \box\eql@cellbox@
        \hskip\glueexpr\eql@paddingleft@+\eql@paddingright@
          -\eql@shape@amount@+\@flushglue\relax
        \eql@tagging@alignleft
      \or
        \hskip\glueexpr\eql@paddingleft@+\eql@shape@amount@+\@flushglue\relax
        \box\eql@cellbox@
        \hskip\glueexpr\eql@paddingright@-\eql@shape@amount@+\@flushglue\relax
        \eql@tagging@aligncenter
      \or
        \hskip\glueexpr\eql@paddingleft@+\eql@paddingright@
          +\eql@shape@amount@+\@flushglue\relax
        \box\eql@cellbox@
        \kern-\eql@shape@amount@
        \eql@tagging@alignright
      \fi
      \tabskip\eql@colsep@\relax
    \crcr
    \noalign{%
      \global\let\eql@shape@lastrow\eql@false
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@mode@stacked{\let\eql@box@open\eql@box@open@stacked}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Aligned Mode}
%
%    \begin{macrocode}
\def\eql@box@lastcell@odd{%
  &\omit
  \eql@prevwidth@\wd\eql@cellbox@
  \let\eql@frame@cmd\eql@frame@prevcmd
  \ifdefined\eql@frame@cmd
    \eql@frame@measure
    \advance\eql@prevwidth@\eql@frame@margin@
    \eql@frame@print
  \fi
  \kern-\eql@prevwidth@
  \unhbox\eql@cellbox@
  \hfil
  &\omit\kern-\eql@colsep@
}%
\def\eql@box@lastcell@even{&\omit\kern-\eql@colsep@}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@verbose@msg@startline@aligned{starting new line}
\def\eql@box@open@aligned{%
% \TODO templates
  \eql@shape@align@disable
  \let\eql@box@lastcell\@empty
  \everycr{\noalign{%
    \eql@verbose@info\eql@verbose@msg@startline@aligned
  }}%
  \tabskip\z@skip
  \halign\bgroup
    &%
      \let\eql@box@lastcell\eql@box@lastcell@odd
      \global\let\eql@cell@container\@empty
      \global\setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@next
          \eql@class@innerleft
          \eql@hook@innerleft
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \eql@cell@container
      \hfil
      \kern\wd\eql@cellbox@
      \ifdefined\eql@frame@cmd
        \eql@frame@measure
        \kern\eql@frame@margin@
      \fi
      \global\let\eql@frame@prevcmd\eql@frame@cmd
      \tabskip\z@skip
    &%
      \eql@prevwidth@\wd\eql@cellbox@
      \let\eql@box@lastcell\eql@box@lastcell@even
      \let\eql@frame@cmd\eql@frame@prevcmd
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \unhbox\eql@cellbox@
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@innerright
          \eql@class@innerright@sel
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \eql@cell@container
      \ifdefined\eql@frame@cmd
        \eql@frame@measure
        \advance\eql@prevwidth@\eql@frame@margin@
        \eql@frame@print
      \fi
      \kern-\eql@prevwidth@
      \unhbox\eql@cellbox@
      \hfil
      \tabskip\eql@colsep@\relax
    \crcr
    \noalign{%
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@mode@aligned{\let\eql@box@open\eql@box@open@aligned}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Cases Mode}
%
% \TODO describe
%
% \TODO how to get proper height in tagging (and avoid nulldelimiterspace)
% \TODO add alignment?
%
%    \begin{macrocode}
\def\eql@box@lastcell@cases{&}%
%    \end{macrocode}
%
%    \begin{macrocode}
\let\eql@box@cases@condtext\eql@false
\let\eql@box@cases@condintro\@empty
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@verbose@msg@startline@cases{starting new line}
\def\eql@box@open@cases{%
  \eql@shape@align@disable
  \let\eql@box@lastcell\@empty
  \everycr{\noalign{%
    \eql@verbose@info\eql@verbose@msg@startline@cases
  }}%
  \tabskip\z@skip
  \halign\bgroup
      \let\eql@box@lastcell\eql@box@lastcell@cases
      \global\let\eql@cell@container\@empty
      \global\setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@next
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \eql@cell@container
      \unhbox\eql@cellbox@
      \hfil
      \eql@tagging@alignleft
      \tabskip\eql@colsep@\relax
    &%
      \let\eql@box@lastcell\@empty
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \unhbox\eql@cellbox@
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \ifdefined\eql@box@cases@condtext
            \expandafter\hbox\else\expandafter\@firstofone\fi\bgroup
          \eql@box@cases@condintro
          ##%
          \eql@punct@apply@col
          \egroup
          \eql@hook@colout
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \eql@cell@container
      \unhbox\eql@cellbox@
      \hfil
      \eql@tagging@alignleft
      \tabskip\z@skip
    \crcr
    \noalign{%
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@mode@cases{\let\eql@box@open\eql@box@open@cases}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Main}
%
%    \begin{macrocode}
\let\eql@box@box\vcenter
\let\eql@box@open\@undefined
\let\eql@box@frame\@firstofone
\def\eql@box@wrap#1#2{\def\eql@box@frame##1{#1##1#2}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@delim#1#2{\def\eql@box@frame##1{\mathinner{\left#1##1\right#2}}}
\def\eql@box@getdim{\setbox\@ne\null\ht\@ne\ht\z@\dp\@ne\dp\z@}
\def\eql@box@deldim#1{\hbox{$\m@th\nulldelimiterspace\z@\left#1
  \ifx\eql@box@box\vcenter\vcenter{\box\@ne}\else\box\@ne\fi\right.$}}
\def\eql@box@ldelim#1{%
  \def\eql@box@frame##1{\mathinner{\eql@box@getdim\eql@box@deldim#1##1}}}
\def\eql@box@rdelim#1{%
  \def\eql@box@frame##1{\mathinner{\eql@box@getdim##1\eql@box@deldim#1}}}
%    \end{macrocode}
%
% \TODO can we avoid setting |\eql@totalrows@| globally here?
% \TODO this is needed for escaping the box and then set the alignment
% \TODO maybe determine alignment within inner math?!
% \TODO difficulty: last line being known (for steps) only after
% all cells have been processed.
% Note: only works for single column anyway! we do not have to cater for more!
%    \begin{macrocode}
\def\eql@box@close{%
    \ifvmode\else
      \ifmmode\else\unskip\fi
      \global\let\eql@shape@lastrow\eql@true
      \eql@punct@apply@block
      \eql@box@endline
      \eql@box@lastcell
      \cr
    \fi
    \noalign{%
      \eql@hook@blockafter
      \global\let\eql@shape@lastrow\eql@false
    }%
    \eql@tagging@tablesaveinner
  \egroup
}
%    \end{macrocode}
%
%   \macro{\eql@box@vcenter}
%    \begin{macrocode}
\def\eql@box@vcenter#1{%
  \ifmmode
    \vcenter{#1}%
  \else
    $\m@th\vcenter{#1}$%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@box@start}
%    \begin{macrocode}
\let\eql@box@endmath\eql@false
\def\eql@box@start{%
  \relax
  \ifmmode
    \let\eql@box@endmath\eql@false
  \else
    \let\eql@box@endmath\eql@true
    \expandafter$%$
  \fi
  \eql@box@processopt
  \eql@stack@save@box
  \let\eql@frame@cmd\@undefined
  \let\eql@layoutleft\eql@false
  \eql@row@\z@
  \eql@totalrows@\@M
  \eql@shape@select
  \setbox\z@\ifx\eql@box@box\vcenter
    \expandafter\vbox
  \else
    \expandafter\eql@box@box
  \fi\bgroup
    \eql@display@nest
    \let\\\eql@box@cr
    \eql@spread@set
    \eql@strut@make
    \eql@box@open
}
%    \end{macrocode}
%
%   \macro{\eql@box@end}
%    \begin{macrocode}
\def\eql@box@end{%
    \eql@box@close
  \egroup
  \eql@box@frame{%
    \ifdefined\eql@display@marginleft
      \hskip\glueexpr\eql@display@marginleft\relax
    \fi
    \ifx\eql@box@box\vcenter
      \eql@box@vcenter{\unvbox\z@}%
    \else
      \box\z@
    \fi
    \eql@tagging@tableaddinner
    \ifdefined\eql@display@marginright
      \hskip\glueexpr\eql@display@marginright\relax
    \fi
  }%
  \eql@stack@restore
  \ifdefined\eql@box@endmath
    \expandafter$%$
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Environment}
%
% \environment{equationsbox}
%    \begin{macrocode}
\newenvironment{equationsbox}{%
  \eql@verbose@info\eql@verbose@msg@enterenv
  \eql@ampprotect\eql@box@testall\eql@box@start
}{%
  \eql@box@end
  \eql@verbose@info\eql@verbose@msg@leaveenv
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@box@testall{\eql@parseopt@main\eql@box@parse}
\def\eql@box@parse{%
  \ifx\eql@parseopt@token[%]
    \let\eql@parseopt@next\eql@parseopt@opt
  \fi
  \ifx\eql@parseopt@token.%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token,%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token~%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token`%
    \let\eql@parseopt@next\eql@parseopt@punctopt
  \fi
  \ifx\eql@parseopt@token=%
    \let\eql@parseopt@next\eql@parseopt@lines
  \fi
  \ifx\eql@parseopt@token|%
    \let\eql@parseopt@next\eql@parseopt@columns
  \fi
  \ifx\eql@parseopt@token<%
    \let\eql@parseopt@next\eql@parseopt@ampeq
  \fi
  \ifx\eql@parseopt@token>%
    \let\eql@parseopt@next\eql@parseopt@eqamp
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@box@processopt}
% \TODO describe
%    \begin{macrocode}
\def\eql@box@processopt{%
  \let\eql@box@frame\@firstofone
  \let\eql@display@marginleft\@undefined
  \let\eql@display@marginright\@undefined
  \eql@nextopt@process{equationsbox}%
  \let\eql@punct@block\eql@punct@main
  \let\eql@punct@main\@undefined
  \eql@colsep@\glueexpr\eql@box@colsep\relax
  \ifdefined\eql@paddingleft@val
    \eql@paddingleft@\glueexpr\eql@paddingleft@val\relax
  \else
    \eql@paddingleft@\z@
  \fi
  \ifdefined\eql@paddingright@val
    \eql@paddingright@\glueexpr\eql@paddingright@val\relax
  \else
    \eql@paddingright@\z@
  \fi
  \eql@indent@\glueexpr\eql@indent@val\relax
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Single-Line Equation}
%
% \TODO describe
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Native Mode}
%
%    \begin{macrocode}
\def\eql@single@start@native{%
  \eql@display@init
  \eql@display@print
  \let\raisetag\eql@raisetag@default
  \eql@shape@align@disable
  \eql@hook@eqin
%  \mathopen{}%
}%
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@single@end@native{%
%  \mathclose{}%
  \eql@tags@container
  \eql@numbering@single@eval
  \if@eqnsw
    \ifdefined\eql@tagsleft
      \leqno
    \else
      \eqno
    \fi
    \eql@composetag@print
  \fi
  \eql@interline@container
  \advance\eql@belowspace@\eql@vspaceskip@
  \eql@display@container
  \eql@display@penalty
  \eql@display@vspace@native
}%
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Print}
%
%    \begin{macrocode}
\def\eql@single@start@print{%
  \eql@display@init
  \eql@display@print
  \eql@shape@align@enable
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@totalrows@\@ne
  \eql@row@\@ne
  \eql@arrange@init
  \global\let\eql@cell@container\@empty
%    \end{macrocode}
%
%    \begin{macrocode}
  \prevgraf\numexpr\prevgraf+\@ne\relax
  \setbox\eql@cellbox@\hbox\bgroup
    \eql@restore@hfuzz
    \eql@strut@cell
    $\m@th\eql@mathstyle%$
      \eql@hook@eqin
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@single@end@print{%
    \eql@tagging@mathsave
    $%$
    \hfil
    \kern\z@
  \egroup
  \prevgraf\numexpr\prevgraf-\@ne\relax
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@shape@eval
  \eql@cell@container
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifdefined\eql@frame@cmd
    \eql@frame@adjust
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@cellwidth@\wd\eql@cellbox@
  \eql@line@height@\ht\eql@cellbox@
  \eql@line@depth@\dp\eql@cellbox@
  \eql@totalwidth@\eql@cellwidth@
  \eql@totalheight@\dimexpr\eql@line@height@+\eql@line@depth@\relax
  \eql@topheight@\eql@line@height@
  \eql@bottomdepth@\eql@line@depth@
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@tags@container
  \eql@numbering@single@eval
  \if@eqnsw
    \eql@tagbox@make\eql@composetag@print
    \eql@tagrows@\@ne
    \ifdefined\eql@tagpos@reserve\else
      \eql@tagwidth@\z@
    \fi
    \eql@tagheight@block@\ht\eql@tagbox@
    \eql@tagdepth@block@\dp\eql@tagbox@
  \else
    \eql@numbering@warnunused
    \eql@tagwidth@\z@
    \eql@tagrows@\z@
  \fi
  \eql@tagwidth@max@\eql@tagwidth@
  \eql@tagpos@single@eval
  \eql@tagpos@print@line@eval
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@intercolumns@\z@
  \eql@adjust@calc@lines
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@display@halign@init{}%
  \halign{##\crcr
    \noalign{\eql@display@halign@start}%
    \eql@arrange@print@line
    \cr
    \noalign{\eql@display@halign@end}%
    \eql@tagging@tablesavelines
  }%
  \eql@tagpos@print@line@end
  \eql@display@close
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Multi-Line with Single Column}
%
% \TODO outline sequence of calls
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Measure}
%
% \TODO describe
%
%    \begin{macrocode}
\def\eql@lines@measure@line@begin{%
  \eql@verbose@info\eql@verbose@msg@startline
  \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
% \TODO it would be an option to add the absolute shove amount
% to the calculation of the maximum width
%    \begin{macrocode}
\def\eql@lines@measure@cell{%
  \ifdefined\eql@frame@cmd
    \ifcase\eql@shape@pos@
      \eql@frame@measure
      \advance\eql@shape@amount@-\eql@frame@margin@
    \or\or
      \eql@frame@measure
      \advance\eql@shape@amount@+\eql@frame@margin@
    \fi
    \eql@frame@print
  \fi
  \eql@cellwidth@\wd\eql@cellbox@
  \eql@line@height@\ht\eql@cellbox@
  \eql@line@depth@\dp\eql@cellbox@
  \eql@dimensions@startrow
  \eql@dimensions@savecell
  \kern\eql@cellwidth@
}
%    \end{macrocode}
%
%   \macro{\eql@lines@measure}
%    \begin{macrocode}
\def\eql@lines@measure{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@lines@measure
  \eql@measure@init\eql@lines@measure@line@begin\eql@lines@measure@line@end
  \eql@totalrows@\@M
  \eql@shape@select
%    \end{macrocode}
%
%    \begin{macrocode}
  \setbox\z@\vbox{\measuring@true\halign{%
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
        $%
      }%
      \ifdefined\eql@shape@lastrow
        \eql@totalrows@\eql@row@
      \fi
      \eql@shape@eval
      \eql@cell@container
      \eql@lines@measure@cell
      \eql@measure@tag
      \eql@measure@endrow
    \crcr
%    \end{macrocode}
%
%    \begin{macrocode}
    \noalign{%
      \global\let\eql@shape@lastrow\eql@false
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
    \eql@scan@body
    \ifvmode\else
      \global\let\eql@shape@lastrow\eql@true
      \eql@punct@apply@block
      \eql@hook@blockout
      \eql@display@endline
      \cr
    \fi
    \omit
    \cr
    \noalign{%
      \eql@hook@blockafter
      \global\let\eql@shape@lastrow\eql@false
    }%
  }}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@measure@close
%    \end{macrocode}
%
%    \begin{macrocode}
  \setbox\z@\vbox{%
    \unvbox\z@
    \unpenalty
    \global\setbox\@ne\lastbox
  }%
  \eql@totalwidth@\wd\@ne
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@verbose@infoarg\eql@verbose@msg@leave\eql@lines@measure
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Column Placement}
%
% \TODO describe
% Find the best row for tag placement:
%    \begin{macrocode}
\def\eql@lines@adjust{%
  \eql@tagpos@adjust@eval
  \eql@adjust@calc@lines
  \eql@numbering@best@eval
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Print}
%
% \TODO describe
%
%   \macro{\eql@lines@print@line@begin}
%    \begin{macrocode}
\def\eql@lines@print@line@begin{%
  \eql@verbose@info\eql@verbose@msg@startline
  \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{%
  \ifdefined\eql@frame@cmd
    \ifcase\eql@shape@pos@
      \eql@frame@measure
      \advance\eql@shape@amount@-\eql@frame@margin@
    \or\or
      \eql@frame@measure
      \advance\eql@shape@amount@+\eql@frame@margin@
    \fi
    \eql@frame@adjust
  \fi
  \eql@cellwidth@\wd\eql@cellbox@
  \eql@line@height@\ht\eql@cellbox@
  \eql@line@depth@\dp\eql@cellbox@
  \eql@numbering@print@line@eval
  \if@eqnsw
    \eql@tagbox@make\eql@composetag@print
  \fi
  \eql@tagpos@print@line@eval
  \eql@arrange@print@line
  \eql@tagpos@print@line@end
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@lines@print{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@lines@print
  \eql@arrange@init
  \eql@display@halign@init\eql@lines@print@line@begin
  \eql@display@halign@letcr\eql@lines@print@line@end
  \tabskip\z@skip
%    \end{macrocode}
%
%    \begin{macrocode}
  \halign{%
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \eql@restore@hfuzz
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
          \eql@tagging@mathsave
        $%
        \hfil
        \kern\z@
      }%
      \eql@shape@eval
      \eql@cell@container
      \eql@lines@print@line@adjust
    \crcr
%    \end{macrocode}
%
%    \begin{macrocode}
    \noalign{%
      \eql@display@halign@start
      \eql@numbering@print@block@begin
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
    \eql@scan@body
    \ifvmode\else
      \relax
      \eql@punct@apply@block
      \eql@hook@blockout
      \eql@display@endline
      \cr
    \fi
    \noalign{%
      \eql@hook@blockafter
      \eql@display@halign@end
      \eql@verbose@infoarg\eql@verbose@msg@leave\eql@lines@print
    }%
    \eql@tagging@tablesavelines
  }%
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Multi-Line with Multiple Columns}
%
% \TODO describe
% \TODO outline sequence of calls
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Support}
%
% \TODO describe
%
%   \macro{\eql@columns@add@amp}
%   \macro{\eql@columns@completerow}
%    \begin{macrocode}
\def\eql@columns@add@amp#1{\if m#1&\omit\expandafter\eql@columns@add@amp\fi}
\def\eql@columns@completerow{%
  \count@\numexpr\eql@totalcolumns@+\@ne-\eql@column@\relax
  \edef\eql@tmp{%
    \expandafter\eql@columns@add@amp\romannumeral\number\count@ 000q}%
  \eql@tmp
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@columns@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}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Transpose}
%
% \TODO describe
%
% \TODO describe
%    \begin{macrocode}
\let\eql@transpose@active\eql@false
\def\eql@transpose@end{\eql@transpose@end}
\def\eql@transpose@skip{&\eqnpunct{}}
\def\eql@transpose@complete{%
  \relax\ifodd\eql@column@\expandafter\eql@transpose@skip\fi&}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose{%
  \eql@totalcolumns@\z@
  \eql@totalrows@\z@
  \expandafter\eql@transpose@scan@col\the\eql@scan@reg@\&\eql@transpose@end\&
  \eql@scan@reg@{}%
  \eql@row@\z@
  \eql@transpose@output@row
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@save@col#1{%
  \@namedef{eql@transpose@data@col@\the\eql@totalcolumns@}{%
    \ifcase\eql@row@#1\else\let\eql@tmp\eql@transpose@skip\fi}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@scan@col#1\&{%
  \def\eql@tmpa{#1}%
  \ifx\eql@tmpa\eql@transpose@end\else
    \advance\eql@totalcolumns@\@ne
    \eql@row@\z@
    \let\eql@transpose@data@col\@empty
    \eql@transpose@scan@row#1\\\eql@transpose@end\\%
    \ifnum\eql@row@>\eql@totalrows@
      \eql@totalrows@\eql@row@
    \fi
    \expandafter\eql@transpose@save@col\expandafter{\eql@transpose@data@col}%
    \expandafter\eql@transpose@scan@col
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@append@row#1{%
  \advance\eql@row@\@ne
  \eql@append\eql@transpose@data@col{\or\def\eql@tmp{#1}}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@scan@row#1\\{%
  \def\eql@tmpa{#1}%
  \ifx\eql@tmpa\eql@transpose@end\else
    \ifx\eql@transpose@active+
      \eql@transpose@scan@cell#1&\eql@transpose@end&%
    \else
      \eql@transpose@append@row{#1}%
    \fi
    \expandafter\eql@transpose@scan@row
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@scan@cell#1&#2&{%
  \def\eql@tmpa{#2}%
  \ifx\eql@tmpa\eql@transpose@end
    \eql@transpose@append@row{#1}%
  \else
    \eql@transpose@append@row{#1&#2}%
    \expandafter\eql@transpose@scan@cell@next
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@scan@cell@next#1&{%
  \def\eql@tmpa{#1}%
  \ifx\eql@tmpa\eql@transpose@end\else
    \eql@transpose@append@row{&#1}%
    \expandafter\eql@transpose@scan@cell@next
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@output@row{%
  \ifnum\eql@row@<\eql@totalrows@
    \advance\eql@row@\@ne
    \eql@column@\z@
    \eql@transpose@output@col
    \ifnum\eql@row@<\eql@totalrows@
      \eql@scan@addto\\%
    \fi
    \expandafter\eql@transpose@output@row
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@transpose@output@col{%
  \ifnum\eql@column@<\eql@totalcolumns@
    \advance\eql@column@\@ne
    \csname eql@transpose@data@col@\the\eql@column@\endcsname
    \expandafter\eql@scan@addto\expandafter{\eql@tmp}%
    \ifnum\eql@column@<\eql@totalcolumns@
      \eql@scan@addto{\eql@transpose@complete}%
    \fi
    \expandafter\eql@transpose@output@col
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Measure}
%
% \TODO describe
% \TODO this is called also for extra line and concluding cr
%   \macro{\eql@columns@measure@line@begin}
%    \begin{macrocode}
\def\eql@columns@measure@line@begin{%
  \eql@verbose@info\eql@verbose@msg@startline
  \global\eql@column@\z@
  \global\eql@line@height@\z@
  \global\eql@line@depth@\z@
  \eql@numbering@measure@line@begin
  \eql@hook@linein
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@columns@measure@cell{%
  \eql@cellwidth@\wd\eql@cellbox@
  \ifdefined\eql@frame@cmd
    \eql@frame@measure
    \advance\eql@cellwidth@\eql@frame@margin@
  \fi
  \ifdim\ht\eql@cellbox@>\eql@line@height@
    \global\eql@line@height@\ht\eql@cellbox@
  \fi
  \ifdim\dp\eql@cellbox@>\eql@line@depth@
    \global\eql@line@depth@\dp\eql@cellbox@
  \fi
  \ifnum\eql@column@=\@ne
    \eql@dimensions@startrow
  \fi
  \ifodd\eql@column@
    \eql@shape@pos@\tw@
  \else
    \eql@shape@pos@\z@
  \fi
  \eql@shape@amount@\z@
  \eql@dimensions@savecell
  \ifodd\eql@column@\else
    \eql@dimensions@savesep
  \fi
  \kern\eql@cellwidth@
}
%    \end{macrocode}
%
%   \macro{\eql@columns@measure@line@end}
%    \begin{macrocode}
\def\eql@columns@measure@line@end{%
  \eql@punct@apply@line
  \eql@hook@lineout
  &\omit
  \ifnum\eql@column@>\eql@totalcolumns@
    \global\eql@totalcolumns@\eql@column@
  \fi
%    \end{macrocode}
% \TODO not sure whether saving the last cell value makes sense,
%   but rather not increase |\eql@totalcolumns@|
%   because that will disable the fallback to lines mode.
% \TODO additional column in width table is accounted for in column table
%    \begin{macrocode}
  \ifdefined\eql@frame@cmd
    \advance\eql@column@\@ne
    \wd\eql@cellbox@\z@
    \eql@columns@measure@cell
  \fi
  \eql@measure@tag
  \eql@measure@endrow
}
%    \end{macrocode}
%
%   \macro{\eql@columns@measure}
%    \begin{macrocode}
\def\eql@columns@measure{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@columns@measure
  \eql@totalcolumns@\z@
  \eql@measure@init\eql@columns@measure@line@begin\eql@columns@measure@line@end
%    \end{macrocode}
%
%    \begin{macrocode}
  \setbox\z@\vbox{\measuring@true\halign{%
    &%
      \global\advance\eql@column@\@ne
      \global\let\eql@cell@container\@empty
      \global\setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@next
          \eql@class@innerleft
          \eql@hook@innerleft
        $%
      }%
      \eql@cell@container
      \hfil
      \eql@columns@measure@cell
      \global\let\eql@frame@prevcmd\eql@frame@cmd
    &%
      \eql@prevwidth@\wd\eql@cellbox@
      \let\eql@frame@cmd\eql@frame@prevcmd
      \global\advance\eql@column@\@ne
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@innerright
          \eql@class@innerright@sel
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
        $%
      }%
      \eql@cell@container
      \eql@columns@measure@cell
      \hfil
    \crcr
%    \end{macrocode}
%
%    \begin{macrocode}
    \noalign{%
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
    \eql@scan@body
%    \end{macrocode}
%
%    \begin{macrocode}
    \ifvmode\else
      \eql@punct@apply@block
      \eql@hook@blockout
      \eql@display@endline
      \cr
    \fi
    \noalign{%
      \eql@hook@blockafter
    }%
%    \end{macrocode}
%    \TODO note we also include the tag column as a backup
%    \begin{macrocode}
    \omit
    \eql@column@\@ne
    \eql@columns@completerow
    \cr
  }}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@measure@close
%    \end{macrocode}
%
%    \begin{macrocode}
  \setbox\z@\vbox{%
    \unvbox\z@
    \unpenalty
    \global\setbox\@ne\lastbox
  }%
  \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@colwidth@save{\wd\thr@@}%
  \repeat
%    \end{macrocode}
%
%    \begin{macrocode}
  \eql@verbose@infoarg\eql@verbose@msg@leave\eql@columns@measure
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Columns Placement}
%
% \TODO describe
% Make sure we have complete pairs of right and left adjusted columns,
% otherwise add a final empty column:
%    \begin{macrocode}
\def\eql@columns@adjust{%
  \ifodd\eql@totalcolumns@
    \advance\eql@totalcolumns@\@ne
  \fi
  \eql@tagpos@adjust@eval
  \eql@adjust@calc@columns
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Print}
%
% \TODO describe
%
%   \macro{\eql@columns@print@line@begin}
%    \begin{macrocode}
\def\eql@columns@print@line@begin{%
  \eql@verbose@info\eql@verbose@msg@startline
  \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@columns@print@cell}
%    \begin{macrocode}
\def\eql@columns@print@cell{%
  \eql@cellwidth@\wd\eql@cellbox@
  \ifodd\eql@column@
    \ifdefined\eql@frame@cmd
      \eql@frame@measure
      \advance\eql@cellwidth@\eql@frame@margin@
    \fi
    \dimen@\z@
  \else
    \advance\eql@cellwidth@-\eql@prevwidth@
%    \end{macrocode}
% draw a frame
%    \begin{macrocode}
    \ifdefined\eql@frame@cmd
      \eql@frame@measure
      \advance\eql@cellwidth@\eql@frame@margin@
      \advance\eql@prevwidth@\eql@frame@margin@
      \eql@frame@print
    \fi
%    \end{macrocode}
% update height and depth
%    \begin{macrocode}
    \ifdim\ht\eql@cellbox@>\eql@line@height@
      \global\eql@line@height@\ht\eql@cellbox@
    \fi
    \ifdim\dp\eql@cellbox@>\eql@line@depth@
      \global\eql@line@depth@\dp\eql@cellbox@
    \fi
%    \end{macrocode}
%    print box
%    \begin{macrocode}
    \kern-\eql@prevwidth@
    \unhbox\eql@cellbox@
    \dimen@-\eql@cellwidth@
  \fi
%    \end{macrocode}
% enforce given width:
% hopefully measure was correct, but need a precise width for tag placement
%    \begin{macrocode}
  \advance\dimen@\eql@colwidth@get\eql@column@\relax
  \kern\dimen@
%    \end{macrocode}
% update available and used space
%    \begin{macrocode}
  \dimen@\eql@colwidth@get\eql@column@\relax
  \ifdim\eql@cellwidth@>\z@
    \ifdim\eql@line@width@=\z@
      \eql@line@avail@\eql@line@pos@
      \ifodd\eql@column@
        \advance\eql@line@avail@\dimen@
        \advance\eql@line@avail@-\eql@cellwidth@
      \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@\eql@cellwidth@
    \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}
%
%    \begin{macrocode}
\def\eql@columns@print@trailright{%
   &\omit
    \eql@prevwidth@\wd\eql@cellbox@
    \let\eql@frame@cmd\eql@frame@prevcmd
    \global\advance\eql@column@\@ne
    \eql@columns@print@cell
}
%    \end{macrocode}
%
%   \macro{\eql@columns@print@line@end}
%    \begin{macrocode}
\def\eql@columns@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@columns@print@trailright
  \fi
  \eql@columns@completerow
  \eql@columns@print@tag
}
%    \end{macrocode}
%
%   \macro{\eql@columns@print@tag}
%    \begin{macrocode}
\def\eql@columns@print@tag{%
  \kern-\dimexpr\eql@totalwidth@+\eql@colsep@\relax
%    \end{macrocode}
% determine first line available space
%    \begin{macrocode}
  \eql@display@firstavail@set\eql@line@avail@
  \eql@columns@overfull
  \eql@numbering@print@line@eval
  \if@eqnsw
    \eql@tagbox@make\eql@composetag@print
  \fi
  \eql@tagpos@print@line@eval
  \eql@tagbox@print@cell
  \eql@tagpos@print@line@end
}
%    \end{macrocode}
%
%   \macro{\eql@columns@print}
%    \begin{macrocode}
\def\eql@columns@print{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@columns@print
  \eql@shape@align@disable
  \eql@display@halign@init\eql@columns@print@line@begin
  \eql@display@halign@letcr\eql@columns@print@line@end
  \tabskip\eql@marginleft@
%    \end{macrocode}
%
%    \begin{macrocode}
  \halign{%
    &%
      \global\advance\eql@column@\@ne
      \global\let\eql@cell@container\@empty
      \global\setbox\eql@cellbox@\hbox{%
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@colin
          ##%
          \eql@punct@apply@next
          \eql@class@innerleft
          \eql@hook@innerleft
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \eql@cell@container
      \hfil
      \eql@columns@print@cell
      \global\let\eql@frame@prevcmd\eql@frame@cmd
      \tabskip\z@skip
    &%
      \eql@prevwidth@\wd\eql@cellbox@
      \let\eql@frame@cmd\eql@frame@prevcmd
      \global\advance\eql@column@\@ne
      \global\let\eql@cell@container\@empty
      \setbox\eql@cellbox@\hbox{%
        \unhbox\eql@cellbox@
        \eql@strut@cell
        \@lign
        $\m@th\eql@mathstyle
          \eql@hook@innerright
          \eql@class@innerright@sel
          ##%
          \eql@punct@apply@col
          \eql@hook@colout
          \eql@tagging@mathsave
        $%
        \eql@tagging@mathaddlast
      }%
      \eql@cell@container
      \eql@columns@print@cell
      \hfil
      \tabskip\eql@colsep@\relax
    \crcr
%    \end{macrocode}
%
%    \begin{macrocode}
    \noalign{%
      \eql@display@halign@start
      \eql@numbering@print@block@begin
      \eql@hook@blockbefore
    }%
    \eql@hook@blockin
    \eql@scan@body
    \ifvmode\else
      \relax
      \eql@punct@apply@block
      \eql@hook@blockout
      \eql@display@endline
      \cr
    \fi
    \noalign{%
      \eql@hook@blockafter
      \eql@display@halign@end
      \eql@verbose@infoarg\eql@verbose@msg@leave\eql@columns@print
    }%
    \eql@tagging@tablesavealign
  }%
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Interface}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Scanning the Equation Body}
%
% The multi-line equatiuon environment must scan its body twice:
% once to determine how wide the columns are and then to actually
% typeset them. This means that we must collect all text in this body
% before calling the environment macros.
% The mechanism and its description follows \amsmath/ closely.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Token Register.}
%
%   \macro{\eql@scan@reg@}
% We start by defining a token register to hold the equation body.
%    \begin{macrocode}
\newtoks\eql@scan@reg@
%    \end{macrocode}
%
%   \macro{\eql@scan@body@dump}
%   \macro{\eql@scan@body@rescan}
%   \macro{\eql@scan@body}
% The macro |\eql@scan@body@dump| dumps the equation body
% from the register so that we do not have to pass it
% around in arguments. The macro |\eql@scan@body@rescan|
% rescans the tokens so that special commands
% such as |\verb| can be processed properly.
% The register |\eql@scan@body|
% holds the currently selected mode of operation:
%    \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}
% We define a macro to append to the token register |\eql@scan@reg@|:
%    \begin{macrocode}
\long\def\eql@scan@addto#1{\eql@scan@reg@\expandafter{\the\eql@scan@reg@#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Scan Modifiers at End.}
%
%   \macro{\eql@scan@testend}
% Scan for modifiers following the end of the scanned block:
%    \begin{macrocode}
\def\eql@scan@testend{%
  \eql@ampprotect\eql@end@testall\eql@scan@end}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Environment Body.}
%
% The following mechanism scans the contents of an environment
% taking into account nested environments
% that may be contained in the body.
%
%   \macro{\eql@scan@env}
% The macro |\eql@scan@env| starts the scan for the |\end{...}|
% command of the current environment. The argument is a call-back macro
% to process the body in |\eql@scan@reg@|:
%    \begin{macrocode}
\def\eql@scan@env#1{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@scan@env
  \def\eql@scan@end{#1\expandafter\end\expandafter{\@currenvir}}%
  \eql@scan@reg@{}\def\eql@scan@stack{b}%
%    \end{macrocode}
% We call |\eql@scan@env@iterate| which will scan until
% the next occurrence of |\end| and then count the number
% of occurrences of |\begin| before |\end| in |\eql@scan@stack|.
% If we simply called |\eql@scan@env@iterate| directly,
% the error message for an unwanted |\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}
  \edef\eql@scan@iterate{\expandafter\noexpand\csname\@currenvir\endcsname}%
  \expandafter\let\expandafter\eql@scan@env@org\eql@scan@iterate
  \ifdefined\eql@scan@par
    \expandafter\let\eql@scan@iterate\eql@scan@env@iterate
  \else
    \expandafter\let\eql@scan@iterate\eql@scan@env@iterate@nopar
  \fi
  \eql@scan@iterate
}
%    \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
% via |\eql@scan@env@count|.
% An empty state for this stack means that we
% have reached the |\end| that matches our original |\begin|.
% Otherwise we need to include the |\end| and its argument in the
% material that we are adding to our environment body accumulator:
%    \begin{macrocode}
\long\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
    \eql@verbose@infoarg\eql@verbose@msg@leave\eql@scan@env
    \expandafter\eql@scan@testend
  \else
    \eql@scan@addto{#1\end{#2}}%
    \expandafter\eql@scan@iterate
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@scan@env@iterate@nopar}
% Version of |\eql@scan@env@iterate| which does not accept |\par|
% within the argument:
%    \begin{macrocode}
\def\eql@scan@env@iterate@nopar#1\end#2{\eql@scan@env@iterate#1\end{#2}}
%    \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}
\long\def\eql@scan@env@count#1\begin#2{%
  \ifx\end#2\else b\expandafter\eql@scan@env@count\fi
}
%    \end{macrocode}
%
% The call-back macro |\eql@scan@env@cancel| ignores the body
% as well as the end clause for the environment:
%    \begin{macrocode}
\def\eql@scan@env@cancel{%
  \@namedef{end\@currenvir}{\ignorespacesafterend}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Square Brackets.}
%
% The following is a version of the above mechanism
% that scans for an equation body enclosed by |\[|\,\ldots|\]|
% paying attention to potential further instances of the square bracket
% enclosures contained in the body.
%
%   \macro{\eql@scan@sqr}
% Start scanning for |\]|:
%    \begin{macrocode}
\def\eql@scan@sqr#1{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@scan@sqr
  \def\eql@scan@end{#1\]}%
  \eql@scan@reg@{}\def\eql@scan@stack{b}%
  \let\eql@scan@sqr@org\[%\]
  \ifdefined\eql@scan@par
    \let\[\eql@scan@sqr@iterate%\]
  \else
    \let\[\eql@scan@sqr@iterate@nopar%\]
  \fi
  \[%\]
}
%    \end{macrocode}
%
%   \macro{\eql@scan@sqr@iterate}
% Iterate until we find a balanced pairing of square brackets.
% Then call the call-back macro:
%    \begin{macrocode}
\long\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}%
    \eql@verbose@infoarg\eql@verbose@msg@leave\eql@scan@sqr
    \expandafter\eql@scan@testend
  \else
    \eql@scan@addto{#1\]}%
    \expandafter\[%\]
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@scan@sqr@iterate@nopar}
% Version of |\eql@scan@sqr@iterate| which does not accept |\par|
% within the argument:
%    \begin{macrocode}
\def\eql@scan@sqr@iterate@nopar#1\]{\eql@scan@sqr@iterate#1\]}
%    \end{macrocode}
%
%   \macro{\eql@scan@sqr@count}
% Push a `|b|' for every encountered instance of `|\[|':
%    \begin{macrocode}
\long\def\eql@scan@sqr@count#1\[#2{%\]
  \ifx\]#2\else b\expandafter\eql@scan@sqr@count\fi
}
%    \end{macrocode}
%
%   \macro{\eql@scan@sqrang@cancel}
% The call-back macro |\eql@scan@sqrang@cancel| ignores the body
% and the closing bracket:
%    \begin{macrocode}
\def\eql@scan@sqrang@cancel{\expandafter\ignorespaces\@gobble}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Angle Brackets.}
%
% The following is another version of the mechanism
% which scans for an equation body enclosed by |\<|\,\ldots|\>|.
%
%   \macro{\eql@scan@ang}
% Start scanning for |\>|:
%    \begin{macrocode}
\def\eql@scan@ang#1{%
  \eql@verbose@infoarg\eql@verbose@msg@enter\eql@scan@ang
  \def\eql@scan@end{#1\>}%
  \eql@scan@reg@{}\def\eql@scan@stack{b}%
  \let\eql@scan@ang@org\<%\>
  \ifdefined\eql@scan@par
    \let\<\eql@scan@ang@iterate%\>
  \else
    \let\<\eql@scan@ang@iterate@nopar%\>
  \fi
  \<%\>
}
%    \end{macrocode}
%
%   \macro{\eql@scan@ang@iterate}
% Iterate until we find a balanced pairing of angle brackets:
%    \begin{macrocode}
\long\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}%
    \eql@verbose@infoarg\eql@verbose@msg@leave\eql@scan@ang
    \expandafter\eql@scan@testend
  \else
    \eql@scan@addto{#1\>}%
    \expandafter\<%\>
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@scan@ang@iterate@nopar}
% Version of |\eql@scan@ang@iterate| which does not accept |\par|
% within the argument:
%    \begin{macrocode}
\def\eql@scan@ang@iterate@nopar#1\>{\eql@scan@ang@iterate#1\>}
%    \end{macrocode}
%
%   \macro{\eql@scan@ang@count}
% Push a `|b|' for every encountered instance of `|\<|':
%    \begin{macrocode}
\long\def\eql@scan@ang@count#1\<#2{%\>
  \ifx\>#2\else b\expandafter\eql@scan@ang@count\fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Options Processing}
%
%   \macro{\eql@equations@testall}
% The macro sequence started by |\eql@equations@testall|
% scans for optional arguments to the equation environments
% and appends them to the argument list using |\eqnaddopt|.
% All arguments are scanned such that any spaces
% stop the scanning and such that any alignment markers `|&|'
% cannot interfere:
% \TODO update
%    \begin{macrocode}
\def\eql@equations@testall{\eql@parseopt@main\eql@equations@parse}
\def\eql@equations@parse{%
  \ifx\eql@parseopt@token*%
    \let\eql@parseopt@next\eql@parseopt@nonumber
  \fi
  \ifx\eql@parseopt@token!%
    \let\eql@parseopt@next\eql@parseopt@donumber
  \fi
  \ifx\eql@parseopt@token/%
    \let\eql@parseopt@next\eql@parseopt@transpose
  \fi
  \ifx\eql@parseopt@token[%]
    \let\eql@parseopt@next\eql@parseopt@opt
  \fi
  \ifx\eql@parseopt@token\eql@atxi
    \let\eql@parseopt@next\eql@parseopt@label
  \fi
  \ifx\eql@parseopt@token\eql@atxii
    \let\eql@parseopt@next\eql@parseopt@label
  \fi
  \ifx\eql@parseopt@token.%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token,%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token~%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token`%
    \let\eql@parseopt@next\eql@parseopt@punctopt
  \fi
  \ifx\eql@parseopt@token-%
    \let\eql@parseopt@next\eql@parseopt@single
  \fi
  \ifx\eql@parseopt@token=%
    \let\eql@parseopt@next\eql@parseopt@lines
  \fi
  \ifx\eql@parseopt@token|%
    \let\eql@parseopt@next\eql@parseopt@columns
  \fi
  \ifx\eql@parseopt@token<%
    \let\eql@parseopt@next\eql@parseopt@ampeq
  \fi
  \ifx\eql@parseopt@token>%
    \let\eql@parseopt@next\eql@parseopt@eqamp
  \fi
  \ifx\eql@parseopt@token\label
    \let\eql@parseopt@next\eql@parseopt@end
  \fi
  \ifx\eql@parseopt@token\begin
    \let\eql@parseopt@next\eql@parseopt@end
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@end@testall}
% \TODO describe
%    \begin{macrocode}
\def\eql@end@testall{\eql@parseopt@main\eql@end@parse}
\def\eql@end@parse{%
  \ifx\eql@parseopt@token.%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token,%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token~%
    \let\eql@parseopt@next\eql@parseopt@punctpass
  \fi
  \ifx\eql@parseopt@token`%
    \let\eql@parseopt@next\eql@parseopt@punctblock
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@equations@processopt}
% The macro |\eql@equations@processopt| processes the options
% recevied by |\eqnaddopt|.
% First, clear several non-persistent registers
% (labels, tags, direct vertical spacing).
% Then process the arguments.
% Finally evaluate |\eql@indent@val| and |\eql@tagsepmin@val|
% and prevent main punctuation from being passed to nested environments:
%    \begin{macrocode}
\def\eql@equations@processopt{%
  \let\eql@tags@container@block\eql@tags@container@clear
  \let\eql@tags@frame@cmd\@firstofone
  \let\eql@skip@force@above\@undefined
  \let\eql@skip@force@below\@undefined
  \let\eql@skip@force@leave\@undefined
  \let\eql@display@linewidth\@undefined
  \let\eql@display@marginleft\@undefined
  \let\eql@display@marginright\@undefined
  \eql@abovespace@\z@skip
  \eql@belowspace@\z@skip
  \eql@displaybreak@prepen@\@MM
  \eql@displaybreak@postpen@\@MM
  \eql@nextopt@process{equations}%
  \let\eql@punct@block\eql@punct@main
  \let\eql@punct@main\@undefined
  \eql@indent@\glueexpr\eql@indent@val\relax
  \eql@tagsepmin@\glueexpr\eql@tagsepmin@val\relax
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Single-Line Main}
%
% In the following, we define the main routine
% for the single-line equation mode.
%
%   \macro{\eql@single@cr@error}
% Cannot use line breaks, produce an error message:
%    \begin{macrocode}
\def\eql@single@cr@error{%
  \eql@error{Cannot use '\string\\' within display equation.
    Please switch to equations environment}%
}
%    \end{macrocode}
%
%   \macro{\eql@single@start}
% Opening code for single-line equation.
% Capture current vertical mode, trigger PDF tagging,
% enter display math mode, initialise numbering scheme,
% backup current state of global registers,
% set native vs.\ manual equation tag mode,
% install error message for using |\\|.
% Hand over to mode-specific opening:
%    \begin{macrocode}
\def\eql@single@start{%
  \eql@display@enter
  \eql@tagging@start
  \eql@dollardollar@begin
  \eql@display@adjust
  \eql@numbering@init
  \eql@stack@save@equations
  \eql@numbering@single@init
  \eql@punct@term@set
  \ifdefined\eql@single@cr@mode
    \let\\\eql@single@cr@mode
  \fi
  \ifdefined\eql@single@native
    \let\eql@single@start@sel\eql@single@start@native
    \let\eql@single@end@sel\eql@single@end@native
  \else
    \let\eql@single@start@sel\eql@single@start@print
    \let\eql@single@end@sel\eql@single@end@print
  \fi
  \eql@single@start@sel
}
%    \end{macrocode}
%
%   \macro{\eql@single@end}
% Closing code for single-line equation.
% Apply punctuation for the block, perform mode-specific ending,
% restore global variables, end display math, indicate end to PDF tagging,
% return to vertical mode if desired:
%    \begin{macrocode}
\def\eql@single@end{%
  \eql@punct@apply@block
  \eql@hook@eqout
  \eql@single@end@sel
  \eql@stack@restore
  \eql@dollardollar@end
  \eql@tagging@end
  \eql@display@leave
}
%    \end{macrocode}
%
%   \macro{\eql@single@main}
% Combined opening, body and closing for pre-scanned body:
% \TODO is |\expandafter| needed? relic?
%    \begin{macrocode}
\def\eql@single@main{%
  \expandafter\eql@single@start
  \eql@scan@body
  \eql@single@end
}
%    \end{macrocode}
%
%   \macro{\eql@mode@single}
% Configure equations macros to single-line mode:
%    \begin{macrocode}
\def\eql@mode@single{%
  \ifdefined\eql@single@doscan
    \let\eql@equations@main\eql@single@main
    \let\eql@equations@end\@empty
  \else
    \let\eql@equations@main\@undefined
    \let\eql@equations@end\eql@single@end
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Multi-Line Main}
%
%   \ebool{\eql@multi@mode@lines}
% Switch register for lines vs.\ columns mode:
%    \begin{macrocode}
\let\eql@multi@mode@lines\eql@false
%    \end{macrocode}
%
%   \macro{\eql@multi@main}
% Main routine for multi-line modes.
% Capture current vertical mode, trigger PDF tagging,
% enter display math mode, initialise numbering scheme,
% backup current state of global registers,
% initialise macros for use within equations:
% \TODO shove depends on lines vs columns
%    \begin{macrocode}
\def\eql@multi@main{%
  \eql@display@enter
  \eql@tagging@start
  \eql@dollardollar@begin
  \eql@display@adjust
  \eql@numbering@init
  \eql@stack@save@equations
  \ifdefined\eql@transpose@active
    \ifdefined\eql@multi@mode@lines\else
      \eql@transpose
    \fi
  \fi
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@init
  \fi
  \eql@display@init
  \let\intertext\eql@intertext
  \let\endintertext\endeql@intertext
  \eql@shape@align@enable
%    \end{macrocode}
% Now measure the given multi-line equations body:
%    \begin{macrocode}
  \ifdefined\eql@multi@mode@lines
    \eql@lines@measure
  \else
    \ifdefined\eql@ampproof@active
      \eql@ampproof
    \fi
    \eql@columns@measure
  \fi
%    \end{macrocode}
% If only a single equation number is used for subequation numbering,
% revert to normal equation numbering.
% If only a single column is used in columns mode,
% may fallback to lines mode.
% Switching from columns to lines mode, the width can be incorrect,
% expect only minor discrpancies,
% but for accurateness, should call |\eql@lines@measure|:
%    \begin{macrocode}
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@test
  \fi
  \ifdefined\eql@multi@mode@lines\else
    \ifdefined\eql@multi@linesfallback
      \ifnum\eql@totalcolumns@=\@ne
        \let\eql@multi@mode@lines\eql@true
        \ifx\eql@multi@linesfallback\z@\else
          \eql@lines@measure
        \fi
      \fi
    \fi
  \fi
%    \end{macrocode}
% Adjust the multi-line equations body:
%    \begin{macrocode}
  \ifdefined\eql@multi@mode@lines
    \eql@lines@adjust
  \else
    \eql@columns@adjust
  \fi
%    \end{macrocode}
% Now print the multi-line equations body:
%    \begin{macrocode}
  \eql@display@print
  \eql@numbering@print@init
  \ifdefined\eql@multi@mode@lines
    \eql@lines@print
  \else
    \eql@columns@print
  \fi
  \eql@display@close
%    \end{macrocode}
% Close numbering, restore global variables,
% end display math, indicate end to PDF tagging,
% return to vertical mode if desired:
%    \begin{macrocode}
  \ifdefined\eql@numbering@subeq@use
    \eql@numbering@subeq@close
  \fi
  \eql@stack@restore
  \eql@dollardollar@end
  \eql@tagging@end
  \eql@display@leave
}
%    \end{macrocode}
%
%   \macro{\eql@mode@columns}
%   \macro{\eql@mode@lines}
% Configure equations macros to one of the two multi-line modes:
%    \begin{macrocode}
\def\eql@mode@columns{%
  \let\eql@equations@main\eql@multi@main
  \let\eql@equations@end\@empty
  \let\eql@multi@mode@lines\eql@false
}
\def\eql@mode@lines{%
  \let\eql@equations@main\eql@multi@main
  \let\eql@equations@end\@empty
  \let\eql@multi@mode@lines\eql@true
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Equations Environment}
%
% We now declare the main environment and its symbolic versions.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Environment.}
%
%   \environment{equations}
% Declare the main equations environment.
% If already in math mode, fail and cancel the environment body.
% Otherwise scan for optional arguments
% and pass on to |\eql@equations@start|:
%    \begin{macrocode}
\newenvironment{equations}{%
  \eql@verbose@info\eql@verbose@msg@enterenv
  \ifmmode
    \eql@error@mathmode{\string\begin{\@currenvir}}%
    \expandafter\eql@scan@env\expandafter\eql@scan@env@cancel
  \else
    \expandafter\eql@ampprotect\expandafter\eql@equations@testall
      \expandafter\eql@equations@start
  \fi
}{%
  \eql@equations@end
  \ignorespacesafterend
  \eql@verbose@info\eql@verbose@msg@leaveenv
}
\eql@markline@amsthm@register{equations}
\eql@tagging@register@luamml{equations}
%    \end{macrocode}
%
%   \macro{\eql@equations@start}
% The macro |\eql@equations@start| first processes the arguments.
% Depending on the chosen mode of operation,
% scan the environment body passing on to |\eql@equations@main|
% or process a single-line equation via |\eql@single@start|:
%    \begin{macrocode}
\def\eql@equations@start{%
  \eql@equations@processopt
  \ifdefined\eql@equations@main
    \expandafter\eql@scan@env\expandafter\eql@equations@main
  \else
    \expandafter\eql@single@start
  \fi
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Square Brackets.}
%
%   \environment{equations@sqr}
% Define a pseudo-environment |equations@sqr|
% such that |\@currenvir| may point to it when needed:
%    \begin{macrocode}
\newenvironment{equations@sqr}{}{}
\eql@markline@amsthm@register{equations@sqr}
\eql@tagging@register@luamml{equations@sqr}
%    \end{macrocode}
%
%   \macro{\eql@equations@sqr@open}
% Definition for `|\[|'.
% If already in math mode, ignore the enclosed contents.
% Otherwise add the default arguments |\eql@equations@sqr@opt|,
% enter the pseudo-environment, scan for optional arguments,
% and pass on to |\eql@equations@sqr@start|:
%    \begin{macrocode}
\protected\def\eql@equations@sqr@open{%
  \ifmmode
    \eql@error@mathmode{\string\[...\string\]}%
    \expandafter\eql@scan@sqr\expandafter\eql@scan@sqrang@cancel
  \else
    \expandafter\eqnaddopt\expandafter{\eql@equations@sqr@opt}%
    \begin{equations@sqr}%
    \eql@verbose@info\eql@verbose@msg@enterenv
    \let\]\eql@equations@sqr@close
    \expandafter\eql@ampprotect\expandafter\eql@equations@testall
      \expandafter\eql@equations@sqr@start
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@equations@sqr@start}
% Process arguments. Depending on mode of operation,
% scan and process enclosed contents via |\eql@equations@main|
% or pass on to |\eql@single@start|:
%    \begin{macrocode}
\def\eql@equations@sqr@start{%
  \eql@equations@processopt
  \ifdefined\eql@equations@main
    \expandafter\eql@scan@sqr\expandafter\eql@equations@main
  \else
    \expandafter\eql@single@start
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@equations@sqr@close}
% Definition for `|\]|'.
% Parse modifiers following `|\]|'
% and hand on to |\eql@equations@sqr@end|:
%    \begin{macrocode}
\protected\def\eql@equations@sqr@close{%
  \eql@ampprotect\eql@end@testall\eql@equations@sqr@end}
%    \end{macrocode}
%
%   \macro{\eql@equations@sqr@end}
% \TODO complete
% End |\[|\,\ldots|\]| block:
%    \begin{macrocode}
\def\eql@equations@sqr@end{%
  \eql@equations@end
  \eql@verbose@info\eql@verbose@msg@leaveenv
  \end{equations@sqr}%
  \ignorespaces
}
%    \end{macrocode}
%
% \TODO describe
%   \macro{\eql@sqr@open}
%   \macro{\eql@sqr@close}
%    \begin{macrocode}
\let\eql@sqr@open\eql@equations@sqr@open
\protected\def\eql@sqr@close{%
  \eql@error{'\string\]' may only close '\string\['}%\]
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Angle Brackets.}
%
%   \environment{equations@ang}
% Define a pseudo-environment |equations@ang|:
%    \begin{macrocode}
\newenvironment{equations@ang}{}{}
\newenvironment{equationsbox@ang}{}{}
\eql@markline@amsthm@register{equations@ang}
\eql@tagging@register@luamml{equations@ang}
%    \end{macrocode}
%
%   \macro{\eql@ang@open}
% Definition for `|\<|'.
% Forward to |equationsbox| if in math mode, otherwise to |equations|:
%    \begin{macrocode}
\protected\def\eql@ang@open{%
  \ifmmode
    \expandafter\eqnaddopt\expandafter{\eql@box@ang@opt}%
    \begin{equationsbox@ang}%
    \eql@verbose@info\eql@verbose@msg@enterenv
    \let\>\eql@box@ang@close
    \expandafter\eql@ampprotect\expandafter\eql@box@testall
      \expandafter\eql@box@start
  \else
    \expandafter\eqnaddopt\expandafter{\eql@equations@ang@opt}%
    \begin{equations@ang}%
    \eql@verbose@info\eql@verbose@msg@enterenv
    \let\>\eql@equations@ang@close
    \expandafter\eql@ampprotect\expandafter\eql@equations@testall
      \expandafter\eql@equations@ang@start
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@ang@close}
% Definition for `|\>|':
% \TODO NOTE: |\protected| acts as |\relax| and starts a row in |\halign|,
% so we overwrite |\>| when starting.
%    \begin{macrocode}
\protected\def\eql@ang@close{%
  \eql@error{'\string\>' may only close '\string\<'}%\>
}
%    \end{macrocode}
%
%   \macro{\eql@equations@ang@start}
% Process arguments and start handling the equation:
%    \begin{macrocode}
\def\eql@equations@ang@start{%
  \eql@equations@processopt
  \ifdefined\eql@equations@main
    \expandafter\eql@scan@ang\expandafter\eql@equations@main
  \else
    \expandafter\eql@single@start
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@equations@ang@close}
% \TODO describe
%    \begin{macrocode}
\def\eql@equations@ang@close{%
  \eql@ampprotect\eql@end@testall\eql@equations@ang@end}
%    \end{macrocode}
%
%   \macro{\eql@equations@ang@end}
% \TODO describe
%    \begin{macrocode}
\def\eql@equations@ang@end{%
  \eql@equations@end
  \eql@verbose@info\eql@verbose@msg@leaveenv
  \end{equations@ang}%
  \ignorespaces
}
%    \end{macrocode}
%
%   \macro{\eql@box@ang@close}
% \TODO describe
%    \begin{macrocode}
\def\eql@box@ang@close{%
  \eql@ampprotect\eql@end@testall\eql@box@ang@end}
%    \end{macrocode}
%
%   \macro{\eql@box@ang@end}
% \TODO describe
%    \begin{macrocode}
\def\eql@box@ang@end{%
  \eql@box@end
  \eql@verbose@info\eql@verbose@msg@leaveenv
  \end{equationsbox@ang}%
  \ignorespaces
}
%    \end{macrocode}
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Options}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Selection Tools}
%
%   \macro{\eql@decide@abovebelow}
% Select between values `|above|' or `|below|' or both:
% execute the corresponding code provided in the latter two arguments:
%    \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}
%
%   \macro{\eql@decide@situation}
% Select a particular vertical spacing situation and store it in
% the macro |#4|:
%    \begin{macrocode}
\def\eql@decide@situation#1#2#3#4{%
  \eql@decide@select{#1}{#2}{#3}{%
    {{long}{\def#4{0}}},%
    {{short}{\def#4{1}}},%
    {{cont}{\def#4{2}}},%
    {{par}{\def#4{3}}},%
    {{top}{\def#4{4}}},%
    {{noskip}{\def#4{5}}},%
    {{medskip}{\def#4{6}}}}}
%    \end{macrocode}
%
%   \macro{\eql@decide@delim}
% \TODO describe
%    \begin{macrocode}
\def\eql@decide@delim#1#2#3{%
  \eql@decide@select{#1}{#2}{#3}{%
    {{,.,\eql@decide@false}{\eql@box@wrap{}{}}},%
    {{\eql@decide@true,r,round}{\eql@box@delim()}},%
    {{s,sqr,square}{\eql@box@delim[]}},%
    {{c,curly,braces}{\eql@box@delim\lbrace\rbrace}},%
    {{a,ang,angle}{\eql@box@delim\langle\rangle}},%
    {{v,vert}{\eql@box@delim\vert\vert}},%
    {{d,dvert}{\eql@box@delim\Vert\Vert}},%
    {\relax{\eql@box@delim#3}}}}%
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Options Declarations}
%
% We now declare all key-value pairs for options sorted by their category.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Modes for Equations Box Environment.}
%
% Declare horizontal and vertical alignment modes
% for the boxed equations environment.
% Also declare spacing of columns:
%    \begin{macrocode}
\eql@define@key{equationsbox}{gathered,gather,ga,lines,ln}[]{%
  \eql@mode@stacked}
\eql@define@key{equationsbox}{aligned,align,al,columns,col}[]{%
  \eql@mode@aligned}
\eql@define@key{equationsbox}{cases}[]{%
  \eql@mode@cases\eql@box@ldelim\lbrace%
  \def\eql@box@colsep{\eql@box@condsep}}
\eql@define@key{equationsbox}{matrix}[r]{%
  \eql@mode@stacked\eql@shape@set{center}%
  \let\eql@spread@reset\eql@true\def\eql@spread@val{\z@}%
  \def\eql@box@colsep{\eql@box@shortsep}%
  \let\eql@mathstyle\@empty\eql@punct@clear
  \eql@decide@delim{#3}{#2}{#1}}
\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}{intro}{%
  \def\eql@box@cases@condintro{#1}}
\eql@define@key{equationsbox}{introtext}{%
  \def\eql@box@cases@condintro{%
    \ifmmode\expandafter\hbox\else\expandafter\@firstofone\fi{#1 }}}
\eql@define@key{equationsbox}{textcond}[true]{%
  \eql@decide@select{#3}{#2}{#1}{%`
    {{\eql@decide@true,text}{\let\eql@box@cases@condtext\eql@true}},%
    {{\eql@decide@false,math}{\let\eql@box@cases@condtext\eql@false}}}}
\eql@define@key{setup}{boxangopt}[]{%
  \def\eql@box@ang@opt{columns,#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Modes for Equations Environment.}
%
% Declare modes and switches for the equations environment:
%    \begin{macrocode}
\eql@define@key{equations}{equation,eq,single,1}[]{\eql@mode@single}
\eql@define@key{equations}{gathered,gather,ga,lines,ln}[]{%
  \eql@mode@lines}
\eql@define@key{equations}{aligned,align,al,columns,col}[]{%
  \eql@mode@columns}
\eql@define@key{equations,setup}{transpose}[true]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@transpose@active\eql@false}},%
    {{noamp,plain,restricted}{\let\eql@transpose@active\eql@true}},%
    {{\eql@decide@true,amp,cont}{\let\eql@transpose@active=+}}}}
\eql@define@key{equations}{native}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@single@native%
  \ifdefined\eql@single@native\let\eql@layoutleft\eql@false\fi}
\eql@define@key{setup}{native}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@single@native}
\eql@define@key{setup}{scanequation}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@single@doscan}
\eql@define@key{setup}{sqropt}[]{%
  \def\eql@equations@sqr@opt{equation,#1}}
\eql@define@key{setup}{angopt}[]{%
  \def\eql@equations@ang@opt{columns,#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Vertical Spacing.}
%
% Settings concerning the spacing of lines:
% \TODO set at end of env only!
%    \begin{macrocode}
\def\eql@keycat{equations,equationsbox,setup}
\eql@define@key\eql@keycat{spread}{%
  \let\eql@spread@reset\eql@false\def\eql@spread@val{#1}}
\eql@define@key\eql@keycat{spread*}[0pt]{%
  \let\eql@spread@reset\eql@true\def\eql@spread@val{#1}}
\eql@define@key\eql@keycat{strut}[true]{\eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@strut@cell\relax\let\eql@strut@tag\relax}},%
    {{cell}{\let\eql@strut@cell\eql@strut\let\eql@strut@tag\relax}},%
    {{tag}{\let\eql@strut@cell\relax\let\eql@strut@tag\eql@strut}},%
    {\eql@decide@true
      {\let\eql@strut@cell\eql@strut\let\eql@strut@tag\eql@strut}}}}
\eql@define@key{setup}{strutdepth}{\def\eql@strut@depth{#1}}
%    \end{macrocode}
%
% Settings to specify the apparent height and depth of equations:
%    \begin{macrocode}
\eql@define@key\eql@keycat{displayheight}[strut]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@display@height\@undefined}},%
    {{strut}{\def\eql@display@height{\ht\eql@strutbox@}}},%
    {\relax{\def\eql@display@height{#1}}}}}
\eql@define@key\eql@keycat{displaydepth}[strut]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@display@depth\@undefined}},%
    {{strut}{\def\eql@display@depth{\dp\eql@strutbox@}}},%
    {\relax{\def\eql@display@depth{#1}}}}}
%    \end{macrocode}
%
% Settings concerning page breaks:
%    \begin{macrocode}
\eql@define@key{equations}{prebreak}[4]{\eql@decide@select{#3}{#2}{#1}{%
    {{force,4,\eql@decide@true}{\eql@displaybreak@pre4}},%
    {{high,3}{\eql@displaybreak@pre3}},%
    {{med,medium,2}{\eql@displaybreak@pre2}},%
    {{low,1}{\eql@displaybreak@pre1}},%
    {{0,\eql@decide@false}{\eql@displaybreak@pre0}},%
    {{default,inherit,-1}{\eql@displaybreak@pre\m@ne}}}}
\eql@define@key{equations}{postbreak}[4]{\eql@decide@select{#3}{#2}{#1}{%
    {{force,4,\eql@decide@true}{\eql@displaybreak@post4}},%
    {{high,3}{\eql@displaybreak@post3}},%
    {{med,medium,2}{\eql@displaybreak@post2}},%
    {{low,1}{\eql@displaybreak@post1}},%
    {{0,\eql@decide@false}{\eql@displaybreak@post0}},%
    {{default,inherit,-1}{\eql@displaybreak@post\m@ne}}}}
\eql@define@key{equations,setup}{allowbreaks,allowdisplaybreaks}[4]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{full,4}{\eql@displaybreak@inter4}},%
    {{high,3}{\eql@displaybreak@inter3}},%
    {{med,medium,2}{\eql@displaybreak@inter2}},%
    {{low,1}{\eql@displaybreak@inter1}},%
    {{0,\eql@decide@false}{\eql@displaybreak@inter\z@}}}}
\eql@define@key{equations}{prepenalty}{%
  \eql@displaybreak@prepen@\numexpr#1\relax}
\eql@define@key{equations}{postpenalty}{%
  \eql@displaybreak@postpen@\numexpr#1\relax}
\eql@define@key{equations,setup}{interpenalty}{%
  \interdisplaylinepenalty\numexpr#1\relax}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{control}{vspace}[]{\eql@vspace@add{#1}}
\eql@define@key{control}{vspace*}[]{\eql@vspace@addfixedbefore{#1}}
\eql@define@key{control}{vspace!}[]{\eql@vspace@addfixedafter{#1}}
\eql@define@key{control}{break}[4]{\eql@displaybreak@level[{#1}]}
\eql@define@key{control}{penalty}[]{\eql@displaybreak@star{#1}}
%    \end{macrocode}
%
% Override vertical spacing situation:
% \TODO short should just apply to above?! or as far as short would apply...
%    \begin{macrocode}
\eql@define@key{equations}{noskip}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@above{5}}%
    {\def\eql@skip@force@below{5}}}
\eql@define@key{equations}{short}[above]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@above{1}}%
    {\def\eql@skip@force@below{1}}}
\eql@define@key{equations}{long}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@above{0}}%
    {\def\eql@skip@force@below{0}}}
\eql@define@key{equations}{medskip}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@above{6}}%
    {\def\eql@skip@force@below{6}}}
\eql@define@key{equations}{par}[par]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{default,\eql@decide@false}{\let\eql@skip@force@leave\@undefined}},%
    {{cont,hmode}{\let\eql@skip@force@leave\z@}},%
    {{par,vmode}{\let\eql@skip@force@leave\@ne
      \ifdefined\eql@skip@force@below\else
        \def\eql@skip@force@below{3}%
      \fi}},%
    {{top}{\let\eql@skip@force@leave\tw@
      \ifdefined\eql@skip@force@below\else
        \def\eql@skip@force@below{4}
      \fi}}}}
%    \end{macrocode}
%
% Specify vertical spacing explicitly:
%    \begin{macrocode}
\eql@define@key{equations}{skip}{%
  \def\eql@skip@force@above{7}%
  \def\eql@skip@custom@above{#1}%
  \let\eql@skip@force@below\eql@skip@force@above
  \let\eql@skip@custom@below\eql@skip@custom@above}
\eql@define@key{equations}{aboveskip}{%
  \def\eql@skip@force@above{7}%
  \def\eql@skip@custom@above{#1}}
\eql@define@key{equations}{belowskip}{%
  \def\eql@skip@force@below{7}%
  \def\eql@skip@custom@below{#1}}
\eql@define@key{equations}{abovespace}{%
  \advance\eql@abovespace@\glueexpr#1\relax}
\eql@define@key{equations}{belowspace}{%
  \advance\eql@belowspace@\glueexpr#1\relax}
%    \end{macrocode}
%
% Vertical spacing for |intertext|:
%    \begin{macrocode}
\eql@define@key{intertext}{skip}{%
  \def\eql@skip@force@above{7}%
  \def\eql@skip@custom@above{#1}%
  \let\eql@skip@force@below\eql@skip@force@above
  \let\eql@skip@custom@below\eql@skip@custom@above}
\eql@define@key{intertext}{aboveskip}{%
  \def\eql@skip@force@below{7}%
  \def\eql@skip@custom@below{#1}}
\eql@define@key{intertext}{belowskip}{%
  \def\eql@skip@force@above{7}%
  \def\eql@skip@custom@above{#1}}
\eql@define@key{intertext}{noskip}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@below{5}}%
    {\def\eql@skip@force@above{5}}}
\eql@define@key{intertext}{short}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@below{1}}%
    {\def\eql@skip@force@above{1}}}
\eql@define@key{intertext}{long}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@below{0}}%
    {\def\eql@skip@force@above{0}}}
\eql@define@key{intertext}{medskip}[both]{%
  \eql@decide@abovebelow{#3}{#2}{#1}%
    {\def\eql@skip@force@below{6}}%
    {\def\eql@skip@force@above{6}}}
%    \end{macrocode}
%
% Configure general vertical spacing behaviour for various situations:
%    \begin{macrocode}
\eql@define@key{setup}{skip,longskip}{%
  \abovedisplayskip\glueexpr#1\relax
  \belowdisplayskip\abovedisplayskip
  \def\eql@skip@long@above{#1}%
  \let\eql@skip@long@below\eql@skip@long@above}
\eql@define@key{setup}{aboveskip,abovelongskip}{%
  \abovedisplayskip\glueexpr#1\relax
  \def\eql@skip@long@above{#1}}
\eql@define@key{setup}{belowskip,belowlongskip}{%
  \belowdisplayskip\glueexpr#1\relax
  \def\eql@skip@long@below{#1}}
\eql@define@key{setup}{aboveshortskip}{%
  \abovedisplayshortskip\glueexpr#1\relax
  \def\eql@skip@short@above{#1}}
\eql@define@key{setup}{belowshortskip}{%
  \belowdisplayshortskip\glueexpr#1\relax
  \def\eql@skip@short@below{#1}}
\eql@define@key{setup}{tagskip}{%
  \def\eql@skip@tag@above{#1}%
  \let\eql@skip@tag@below\eql@skip@tag@above}
\eql@define@key{setup}{abovetagskip}{%
  \def\eql@skip@tag@above{#1}}
\eql@define@key{setup}{belowtagskip}{%
  \def\eql@skip@tag@below{#1}}
\eql@define@key{setup}{medskip}{%
  \def\eql@skip@med@above{#1}%
  \let\eql@skip@med@below\eql@skip@med@above}
\eql@define@key{setup}{abovemedskip}{%
  \def\eql@skip@med@above{#1}}
\eql@define@key{setup}{belowmedskip}{%
  \def\eql@skip@med@below{#1}}
\eql@define@key{setup}{abovetopskip}{%
  \def\eql@skip@top@above{#1}}
\eql@define@key{setup}{belowtopskip}{%
  \def\eql@skip@top@below{#1}}
\eql@define@key{setup}{aboveparskip}{%
  \def\eql@skip@par@above{#1}}
\eql@define@key{setup}{belowparskip}{%
  \def\eql@skip@par@below{#1}}
\eql@define@key{setup}{abovecontskip}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{hide}{\def\eql@skip@cont@above{\eql@spread@val-\eql@skip@long@below}}},%
    {\relax{\def\eql@skip@cont@above{#1}}}}}
\eql@define@key{setup}{belowcontskip}{%
  \def\eql@skip@cont@below{#1}}
\eql@define@key{setup}{shortmode}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{\eql@decide@false,never}{\def\eql@skip@mode@short{0}}},%
    {{above,neverbelow,belowoff}{\def\eql@skip@mode@short{1}}},%
    {{belowone,belowsingle}{\def\eql@skip@mode@short{2}}},%
    {{belowall,always,on}{\def\eql@skip@mode@short{3}}}}}
\eql@define@key{setup}{abovecontmode}{%
  \eql@decide@situation{#3}{#2}{#1}\eql@skip@mode@cont@above}
\eql@define@key{setup}{belowcontmode}{%
  \eql@decide@situation{#3}{#2}{#1}\eql@skip@mode@cont@below}
\eql@define@key{setup}{aboveparmode}{%
  \eql@decide@situation{#3}{#2}{#1}\eql@skip@mode@par@above}
\eql@define@key{setup}{belowparmode}{%
  \eql@decide@situation{#3}{#2}{#1}\eql@skip@mode@par@below}
\eql@define@key{setup}{abovetopmode}{%
  \eql@decide@situation{#3}{#2}{#1}\eql@skip@mode@top@above}
\eql@define@key{setup}{belowtopmode}{%
  \eql@decide@situation{#3}{#2}{#1}\eql@skip@mode@top@below}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Labels and Tag Declaration.}
%
% Specify label and tag for equations and subequations:
%    \begin{macrocode}
\def\eql@keycat{equations,subequations}
\eql@define@key\eql@keycat{label}{\eql@tags@addblock@label{#1}}
\eql@define@key\eql@keycat{labelname}{\eql@tags@addblock@name{#1}}
\eql@define@key\eql@keycat{tag}{\eql@tags@addblock@tag{#1}}
\eql@define@key\eql@keycat{tag*}{%
  \eql@tags@addblock@tagform@off\eql@tags@addblock@tag{#1}}
\eql@define@key\eql@keycat{taglabel}{\eql@tags@addblock@ref{#1}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{control}{label}{\eql@tags@add@label{#1}}
\eql@define@key{control}{labelname}{\eql@tags@add@name{#1}}
\eql@define@key{control}{tag}{\eql@tags@add@tag{#1}}
\eql@define@key{control}{tag*}{\eql@tags@add@tagform@off\eql@tags@add@tag{#1}}
\eql@define@key{control}{taglabel}{\eql@tags@add@ref{#1}}
\eql@define@key{control}{shifttag}{\eql@tags@add@raiseshift{#1}}
\eql@define@key{control}{smashtag}{\eql@tags@add@raisesmash{#1}}
\eql@define@key{control}{pushtag}[]{\eql@tags@add@forceraise}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{setup}{labelname}{\protected@edef\eql@tags@name@generic{#1}}
\eql@define@key{setup}{autolabel}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@tags@autolabel}
\eql@define@key{setup}{autotag}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@tags@autotag}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tag Spacing.}
%
% Configure horizontal spacing for equation tags:
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{tagmargin}[auto]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{auto,\eql@decide@false}{\let\eql@tagmargin@val\@undefined}},%
    {\relax{\def\eql@tagmargin@val{#1}}}}}
\eql@define@key\eql@keycat{tagmargin*}{%
  \settowidth\dimen@{#1}\edef\eql@tagmargin@val{\the\dimen@}}
\eql@define@key\eql@keycat{tagmarginratio}{%
  \eql@tagmargin@ratio@\dimexpr#1pt\relax}
\eql@define@key\eql@keycat{tagmarginthreshold}{%
  \def\eql@tagmargin@threshold{#1}}
\eql@define@key\eql@keycat{mintagsep}{\def\eql@tagsepmin@val{#1}}
\eql@define@key\eql@keycat{mintagwidth}{%
  \settowidth\dimen@{#1}\edef\eql@tagsepmin@val{\the\dimen@}}
\eql@define@key\eql@keycat{mintagwidth*}{\settowidth\eql@tagwidthmin@{#1}}
\eql@define@key\eql@keycat{tagsnap}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@tagpos@snap\z@}},%
    {\relax{\def\eql@tagpos@snap{#1}}}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tag Layout.}
%
% Configure methods to declare equation tag layout:
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{tagbox,taglayout}{%
  \eql@tags@taglayout@set{#1}}
\eql@define@key\eql@keycat{tagbox*,taglayout*}{%
  \eql@tags@taglayout@set@direct{#1}}
\eql@define@key\eql@keycat{tagform}{%
  \eql@tags@tagform@set#1}
\eql@define@key\eql@keycat{tagform*}{%
  \eql@tags@tagform@set@direct{#1}}
\eql@define@key\eql@keycat{subeqtemplate}{%
  \def\eql@subequations@template####1####2{#1}%
  \eql@append\eql@subequations@template{\theparentequation{equation}}}
%    \end{macrocode}
%
%    \begin{macrocode}
\eql@define@key{control}{tagbox,taglayout}{%
  \global\eql@append\eql@tags@container{\eql@tags@taglayout@set{#1}}}
\eql@define@key{control}{tagbox*,taglayout*}{%
  \global\eql@append\eql@tags@container{\eql@tags@taglayout@set@direct{#1}}}
\eql@define@key{control}{tagform}{%
  \global\eql@append\eql@tags@container{\eql@tags@tagform@set#1}}
\eql@define@key{control}{tagform*}[{####1}]{%
  \global\eql@append\eql@tags@container{\eql@tags@tagform@set@direct{#1}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Equation Numbering.}
%
% Configure equation numbering schemes:
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{numberline,number,num,numline,n}[all]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{\eql@decide@false,0,*}{\let\eql@numbering@active\eql@false}},%
    {{\eql@decide@true,!}{\let\eql@numbering@active\eql@true}},%
    {{none,n,-}{\let\eql@numbering@mode\eql@numbering@mode@multi
        \let\eql@numbering@active\eql@false}},%
    {{single,1}{\let\eql@numbering@mode\eql@numbering@mode@single
        \let\eql@numbering@active\eql@true}},%
    {{multi,@}{\let\eql@numbering@mode\eql@numbering@mode@multi
        \let\eql@numbering@active\eql@true}},%
    {\relax{\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{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}}}}
\eql@define@key\eql@keycat{evadetag,avoidtag}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@numbering@best@auto}
\eql@define@key\eql@keycat{tagbetween}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@tagpos@doconvert}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{control}{nonumber,nn,*}[]{\global\@eqnswfalse}
\eql@define@key{control}{donumber,dn,!}[]{\global\@eqnswtrue}
\eql@define@key{control}{numberhere}[]{\eql@numberhere}
\eql@define@key{control}{numbernext}[]{\eql@numbernext}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Horizontal Layout.}
%
% Configure horizontal alignment mode and margin for left alignment:
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{layout}{\eql@decide@select{#3}{#2}{#1}{%
  {{center,c}{\let\eql@layoutleft\eql@false}},%
  {{left,l}{\let\eql@layoutleft\eql@true}}}}
\eql@define@key\eql@keycat{center}[]{\let\eql@layoutleft\eql@false}
\eql@define@key\eql@keycat{flushleft,left}[]{\let\eql@layoutleft\eql@true}
\eql@define@key\eql@keycat{leftmargin}{\def\eql@layoutleftmargin{#1}}
\eql@define@key\eql@keycat{leftmargin*}{%
  \settowidth\dimen@{#1}\edef\eql@layoutleftmargin{\the\dimen@}}
\eql@define@key\eql@keycat{minleftmargin}{%
  \def\eql@layoutleftmarginmin{#1}}
\eql@define@key\eql@keycat{maxleftmargin}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\def\eql@layoutleftmarginmax{.5\maxdimen}}},%
    {\relax{\def\eql@layoutleftmarginmax{#1}}}}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\eql@keycat{equations,equationsbox}
\eql@define@key\eql@keycat{margin}{%
  \def\eql@display@marginleft{#1}\def\eql@display@marginright{#1}}
\eql@define@key\eql@keycat{marginleft}{\def\eql@display@marginleft{#1}}
\eql@define@key\eql@keycat{marginright}{\def\eql@display@marginright{#1}}
\eql@define@key{equations}{linewidth,width}{\def\eql@display@linewidth{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Horizontal Spacing and Columns.}
%
% Configure column spacing and compression threshold:
%    \begin{macrocode}
\def\eql@keycat{equations,setup}
\eql@define@key\eql@keycat{alignshrink}{\eql@decide@select{#3}{#2}{#1}{%
    {{max,full,4}{\eql@alignbadness@\inf@bad}},%
    {{high,3}{\eql@alignbadness@54\relax}},%
    {{med,medium,2}{\eql@alignbadness@18\relax}},%
    {{low,1}{\eql@alignbadness@6\relax}},%
    {{0,\eql@decide@false}{\eql@alignbadness@\z@}}}}
\eql@define@key\eql@keycat{tagshrink}{\eql@decide@select{#3}{#2}{#1}{%
    {{max,full,4}{\eql@tagbadness@\inf@bad}},%
    {{high,3}{\eql@tagbadness@54\relax}},%
    {{med,medium,2}{\eql@tagbadness@18\relax}},%
    {{low,1}{\eql@tagbadness@6\relax}},%
    {{0,\eql@decide@false}{\eql@tagbadness@\z@}}}}
\eql@define@key\eql@keycat{alignbadness}{\eql@alignbadness@\numexpr#1\relax}
\eql@define@key\eql@keycat{tagbadness}{\eql@tagbadness@\numexpr#1\relax}
\eql@define@key\eql@keycat{mincolsep}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@colsepmin@val{0pt}}},%
    {\relax{\def\eql@colsepmin@val{#1}}}}}
\eql@define@key\eql@keycat{maxcolsep}{\eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\def\eql@colsepmax@val{.5\maxdimen}}},%
    {\relax{\def\eql@colsepmax@val{#1}}}}}
\eql@define@key\eql@keycat{fulllength}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@columns@fulllength}
%    \end{macrocode}
%
% \TODO is boxcolsep vs breakcolsep okay??!
%    \begin{macrocode}
\eql@define@key\eql@keycat{linesep}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@break@line@sep{0pt}}},%
    {\relax{\def\eql@break@line@sep{#1}}}}}
\eql@define@key\eql@keycat{linesep*}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@break@line@shortsep{0pt}}},%
    {\relax{\def\eql@break@line@shortsep{#1}}}}}
\eql@define@key{equationsbox,setup}{colsep}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@box@colsep{0pt}}},%
    {{short}{\def\eql@box@colsep{\eql@box@shortsep}}},%
    {\relax{\def\eql@box@colsep{#1}}}}%
  \let\eql@break@col@sep\eql@box@colsep}
\eql@define@key{equations}{colsep}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@break@col@sep{0pt}}},%
    {\relax{\def\eql@break@col@sep{#1}}}}%
  \let\eql@colsepmin@val\eql@box@colsep
  \let\eql@colsepmax@val\eql@box@colsep
  \let\eql@box@colsep\eql@break@col@sep}
\eql@define@key\eql@keycat{colsep*}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@break@col@shortsep{0pt}}},%
    {\relax{\def\eql@break@col@shortsep{#1}}}}}
\eql@define@key{equationsbox,setup}{colsep*}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@box@shortsep{0pt}}},%
    {\relax{\def\eql@box@shortsep{#1}}}}}
\eql@define@key{equationsbox,setup}{condsep}{\eql@decide@select{#3}{#2}{#1}{%
    {{0,\eql@decide@false}{\def\eql@box@condsep{0pt}}},%
    {\relax{\def\eql@box@condsep{#1}}}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Horizontal Shape.}
%
% Configure horizontal alignment schemes:
%    \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}[indent]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{max}{\let\eql@paddingleft@val\@undefined}},%
    {{indent}{\def\eql@paddingleft@val{\eql@indent@val}}},%
    {{0,\eql@decide@false}{\def\eql@paddingleft@val{0pt}}},%
    {\relax{\def\eql@paddingleft@val{#1}}}}%
  \let\eql@paddingright@val\eql@paddingleft@val}
\eql@define@key\eql@keycat{padleft}[indent]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{max}{\let\eql@paddingleft@val\@undefined}},%
    {{indent}{\def\eql@paddingleft@val{\eql@indent@val}}},%
    {{0,\eql@decide@false}{\def\eql@paddingleft@val{0pt}}},%
    {\relax{\def\eql@paddingleft@val{#1}}}}}
\eql@define@key\eql@keycat{padright}[indent]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{max}{\let\eql@paddingright@val\@undefined}},%
    {{indent}{\def\eql@paddingright@val{\eql@indent@val}}},%
    {{0,\eql@decide@false}{\def\eql@paddingright@val{0pt}}},%
    {\relax{\def\eql@paddingright@val{#1}}}}}
\eql@define@key\eql@keycat{indent}[2em]{%
  \def\eql@indent@val{#1}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{control}{align}[]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{l,left}{\global\eql@append\eql@cell@container{\eql@shape@pos@\z@}}},%
    {{c,center}{\global\eql@append\eql@cell@container{\eql@shape@pos@\@ne}}},%
    {{r,right}{\global\eql@append\eql@cell@container{\eql@shape@pos@\tw@}}}}}
\eql@define@key{control}{shift,shiftto}[]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{*,indent}{\eql@shape@alignamount@set{\eql@indent@}}},%
    {{!,outdent}{\eql@shape@alignamount@set{-\eql@indent@}}},%
    {\relax{\eql@shape@alignamount@set{#1}}}}}
\eql@define@key{control}{shift*,shiftby}[]{\eql@shape@alignamount@add{#1}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Math Classes at Alignment.}
%
% Configure math classes at alignment marker:
%    \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{classlead,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{Math Styles.}
%
% Configure math classes at alignment marker:
%    \begin{macrocode}
\eql@define@key\eql@keycat{style}[display]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{text,\eql@decide@false}{\let\eql@mathstyle\@empty}},%
    {{display,\eql@decide@true}{\let\eql@mathstyle\displaystyle}}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Punctuation.}
%
% Configure punctuation defaults:
% \TODO describe
%    \begin{macrocode}
\def\eql@punct@all#1#2#3#4#5\eql@punct@end{%
  \def\eql@tmp{#4}\def\eql@tmpa{1}%
  \ifx\eql@tmp\eql@tmpa
    \ifnum#5=1111\relax
      \eql@punct@set\eql@punct@col{#1}%
      \eql@punct@set\eql@punct@line{#2}%
      \eql@punct@set\eql@punct@main{#3}%
    \else\ifnum#5=111\relax
      \eql@punct@set\eql@punct@line{#1}%
      \eql@punct@set\eql@punct@main{#2}%
    \else\ifnum#5=11\relax
      \eql@punct@set\eql@punct@main{#1}%
    \else
      \eql@punct@clear
    \fi\fi\fi
  \else
    \eql@error{Too many arguments to punctall}%
  \fi
}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@keycat{equations,equationsbox,setup}
\eql@define@key\eql@keycat{punctsep}[\,]{\def\eql@punct@sep{#1}}
\eql@define@key\eql@keycat{punct}[.]{\eql@punct@set\eql@punct@main{#1}}
\eql@define@key\eql@keycat{punct*}[]{\eql@punct@set\eql@punct@main\relax}
\eql@define@key\eql@keycat{punctline}[,]{\eql@punct@set\eql@punct@line{#1}}
\eql@define@key\eql@keycat{punctline*}[]{\eql@punct@set\eql@punct@line\relax}
\eql@define@key\eql@keycat{punctcol}[,]{\eql@punct@set\eql@punct@col{#1}}
\eql@define@key\eql@keycat{punctcol*}[]{\eql@punct@set\eql@punct@col\relax}
\eql@define@key\eql@keycat{punctall}[,,.]{\eql@punct@all#111111\eql@punct@end}
%    \end{macrocode}
%
%    \begin{macrocode}
\eql@define@key{control}{punctsep}[\,]{\def\eql@punct@sep{#1}}
\eql@define@key{control}{punct}[.]{\eql@punct@set\eql@punct@next{#1}}
\eql@define@key{control}{punct*}[]{\eql@punct@set\eql@punct@block\relax}
\eql@define@key{control}{punctapply}[]{\eqnpunctapply}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Frames.}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{equationsbox}{frame}[\fbox]{%
  \def\eql@box@frame{#1}%
  \ifx\eql@box@frame\@empty\let\eql@box@frame\@firstofone\fi}
\eql@define@key{equationsbox}{wrap}{\eql@box@wrap#1}
\eql@define@key{equationsbox}{delim}[r]{\eql@decide@delim{#3}{#2}{#1}}
\eql@define@key{equationsbox}{ldelim}{\eql@box@ldelim#1}
\eql@define@key{equationsbox}{rdelim}{\eql@box@rdelim#1}
\eql@define@key{equationsbox}{lbrace}[]{\eql@box@ldelim\lbrace}
\eql@define@key{equationsbox}{rbrace}[]{\eql@box@rdelim\rbrace}
\eql@define@key{equationsbox}{lrbrace,lrbraces}[]{\eql@box@delim\lbrace\rbrace}
\eql@define@key\eql@keycat{braces}[lr]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{\eql@decide@false}{\eql@box@wrap{}{}}},%
    {{l,left}{\eql@box@ldelim\lbrace}},%
    {{r,right}{\eql@box@rdelim\rbrace}},%
    {{\eql@decide@true,lr,both}{\eql@box@delim\lbrace\rbrace}}}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{control}{framecell}[\fbox]{%
  \global\eql@append\eql@cell@container{\def\eql@frame@cmd{#1}}}
\eql@define@key{control}{frametag}[\fbox]{%
  \global\eql@append\eql@tags@container{\def\eql@tags@frame@cmd{#1}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Alternative Content Description.}
%
% Alternative content description for accessibility or documentation purposes:
% \TODO implement in PDF tagging
%    \begin{macrocode}
\eql@define@key{equations,equationsbox}{alt}{}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Injections.}
%
%    \begin{macrocode}
\eql@define@key{control}{inject}{%
  \global\eql@append\eql@interline@container{%
    \eql@append\eql@display@injectbefore{#1}}}
\eql@define@key{control}{inject*}{%
  \global\eql@append\eql@interline@container{%
    \eql@append\eql@display@injectafter{#1}}}
\eql@define@key{control}{markline}[]{\eql@markline@inject{#1}}
\eql@define@key{control}{markline*}[]{\eql@markline@inject{push,#1}}
\eql@define@key{control}{qed}[]{\eql@markline@inject{qed,#1}}
\eql@define@key{control}{qed*}[]{\eql@markline@inject{qed,push,#1}}
%    \end{macrocode}
%
% \TODO describe
%    \begin{macrocode}
\eql@define@key{markline}{pos}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{below,push}{\let\eql@markline@pos\eql@markline@pos@below}},%
    {{baseline}{\let\eql@markline@pos\eql@markline@pos@baseline}},%
    {{bottom}{\let\eql@markline@pos\eql@markline@pos@bottom}}}}
\eql@define@key{markline}{below,push}[]{%
  \let\eql@markline@pos\eql@markline@pos@below}
\eql@define@key{markline}{baseline}[]{%
  \let\eql@markline@pos\eql@markline@pos@baseline}
\eql@define@key{markline}{bottom}[]{%
  \let\eql@markline@pos\eql@markline@pos@bottom}
\eql@define@key{markline}{shift}{\def\eql@markline@shift{#1}}
\eql@define@key{markline}{symbol}{\def\eql@markline@symbol{#1}}
\eql@define@key{markline}{qed}[]{\let\eql@markline@symbol\eql@markline@qed}
\eql@define@key{setup}{marksymbol}{\def\eql@markline@symbol{#1}}
\eql@define@key{setup}{qedsymbol}{\def\eql@markline@qed{#1}}
\eql@define@key{setup}{markpos}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{below}{\let\eql@markline@pos\eql@markline@pos@below}},%
    {{baseline}{\let\eql@markline@pos\eql@markline@pos@baseline}},%
    {{bottom}{\let\eql@markline@pos\eql@markline@pos@bottom}}}}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Global Switches.}
%
% Set global switches:
%    \begin{macrocode}
\let\eql@multi@linesfallback\eql@false
\let\eql@scan@par\eql@false
\let\eql@single@cr@mode\eql@false
\let\eql@ampproof@active\eql@false
\let\eql@parseopt@warn@main\eql@warn@parseopt
\let\eql@parseopt@warn@aux\@empty
%    \end{macrocode}
%
%    \begin{macrocode}
\eql@define@key{equations,setup}{linesfallback}[true]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@multi@linesfallback\eql@false}},%
    {{reuse,lean}{\let\eql@multi@linesfallback\z@}},%
    {{measure,full,\eql@decide@true}{\let\eql@multi@linesfallback\eql@true}}}}
\eql@define@key{setup}{ampproof}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@ampproof@active}
\eql@define@key{equations,setup}{equationcr}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@single@cr@mode\eql@false}},%
    {{\eql@decide@true,break}{\let\eql@single@cr@mode\eql@break@line}},%
    {{error,verbose}{\let\eql@single@cr@mode\eql@single@cr@error}}}}
\eql@define@key{setup}{modifierwarning}[true]{%
  \eql@decide@select{#3}{#2}{#1}{%
    {\eql@decide@false{\let\eql@parseopt@warn@main\@empty
      \let\eql@parseopt@warn@aux\@empty}},%
    {{-}{\let\eql@parseopt@warn@main\eql@warn@parseopt
      \let\eql@parseopt@warn@aux\@empty}},%
    {\eql@decide@true{\let\eql@parseopt@warn@main\eql@warn@parseopt
      \let\eql@parseopt@warn@aux\eql@warn@parseopt}},%
    {{verbose,+}{\let\eql@parseopt@warn@main\eql@warn@parseopt@verbose
      \let\eql@parseopt@warn@aux\eql@warn@parseopt@verbose}}}}
\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}}
\eql@define@key{equations,equationsbox,setup}{scanpar}[true]{%
  \eql@decide@bool{#3}{#2}{#1}\eql@scan@par}
\eql@define@key{setup}{defaults}{%
  \eql@decide@select{#3}{#2}{#1}{%
    {{classic}{\eql@defaults@classic}},%
    {{eqnlines}{\eql@defaults@eqnlines}}}}
\eql@define@key{equations,equationsbox,setup}{verbose}[true]{%
  \eql@decide@if{#3}{#2}{#1}\eql@verbose@on\eql@verbose@off}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Package Options.}
%
% Declare choices available at loading of package only:
% \TODO adjust
%    \begin{macrocode}
\let\eql@provide@opt@env\tw@
\let\eql@provide@opt@amsmathpatch\eql@false
\let\eql@provide@opt@backup\eql@false
\let\eql@provide@opt@ang\eql@true
\let\eql@provide@opt@eqref\eql@true
\let\eql@provide@opt@matrix\eql@true
%    \end{macrocode}
%
%    \begin{macrocode}
\eql@define@key{setup}{amsmathends,amsmathpatch}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@opt@amsmathpatch}
\eql@define@key{setup}{backup}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@opt@backup}
\eql@define@key{setup}{env}[equation]{%
  \eql@error@packageoption{#2}%
  \eql@decide@select{#3}{#2}{#1}{%
    {{none,\eql@decide@false}{\let\eql@provide@opt@env\z@}},%
    {{equation,latex}{\let\eql@provide@opt@env\@ne}},%
    {{amsmath,all,\eql@decide@true}{\let\eql@provide@opt@env\tw@}}}}
\eql@define@key{setup}{ang}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@opt@ang}
\eql@define@key{setup}{eqref}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@opt@eqref}
\eql@define@key{setup}{matrix}[true]{%
  \eql@error@packageoption{#2}%
  \eql@decide@bool{#3}{#2}{#1}\eql@provide@opt@matrix}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Shortcut Options.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@parseopt@nonumber#1{\eqnaddopt{nonumber}\eql@parseopt@peek}
\def\eql@parseopt@donumber#1{\eqnaddopt{donumber}\eql@parseopt@peek}
\def\eql@parseopt@single#1{\eqnaddopt{single}\eql@parseopt@peek}
\def\eql@parseopt@lines#1{\eqnaddopt{lines}\eql@parseopt@peek}
\def\eql@parseopt@eqamp#1{\eqnaddopt{eqamp}\eql@parseopt@peek}
\def\eql@parseopt@ampeq#1{\eqnaddopt{ampeq}\eql@parseopt@peek}
\def\eql@parseopt@columns#1{\eqnaddopt{columns}\eql@parseopt@peek}
\def\eql@parseopt@transpose#1{\eqnaddopt{columns,transpose}\eql@parseopt@peek}
\def\eql@parseopt@opt[#1]{\eqnaddopt{#1}\eql@parseopt@peek}
\def\eql@parseopt@label#1#2{\eqnaddopt{label={#2}}\eql@parseopt@peek}
\def\eql@parseopt@punctpass{\eql@parseopt@peek`}
\def\eql@parseopt@punctopt#1#2{\eqnaddopt{punctall={#2}}\eql@parseopt@peek}
\def\eql@parseopt@punctnext#1#2{%
  \eql@punct@set\eql@punct@next{#2}\eql@parseopt@peek}
\def\eql@parseopt@punctblock#1#2{%
  \eql@punct@set\eql@punct@block{#2}\eql@parseopt@peek}
\def\eql@parseopt@vspace[#1]{%
  \advance\eql@vspaceskip@\glueexpr#1\relax\eql@parseopt@peek}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Parameter Presets}
%
% The package offers two parameter presets
% which lead to somewhat different layout.
% Instead of setting the internal parameters directly,
% we expose them as public settings so that
% they are easier to read and such that individual settings
% can be used to compose own layouts.
%
%   \macro{\eql@defaults@classic}
% The preset |classic| aims to reproduce
% the \tex/, \latex/ and \amsmath/ layout closely.
% These presets mostly use fixed dimensions:
%    \begin{macrocode}
\def\eql@defaults@classic{%
  \eqnlinesset{numberline=all}%
  \eqnlinesset{mintagsep={.5\fontdimen6\textfont2}}%
  \eqnlinesset{maxcolsep=off}%
  \eqnlinesset{spread={\jot}}%
  \eqnlinesset{tagmargin}%
  \eqnlinesset{tagmarginratio=1}%
  \eqnlinesset{tagmarginthreshold=0.5}%
  \eqnlinesset{leftmargin={\leftmargini}}%
  \eqnlinesset{padding=max}%
  \eqnlinesset{evadetag=off}%
  \eqnlinesset{displayheight=off}%
  \eqnlinesset{displaydepth=off}%
  \eqnlinesset{shortmode=belowsingle}%
  \eqnlinesset{abovecontmode=short}%
  \eqnlinesset{belowcontmode=short}%
  \eqnlinesset{aboveparmode=long}%
  \eqnlinesset{belowparmode=long}%
  \eqnlinesset{abovetopmode=long}%
  \eqnlinesset{belowtopmode=long}%
  \eqnlinesset{abovelongskip={\abovedisplayskip}}%
  \eqnlinesset{belowlongskip={\belowdisplayskip}}%
  \eqnlinesset{aboveshortskip={\abovedisplayshortskip}}%
  \eqnlinesset{belowshortskip={\belowdisplayshortskip}}%
  \eqnlinesset{abovemedskip={.5\abovedisplayskip}}%
  \eqnlinesset{belowmedskip={.5\belowdisplayskip}}%
  \eqnlinesset{abovecontskip=0pt}%
  \eqnlinesset{belowcontskip=0pt}%
  \eqnlinesset{aboveparskip=0pt}%
  \eqnlinesset{belowparskip=0pt}%
  \eqnlinesset{abovetopskip=0pt}%
  \eqnlinesset{belowtopskip=0pt}%
  \eqnlinesset{abovetagskip=0pt}%
  \eqnlinesset{belowtagskip=0pt}%
  \eqnlinesset{equationcr=off}%
  \eqnlinesset{linesfallback=false}%
}
%    \end{macrocode}
%
% values based on 10pt vs 12pt
%   \macro{\eql@defaults@eqnlines}
% The (default) preset |eqnlines| implements a layout
% that scales with the font size by using the units |em|
% and |\normalbaselineskip| for horizontal and vertical spacing, respectively.
% It aims to approximately reproduce the |classic| spacing
% for a 12\,pt computer modern font such that 10\,pt fonts
% will lead to slightly reduced spacing.
% Apart from that, the |eqnlines| setting makes some
% deliberate layout choices that deviate significantly
% from |classic| (maximum column separation,
% no shortening below equations):
%    \begin{macrocode}
\def\eql@defaults@eqnlines{%
  \eqnlinesset{numberline=all}%
  \eqnlinesset{mintagsep=.5em}%
  \eqnlinesset{maxcolsep=2em}%
  \eqnlinesset{spread={0.2\normalbaselineskip}}%
  \eqnlinesset{tagmargin}%
  \eqnlinesset{tagmarginratio=.334}%
  \eqnlinesset{tagmarginthreshold=0.5}%
  \eqnlinesset{leftmargin={\leftmargini}}%
  \eqnlinesset{padding=0pt}%
  \eqnlinesset{evadetag}%
  \eqnlinesset{displayheight=strut}%
  \eqnlinesset{displaydepth=strut}%
  \eqnlinesset{shortmode=above}%
  \eqnlinesset{abovecontmode=noskip}%
  \eqnlinesset{belowcontmode=long}%
  \eqnlinesset{aboveparmode=long}%
  \eqnlinesset{belowparmode=long}%
  \eqnlinesset{abovetopmode=noskip}%
  \eqnlinesset{belowtopmode=long}%
  \eqnlinesset{longskip={0.75\normalbaselineskip
    plus 0.25\normalbaselineskip minus 0.4\normalbaselineskip}}%
  \eqnlinesset{aboveshortskip={0.0\normalbaselineskip
    plus 0.25\normalbaselineskip}}%
  \eqnlinesset{belowshortskip={0.0\normalbaselineskip
    plus 0.25\normalbaselineskip}}%
  \eqnlinesset{medskip={0.4\normalbaselineskip
    plus 0.2\normalbaselineskip minus 0.2\normalbaselineskip}}%
  \eqnlinesset{abovecontskip=0pt}%
  \eqnlinesset{belowcontskip=0pt}%
  \eqnlinesset{aboveparskip=0pt}%
  \eqnlinesset{belowparskip=0pt}%
  \eqnlinesset{abovetopskip=0pt}%
  \eqnlinesset{belowtopskip=0pt}%
  \eqnlinesset{abovetagskip={0.25\normalbaselineskip
    minus 0.25\normalbaselineskip}}%
  \eqnlinesset{belowtagskip={0.25\normalbaselineskip
    minus 0.25\normalbaselineskip}}%
  \eqnlinesset{equationcr=break}%
  \eqnlinesset{linesfallback=true}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Component Selection}
%
% The following routines provide several additional math environments
% beyond |equations|. They also backup and overwrite the original routines
% of \latex/ and \amsmath/ carefully.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Tools.}
%
%   \macro{\eql@provide@movecmd}
%   \macro{\eql@provide@moveenv}
%   \macro{\eql@provide@undefinecmd}
%   \macro{\eql@provide@undefineenv}
% We introduce a couple of tools to rename and undefine
% commands and environments:
%    \begin{macrocode}
\def\eql@provide@movecmd#1#2{%
  \eql@letcs{#1\expandafter}\csname#2\endcsname
}
\def\eql@provide@moveenv#1#2{%
  \eql@provide@movecmd{#1}{#2}%
  \ifcsname end#2\endcsname
    \eql@provide@movecmd{end#1}{end#2}%
  \fi
}
\def\eql@provide@undefinecmd#1{%
  \eql@letcs{#1}\@undefined
}
\def\eql@provide@undefineenv#1{%
  \eql@provide@undefinecmd{#1}%
  \eql@provide@undefinecmd{end#1}%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Fix Endings for amsmath Environments.}
%
% The \amsmath/ derived environments forward their ending routines
% directly to the ending routines for the main environments
% |gather|, |multline|, |align|, |aligned|.
% This causes a problem when the main environments are replaced
% but the derived ones are still used. We fix the potential problem
% by copying the ending routines of the main environments
% to the ending routines of the derived environments.
%
%   \macro{\eql@amsmath@endfix}
% Check whether the original forwarding
% of an ending routine is still in place
% (other packages or future updates to \amsmath/ might change the behaviour).
% If so, copy the ending routine into place:
%    \begin{macrocode}
\def\eql@amsmath@endfix#1#2{%
  \long\edef\eql@tmpa{\expandafter\noexpand\csname end#2\endcsname}%
  \expandafter\ifx\csname end#1\endcsname\eql@tmpa
    \eql@provide@movecmd{end#1}{end#2}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@amsmath@fixmatrix}
%   \macro{\eql@amsmath@fixmatrixend}
% \TODO describe
%    \begin{macrocode}
\def\eql@amsmath@fixmatrix#1{%
  \expandafter\let\expandafter\eql@tmp\csname#1\endcsname
  \begingroup
    \let\matrix@check\@gobble
    \def\env@matrix{\noexpand\env@matrix}%
    \def\env@cases{\noexpand\env@cases}%
    \global\edef\eql@tmp{\eql@tmp}%
  \endgroup
  \eql@letcs{#1}\eql@tmp
}
\def\eql@amsmath@fixmatrixend#1{%
  \expandafter\let\expandafter\eql@tmp\csname end#1\endcsname
  \begingroup
    \expandafter\def\expandafter\endmatrix\expandafter{%
      \expandafter\unexpanded\expandafter{\endmatrix}}%
    \global\long\edef\eql@tmp{\eql@tmp}%
  \endgroup
  \eql@letcs{end#1}\eql@tmp
}
%    \end{macrocode}
%
%   \macro{\eql@amsmath@fixends}
% Perform the replacement for all \amsmath/ environments
% whenever \amsmath/ is loaded:
%    \begin{macrocode}
\def\eql@amsmath@fixends{%
  \eql@amsmath@after{%
    \eql@amsmath@endfix{flalign}{align}%
    \eql@amsmath@endfix{alignat}{align}%
    \eql@amsmath@endfix{xalignat}{align}%
    \eql@amsmath@endfix{xxalignat}{align}%
    \eql@amsmath@endfix{gather*}{gather}%
    \eql@amsmath@endfix{multline*}{multline}%
    \eql@amsmath@endfix{align*}{align}%
    \eql@amsmath@endfix{flalign*}{align}%
    \eql@amsmath@endfix{alignat*}{align}%
    \eql@amsmath@endfix{xalignat*}{align}%
    \eql@amsmath@endfix{gathered}{aligned}%
    \eql@amsmath@endfix{alignedat}{aligned}%
  }
}
%    \end{macrocode}
%
%   \macro{\eql@amsmath@fixmatrices}
% Perform the replacement for all \amsmath/ environments
% whenever \amsmath/ is loaded:
%    \begin{macrocode}
\def\eql@amsmath@fixmatrices{%
  \eql@amsmath@after{%
    \eql@amsmath@fixmatrix{cases}%
    \eql@amsmath@fixmatrix{matrix}%
    \eql@amsmath@fixmatrix{pmatrix}%
    \eql@amsmath@fixmatrixend{pmatrix}%
    \eql@amsmath@fixmatrixend{bmatrix}%
    \eql@amsmath@fixmatrixend{Bmatrix}%
    \eql@amsmath@fixmatrixend{vmatrix}%
    \eql@amsmath@fixmatrixend{Vmatrix}%
  }
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Backup amsmath Environments.}
%
% We can backup all \amsmath/ environments \textit{env} to |ams|\textit{env}
% so that they can be used in parallel if needed.
%
%   \macro{\eql@provide@backup@amsenv}
% Copy an \amsmath/ environment \textit{env} to |ams|\textit{env}
% whenever \amsmath/ is loaded:
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@backup@amsenv#1{%
  \eql@amsmath@after{%
    \eql@provide@moveenv{ams#1}{#1}%
    \eql@tagging@register@luamml{ams#1}%
    \eql@markline@amsthm@move{ams#1}{#1}%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup@amsbox}
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@backup@amsbox#1{%
  \eql@amsmath@after{%
    \eql@provide@moveenv{ams#1}{#1}%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup@eqref}
% Copy an |eqref| to |amseqref| whenever \amsmath/ is loaded:
%    \begin{macrocode}
\def\eql@provide@backup@eqref{%
  \eql@amsmath@after{%
    \eql@provide@movecmd{amseqref}{eqref}%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup@multlined}
% The environment |multlined| is supplied by \ctanpkg{mathtools}.
% We copy it to |amsmultlined| anyway,
% but whenever \ctanpkg{mathtools} is loaded:
%    \begin{macrocode}
\def\eql@provide@backup@multlined{%
  \AddToHook{package/mathtools/after}{%
    \eql@provide@moveenv{amsmultlined}{multlined}}%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup@equation}
% The \latex/ environment |equation| is overwritten by several packages
% to implement their adjustments.
% Here we cater for adjustments through \amsmath/, \ctanpkg{hyperref}
% and the PDF tagging mechanism.
% Copy |equation| and |equation*| whenever \amsmath/ is loaded.
% Whenever \ctanpkg{hyperref} is loaded,
% and \amsmath/ is not yet present,
% backup the original \latex/ and \ctanpkg{hyperref} versions of |equation|.
% If neither \ctanpkg{hyperref} nor \amsmath/ are present,
% just backup the original \latex/ |equation|.
% The PDF tagging mechanism registers |equation| upon |\begin{document}|.
% We thus need to register all copies of |equation| on our own,
% so that they can be used with their new names:
%    \begin{macrocode}
\def\eql@provide@backup@equation{%
  \eql@amsmath@after{%
    \eql@provide@moveenv{amsequation}{equation}%
    \eql@provide@moveenv{amsequation*}{equation*}%
    \eql@tagging@register@env{amsequation}%
    \eql@tagging@register@env{amsequation*}%
    \eql@tagging@register@luamml{amsequation}%
    \eql@tagging@register@luamml{amsequation*}%
    \eql@markline@amsthm@move{amsequation}{equation}%
    \eql@markline@amsthm@move{amsequation*}{equation*}%
  }%
  \AddToHook{package/hyperref/after}{%
    \@ifpackageloaded{amsmath}{}{%
      \eql@provide@moveenv{hyperrefequation}{equation}%
      \eql@tagging@register@env{hyperrefequation}%
      \eql@tagging@register@luamml{hyperrefequation}%
      \eql@markline@amsthm@move{hyperequation}{equation}%
    }%
  }%
  \@ifpackageloaded{amsmath}{}{%
    \@ifpackageloaded{hyperref}{%
      \let\latexequation\H@equation
      \let\endlatexequation\H@endequation
    }{\eql@provide@moveenv{latexequation}{equation}}%
    \eql@tagging@register@env{latexequation}%
    \eql@tagging@register@luamml{latexequation}%
    \eql@markline@amsthm@move{latexequation}{equation}%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup@displaymath}
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@backup@displaymath{%
  \eql@provide@moveenv{latexdisplaymath}{displaymath}%
  \eql@markline@amsthm@move{latexdisplaymath}{displaymath}%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup@subequations}
% The \amsmath/ |subequations| environment is adjusted by
% \ctanpkg{hyperref} through an environment hook,
% but this hook gets applied only later at |\begin{document}|.
% Hence, we need to supply the hook routine to the new routine ourselves:
%    \begin{macrocode}
\def\eql@provide@backup@subequations{%
  \eql@amsmath@after{%
    \eql@provide@moveenv{amssubequations}{subequations}%
  }%
  \AddToHook{package/hyperref/after}{%
    \AddToHook{cmd/amssubequations/before}%
    {%
      \stepcounter{equation}%
      \protected@edef\theHparentequation{\theHequation}%
      \addtocounter{equation}{-1}%
    }%
    \AddToHook{cmd/amssubequations/after}%
    {%
      \def\theHequation{\theHparentequation\alph{equation}}%
      \ignorespaces
    }%
  }%
}
%    \end{macrocode}
%
%   \macro{\eql@provide@backup}
% Backup all \amsmath/ environments:
%    \begin{macrocode}
\def\eql@provide@backup{%
  \eql@provide@backup@eqref
  \eql@provide@backup@equation
  \eql@provide@backup@displaymath
  \eql@provide@backup@amsenv{gather}%
  \eql@provide@backup@amsenv{multline}%
  \eql@provide@backup@amsenv{align}%
  \eql@provide@backup@amsenv{flalign}%
  \eql@provide@backup@amsenv{alignat}%
  \eql@provide@backup@amsenv{xalignat}%
  \eql@provide@backup@amsenv{xxalignat}%
  \eql@provide@backup@amsenv{gather*}%
  \eql@provide@backup@amsenv{multline*}%
  \eql@provide@backup@amsenv{align*}%
  \eql@provide@backup@amsenv{flalign*}%
  \eql@provide@backup@amsenv{alignat*}%
  \eql@provide@backup@amsenv{xalignat*}%
  \eql@provide@backup@amsbox{gathered}%
  \eql@provide@backup@multlined
  \eql@provide@backup@amsbox{aligned}%
  \eql@provide@backup@amsbox{alignedat}%
  \eql@provide@backup@amsbox{cases}%
  \eql@provide@backup@amsbox{matrix}%
  \eql@provide@backup@amsbox{pmatrix}%
  \eql@provide@backup@amsbox{bmatrix}%
  \eql@provide@backup@amsbox{Bmatrix}%
  \eql@provide@backup@amsbox{vmatrix}%
  \eql@provide@backup@amsbox{Vmatrix}%
  \eql@provide@backup@subequations
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Replacement amsmath Environments.}
%
% \TODO describe
%    \begin{macrocode}
\def\eql@alignat@gobblecol#1{%
  \eql@ifnextchar@tight\bgroup{\@firstoftwo{#1}}{#1}}
%    \end{macrocode}
%
%   \environment{eql@gathered}
%   \environment{eql@multlined}
%   \environment{eql@aligned}
% Define replacement versions for boxed environments
% |gathered|, |multlined| and |aligned|
% which forward to |equationsbox|
% with specific presets:
%    \begin{macrocode}
\newenvironment{eql@gathered}
  {\eqnaddopt{lines}\equationsbox}{\endequationsbox}
\newenvironment{eql@multlined}
  {\eqnaddopt{lines,padding,shape=steps}\equationsbox}{\endequationsbox}
\newenvironment{eql@aligned}
  {\eqnaddopt{columns}\equationsbox}{\endequationsbox}
\newenvironment{eql@alignedat}
  {\eqnaddopt{columns,colsep=off}\eql@alignat@gobblecol\equationsbox}
  {\endequationsbox}
\newenvironment{eql@cases}
  {\eqnaddopt{cases}\equationsbox}{\endequationsbox}
\newenvironment{eql@matrix}
  {\eqnaddopt{matrix=.}\equationsbox}{\endequationsbox}
\newenvironment{eql@pmatrix}
  {\eqnaddopt{matrix=r}\equationsbox}{\endequationsbox}
\newenvironment{eql@bmatrix}
  {\eqnaddopt{matrix=s}\equationsbox}{\endequationsbox}
\newenvironment{eql@Bmatrix}
  {\eqnaddopt{matrix=c}\equationsbox}{\endequationsbox}
\newenvironment{eql@vmatrix}
  {\eqnaddopt{matrix=v}\equationsbox}{\endequationsbox}
\newenvironment{eql@Vmatrix}
  {\eqnaddopt{matrix=d}\equationsbox}{\endequationsbox}
%    \end{macrocode}
%
%   \environment{eql@equation}
%   \environment{eql@gather}
%   \environment{eql@multline}
%   \environment{eql@align}
% Define replacement versions for display environments
% |equation|, |gather|, |multline|, |aligned| and derivatives
% which forward to |equations| with specific presets:
% \TODO amsmath at variants would need predefined columns for full operation
%    \begin{macrocode}
\newenvironment{eql@equation}
  {\eqnaddopt{equation}\equations}{\endequations}
\newenvironment{eql@displaymath}
  {\eqnaddopt{equation,nonumber}\equations}{\endequations}
\newenvironment{eql@gather}
  {\eqnaddopt{lines}\equations}{\endequations}
\newenvironment{eql@multline}
  {\eqnaddopt{lines,padding=max,shape=steps,numberline=out}\equations}
  {\endequations}
\newenvironment{eql@align}
  {\eqnaddopt{columns}\equations}{\endequations}
\newenvironment{eql@flalign}
  {\eqnaddopt{fulllength}\eql@align}{\endequations}
\newenvironment{eql@alignat}
  {\eqnaddopt{colsep=off}\eql@xalignat}{\endequations}
\newenvironment{eql@xalignat}
  {\eql@alignat@gobblecol\eql@align}{\endequations}
\newenvironment{eql@xxalignat}
  {\eqnaddopt{fulllength}\eql@xalignat}{\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}
\newenvironment{eql@alignat*}
  {\eqnaddopt{nonumber}\eql@alignat}{\endequations}
\newenvironment{eql@xalignat*}
  {\eqnaddopt{nonumber}\eql@xalignat}{\endequations}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Install Additional Environments.}
%
% The additional environments need to be installed
% at their intended names which can be adjusted by the user.
%
%   \macro{\eql@provide@onlyonce}
% Process arguments for providing a specific environment.
% |#1| describes the environment using the \amsmath/ name.
% |#2| specifies the desired target name.
% If |#2| is empty or equals |#1|,
% overwrite the \amsmath/ environment in place
% making sure that the replacement is robust against
% loading \amsmath/ before or after.
% If |#2| equals `|*|', just overwrite the \amsmath/ environment
% in place immediately (e.g.\ within a block in the document body):
%    \begin{macrocode}
\def\eql@provide@onlyonce#1#2{%
  \def\eql@tmp{#2}\def\eql@tmpa{#1}%
  \ifx\eql@tmp\eql@tmpa
    \let\eql@tmp\@empty
  \fi
  \ifx\eql@tmp\@empty
    \let\eql@tmp\@undefined
    \ifx\@nodocument\relax
      \def\eql@tmp{#1}%
    \fi
    \ifcsname eql@provided@#1\endcsname
      \def\eql@tmp{#1}%
    \fi
    \eql@letcs{eql@provided@#1}\eql@true
  \else
    \def\eql@tmpa{*}%
    \ifx\eql@tmp\eql@tmpa
      \def\eql@tmp{#1}%
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@eqref}
% Provide |\eqref| as the macro |#1|.
% We have to check whether |#1| is empty or equals |\eqref|
% or takes the value `|*|'. If not, we should strip the backslash
% for further processing.
% Copy the macro into place, and copy again
% when \amsmath/ or \ctanpkg{mathtools} are loaded.
% Remove definition before \amsmath/ is loaded in the future
% to avoid a potential error:
%    \begin{macrocode}
\def\eql@provide@eqref#1{%
  \def\eql@tmp{#1}\def\eql@tmpa{\eqref}%
  \ifx\eql@tmp\eql@tmpa
    \let\eql@tmp\@empty
  \fi
  \ifx\eql@tmp\@empty
    \eql@provide@onlyonce{eqref}{}%
  \else
    \def\eql@tmpa{*}%
    \ifx\eql@tmp\eql@tmpa
      \def\eql@tmp{eqref}%
    \else
      \edef\eql@tmp{\expandafter\@gobble\string#1}%
    \fi
  \fi
  \ifdefined\eql@tmp
    \expandafter\eql@provide@movecmd\expandafter{\eql@tmp}{eql@eqref}%
  \else
    \eql@amsmath@after{%
      \eql@provide@movecmd{eqref}{eql@eqref}%
    }%
    \AddToHook{package/mathtools/after}{%
      \eql@provide@movecmd{eqref}{eql@eqref}%
    }%
    \eql@provide@movecmd{eqref}{eql@eqref}%
    \eql@amsmath@undefine\eqref
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@amsenv}
% Provide one of the \amsmath/ environments.
% Copy into place, and copy again when \amsmath/ is loaded.
% Remove definition before \amsmath/ is loaded in the future
% to avoid an error:
%    \begin{macrocode}
\def\eql@provide@amsenv#1#2{%
  \eql@provide@onlyonce{#1}{#2}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@#1}%
    \eql@tagging@register@luamml{\eql@tmp}%
    \eql@markline@amsthm@register{\eql@tmp}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{#1}{eql@#1}%
      \eql@markline@amsthm@register{#1}%
    }%
    \AddToHook{package/mathtools/after}{%
      \eql@provide@moveenv{#1}{eql@#1}%
      \eql@markline@amsthm@register{#1}%
    }%
    \eql@provide@moveenv{#1}{eql@#1}%
    \eql@markline@amsthm@register{#1}%
    \eql@amsmath@before{\eql@provide@undefineenv{#1}}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@amsbox}
% Provide one of the \amsmath/ subequation structures.
% Copy into place, and copy again when \amsmath/ is loaded.
% Remove definition before \amsmath/ is loaded in the future
% to avoid an error:
%    \begin{macrocode}
\def\eql@provide@amsbox#1#2{%
  \eql@provide@onlyonce{#1}{#2}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@#1}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{#1}{eql@#1}}%
    \AddToHook{package/mathtools/after}{%
      \eql@provide@moveenv{#1}{eql@#1}}%
    \eql@provide@moveenv{#1}{eql@#1}%
    \eql@amsmath@before{\eql@provide@undefineenv{#1}}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@multlined}
% Provide \ctanpkg{mathtools} environment |multlined|.
% Copy into place, and copy again when \ctanpkg{mathtools} is loaded.
% Remove definition before \ctanpkg{mathtools} is loaded in the future
% to avoid an error:
%    \begin{macrocode}
\def\eql@provide@multlined#1{%
  \eql@provide@onlyonce{multlined}{#1}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@multlined}%
  \else
    \AddToHook{package/mathtools/after}{%
      \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}
%
%   \macro{\eql@provide@matrix}
% Provide the |cases| and |matrix| environments.
% Copy into place, and copy again when \amsmath/ is loaded:
%    \begin{macrocode}
\def\eql@provide@matrix#1#2#3{%
  \eql@provide@onlyonce{#1}{#3}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@#1}%
    \eql@tagging@register@luamml{\eql@tmp}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{#1}{eql@#1}%
    }%
    \eql@provide@moveenv{#1}{eql@#1}%
    \ifdefined#2\eql@amsmath@before{\eql@provide@undefineenv{#1}}\fi%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@equation}
% Provide the environment |equation|.
% Copy into place, and copy again
% when \amsmath/ or \ctanpkg{hyperref} are loaded.
% When PDF tagging is active, the environment is modified
% at |\begin{document}| in an undesirable fashion,
% so copy the definition again:
%    \begin{macrocode}
\def\eql@provide@equation#1{%
  \eql@provide@onlyonce{equation}{#1}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@equation}%
    \eql@tagging@register@luamml{\eql@tmp}%
    \eql@markline@amsthm@register{\eql@tmp}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{equation}{eql@equation}%
      \eql@markline@amsthm@register{equation}%
    }%
    \AddToHook{package/hyperref/after}{%
      \@ifpackageloaded{amsmath}{}{%
        \eql@provide@moveenv{equation}{eql@equation}%
        \eql@markline@amsthm@register{equation}%
      }%
    }%
    \eql@provide@moveenv{equation}{eql@equation}%
    \eql@markline@amsthm@register{equation}%
    \ifdefined\eql@tagging@on
      \AddToHook{begindocument/end}{%
        \eql@provide@moveenv{equation}{eql@equation}%
        \eql@markline@amsthm@register{equation}%
      }%
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@equationstar}
% Provide the environment |equation*|.
% Copy into place, and copy again
% when \amsmath/ or \ctanpkg{hyperref} are loaded.
% Remove definition of |equation*|
% before \ctanpkg{amsmath} is loaded in the future to avoid an error.
% When PDF tagging is active, the environment is modified
% at |\begin{document}| in an undesirable fashion,
% so copy the definition again:
%    \begin{macrocode}
\def\eql@provide@equationstar#1{%
  \eql@provide@onlyonce{equation*}{#1}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@equation*}%
    \eql@tagging@register@luamml{\eql@tmp}%
    \eql@markline@amsthm@register{\eql@tmp}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{equation*}{eql@equation*}%
      \eql@markline@amsthm@register{equation*}%
    }%
    \eql@provide@moveenv{equation*}{eql@equation*}%
    \eql@markline@amsthm@register{equation*}%
    \eql@amsmath@before{\eql@provide@undefineenv{equation*}}%
    \ifdefined\eql@tagging@on
      \AddToHook{begindocument/end}{%
        \eql@provide@moveenv{equation*}{eql@equation*}%
        \eql@markline@amsthm@register{equation*}%
      }%
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@displaymath}
% \TODO describe
%    \begin{macrocode}
\def\eql@provide@displaymath#1{%
  \eql@provide@onlyonce{displaymath}{#1}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@displaymath}%
    \eql@markline@amsthm@register{\eql@tmp}%
    \eql@tagging@register@luamml{\eql@tmp}%
  \else
    \eql@provide@moveenv{displaymath}{eql@displaymath}%
    \eql@markline@amsthm@register{displaymath}%
    \ifdefined\eql@tagging@on
      \AddToHook{begindocument/end}{%
        \eql@provide@moveenv{displaymath}{eql@displaymath}}%
    \fi
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@subequations}
% Provide the \amsmath/ environment |subequations|.
% Copy into place, and copy again
% when \amsmath/ is loaded.
% \ctanpkg{hyperref} adds a hook to the command
% which messes up the parsing of optional arguments
% (even if the hook is emptied).
% The hook placement happens at |\begin{document}|,
% so we copy the environment again afterwards.
% We also remove the hook (after adding an empty hook to avoid errors).
% Remove definition before \amsmath/ is loaded in the future
% to avoid an error:
%    \begin{macrocode}
\def\eql@provide@subequations#1{%
  \eql@provide@onlyonce{subequations}{#1}%
  \ifdefined\eql@tmp
    \eql@provide@moveenv{\eql@tmp}{eql@subequations}%
  \else
    \eql@amsmath@after{%
      \eql@provide@moveenv{subequations}{eql@subequations}%
    }%
    \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{begindocument/end}{%
        \eql@provide@moveenv{subequations}{eql@subequations}}%
    }%
    \eql@provide@moveenv{subequations}{eql@subequations}%
    \eql@amsmath@before{\eql@provide@undefineenv{subequations}}%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@sqr}
% Provide the symbolic environment |\[|\,\ldots|\]|.
% Copy into place, and copy again when \amsmath/ is loaded.
% If PDF tagging is active, some undesired modifications
% happen at |\begin{document}|, so copy again afterwards:
%    \begin{macrocode}
\def\eql@provide@sqr{%
  \let\[\eql@sqr@open
  \let\]\eql@sqr@close
  \eql@amsmath@after{%
    \let\[\eql@sqr@open
    \let\]\eql@sqr@close
  }%
  \ifdefined\eql@tagging@on
    \AddToHook{begindocument/end}{%
      \let\[\eql@sqr@open
      \let\]\eql@sqr@close
    }%
  \fi
}
%    \end{macrocode}
%
%   \macro{\eql@provide@ang}
% Provide the symbolic environment |\<|\,\ldots|\>|.
% This is easy because none of the other packages uses this structure:
%    \begin{macrocode}
\def\eql@provide@ang{%
  \let\<\eql@ang@open
  \let\>\eql@ang@close
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Interface.}
%
%   \key{provide}
% We provide the additional environments via key-value pairs,
% where the value specifies the intended name:
%    \begin{macrocode}
\eql@define@key{provide}{equation}[]{\eql@provide@equation{#1}}
\eql@define@key{provide}{equation*}[]{\eql@provide@equationstar{#1}}
\eql@define@key{provide}{displaymath}[]{\eql@provide@displaymath{#1}}
\eql@define@key{provide}{gather}[]{\eql@provide@amsenv{gather}{#1}}
\eql@define@key{provide}{multline}[]{\eql@provide@amsenv{multline}{#1}}
\eql@define@key{provide}{align}[]{\eql@provide@amsenv{align}{#1}}
\eql@define@key{provide}{flalign}[]{\eql@provide@amsenv{flalign}{#1}}
\eql@define@key{provide}{alignat}[]{\eql@provide@amsenv{alignat}{#1}}
\eql@define@key{provide}{xalignat}[]{\eql@provide@amsenv{xalignat}{#1}}
\eql@define@key{provide}{xxalignat}[]{\eql@provide@amsenv{xxalignat}{#1}}
\eql@define@key{provide}{gather*}[]{\eql@provide@amsenv{gather*}{#1}}
\eql@define@key{provide}{multline*}[]{\eql@provide@amsenv{multline*}{#1}}
\eql@define@key{provide}{align*}[]{\eql@provide@amsenv{align*}{#1}}
\eql@define@key{provide}{flalign*}[]{\eql@provide@amsenv{flalign*}{#1}}
\eql@define@key{provide}{alignat*}[]{\eql@provide@amsenv{alignat*}{#1}}
\eql@define@key{provide}{xalignat*}[]{\eql@provide@amsenv{xalignat*}{#1}}
\eql@define@key{provide}{gathered}[]{\eql@provide@amsbox{gathered}{#1}}
\eql@define@key{provide}{multlined}[]{\eql@provide@multlined{#1}}
\eql@define@key{provide}{aligned}[]{\eql@provide@amsbox{aligned}{#1}}
\eql@define@key{provide}{alignedat}[]{\eql@provide@amsbox{alignedat}{#1}}
\eql@define@key{provide}{cases}[]{\eql@provide@matrix{cases}\eql@false{#1}}
\eql@define@key{provide}{matrix}[]{\eql@provide@matrix{matrix}\eql@false{#1}}
\eql@define@key{provide}{pmatrix}[]{\eql@provide@matrix{pmatrix}\eql@false{#1}}
\eql@define@key{provide}{bmatrix}[]{\eql@provide@matrix{bmatrix}\eql@true{#1}}
\eql@define@key{provide}{Bmatrix}[]{\eql@provide@matrix{Bmatrix}\eql@true{#1}}
\eql@define@key{provide}{vmatrix}[]{\eql@provide@matrix{vmatrix}\eql@true{#1}}
\eql@define@key{provide}{Vmatrix}[]{\eql@provide@matrix{Vmatrix}\eql@true{#1}}
\eql@define@key{provide}{subequations}[]{\eql@provide@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@eqref{#1}}
\eql@define@key{provide}{tagform}[]{%
  \def\tagform@##1{\maketag@@@{\eql@tags@tagform{#1}}}}
\eql@define@key{provide}{maketag}[]{%
  \def\maketag@@@##1{\eql@tags@taglayout{##1}}}
%    \end{macrocode}
%
%   \imacro{\eqnlinesprovide}
% Provide an additional environment or macro via key-value interface:
%    \begin{macrocode}
\newcommand{\eqnlinesprovide}[1]{%
  \eql@setkeys{provide}{#1}%
  \ignorespaces
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Global and Package Options}
%
% Handle global and package options:
%
% Disable error message for exclusive package options:
%    \begin{macrocode}
\let\eql@error@packageoption\@gobble
%    \end{macrocode}
%
% Declare math layout options |leqno| and |fleqn| for common \latex/ classes:
%    \begin{macrocode}
\DeclareOption{leqno}{\eqnlinesset{tagsleft}}
\DeclareOption{fleqn}{\eqnlinesset{left}}
%    \end{macrocode}
%
% Pass undeclared options on to \ctanpkg{keyval} processing:
%    \begin{macrocode}
\DeclareOption*{\expandafter\eqnlinesset\expandafter{\CurrentOption}}
%    \end{macrocode}
%
% Set defaults for package:
%    \begin{macrocode}
\eql@defaults@eqnlines
\eql@mode@columns
\eql@mode@aligned
%    \end{macrocode}
%
% Make sure that the \amsmath/ conditionals
% |\iftagsleft@| and |\if@fleqn| are declared
% without spelling out their name
% which may upset the \tex/ conditional parsing mechanism:
%    \begin{macrocode}
\ifdefined\tagsleft@true\else
  \expandafter\newif\csname iftagsleft@\endcsname
\fi
\ifdefined\@fleqntrue\else
  \expandafter\newif\csname if@fleqn\endcsname
\fi
%    \end{macrocode}
%
% Import \amsmath/ switches |leqno| as |tagsleft|
% and |fleqn| as |left|:
%    \begin{macrocode}
\eql@amsmath@after{%
  \ifnum\eql@provide@opt@env=\tw@
    \iftagsleft@
      \eqnlinesset{tags=left}%
    \else
      \eqnlinesset{tags=right}%
    \fi
    \if@fleqn
      \eqnlinesset{layout=left}%
    \else
      \eqnlinesset{layout=center}%
    \fi
  \fi
}
%    \end{macrocode}
%
% Process package options:
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%   \macro{\eql@error@packageoption}
% Enable error message for exclusive package options:
%    \begin{macrocode}
\def\eql@error@packageoption#1{%
  \eql@error{may only use '#1' as a package option}%
}
%    \end{macrocode}
%
% Make the ending statements for \amsmath/ environments independent
% if desired, so that they may be overwritten individually:
%    \begin{macrocode}
\ifnum\eql@provide@opt@env=\tw@
\ifdefined\eql@provide@opt@matrix
  \let\eql@provide@opt@amsmathpatch\eql@false
\fi\fi
\ifdefined\eql@provide@opt@backup
  \let\eql@provide@opt@amsmathpatch\eql@true
\fi
\ifdefined\eql@provide@opt@amsmathpatch
  \eql@amsmath@fixends
  \eql@amsmath@fixmatrices
\fi
%    \end{macrocode}
%
% Backup all \amsmath/ environments that may be overwritten to |ams...|.
% This will happen before any replacements:
%    \begin{macrocode}
\ifdefined\eql@provide@opt@backup\eql@provide@backup\fi
%    \end{macrocode}
%
% Provide native \latex/ environment |equation|
% and symbolic shortcut |\[|\,\ldots|\]| if desired:
%    \begin{macrocode}
\ifnum\eql@provide@opt@env>\z@
  \eqnlinesprovide{equation,equation*,sqr,displaymath}
\fi
%    \end{macrocode}
%
% Provide \amsmath/ equation environments if desired:
%    \begin{macrocode}
\ifnum\eql@provide@opt@env=\tw@
  \eqnlinesprovide{%
    multline,gather,align,flalign,alignat,xalignat,xxalignat,%
    multline*,gather*,align*,flalign*,alignat*,xalignat*,%
    multlined,gathered,aligned,alignedat,%
    subequations}
\fi
%    \end{macrocode}
%
% Provide symbolic shortcut |\<|\,\ldots|\>| if desired:
%    \begin{macrocode}
\ifdefined\eql@provide@opt@ang\eqnlinesprovide{ang}\fi
%    \end{macrocode}
%
% Provide equation reference |\eqref| if desired:
%    \begin{macrocode}
\ifdefined\eql@provide@opt@eqref\eqnlinesprovide{eqref}\fi
%    \end{macrocode}
%
% Provide |cases| and |matrix| environments if desired:
%    \begin{macrocode}
\ifdefined\eql@provide@opt@matrix
  \eqnlinesprovide{cases,matrix,pmatrix,bmatrix,Bmatrix,vmatrix,Vmatrix}
\fi
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \iffalse
%</package>
% \fi
%
\endinput
