%%
%% This is file `eledmac.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% eledmac.dtx  (with options: `code')
%% 
%%   Author: Author: Peter Wilson ; Herries Press herries dot press at earthlink dot net ; Maïeul Rouquette maieul at maieul dot net
%%   Copyright 2004, 2005 Peter R. Wilson
%%  2011- Maïeul Rouquette
%%   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 the license is in
%%      http://www.latex-project.org/lppl.txt
%%   and version 1.3 or later is part of all distributions of
%%   LaTeX version 2003/06/01 or later.
%% 
%%   This work has the LPPL maintenance status "maintained".
%% 
%%   This work consists of the files listed in the README file.


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{eledmac}[2012/09/16 v1.0.1 LaTeX port of EDMAC]

\newif\ifledfinal
\DeclareOption{final}{\ledfinaltrue}
\DeclareOption{draft}{\ledfinalfalse}
\ExecuteOptions{final}
\ProcessOptions*\relax

\RequirePackage{xargs}
\RequirePackage{etoolbox}
\ifledfinal
  \newcommand*{\showlemma}[1]{#1}
\else
  \newcommand*{\showlemma}[1]{\underline{#1}}
\fi

\let\linenumberlist=\empty

\newcount\@l@dtempcnta \newcount\@l@dtempcntb
\newif\ifl@dmemoir
\@ifclassloaded{memoir}{\l@dmemoirtrue}{\l@dmemoirfalse}

\newcommand{\eledmac@warning}[1]{\PackageWarning{eledmac}{#1}}
\newcommand{\eledmac@error}[2]{\PackageError{eledmac}{#1}{#2}}
\newcommand*{\led@err@NumberingStarted}{%
  \eledmac@error{Numbering has already been started}{\@ehc}}
\newcommand*{\led@err@NumberingNotStarted}{%
  \eledmac@error{Numbering was not started}{\@ehc}}
\newcommand*{\led@err@NumberingShouldHaveStarted}{%
  \eledmac@error{Numbering should already have been started}{\@ehc}}
\newcommand*{\led@mess@NotesChanged}{%
  \typeout{eledmac reminder: }%
  \typeout{ The number of the footnotes in this section
            has changed since the last run.}%
  \typeout{ You will need to run LaTeX two more times
            before the footnote placement}%
  \typeout{ and line numbering in this section are
            correct.}}
\newcommand*{\led@mess@SectionContinued}[1]{%
  \message{Section #1 (continuing the previous section)}}
\newcommand*{\led@err@LineationInNumbered}{%
  \eledmac@error{You can't use \string\lineation\space within
                a numbered section}{\@ehc}}
\newcommand*{\led@warn@BadLineation}{%
  \eledmac@warning{Bad \string\lineation\space argument}}
\newcommand*{\led@warn@BadLinenummargin}{%
  \eledmac@warning{Bad \string\linenummargin\space argument}}
\newcommand*{\led@warn@BadLockdisp}{%
  \eledmac@warning{Bad \string\lockdisp\space argument}}
\newcommand*{\led@warn@BadSublockdisp}{%
  \eledmac@warning{Bad \string\sublockdisp\space argument}}
\newcommand*{\led@warn@NoLineFile}[1]{%
  \eledmac@warning{Can't find line-list file #1}}
\newcommand*{\led@warn@BadAdvancelineSubline}{%
  \eledmac@warning{\string\advanceline\space produced a sub-line
                  number less than zero.}}
\newcommand*{\led@warn@BadAdvancelineLine}{%
  \eledmac@warning{\string\advanceline\space produced a line
                  number less than zero.}}
\newcommand*{\led@warn@BadSetline}{%
  \eledmac@warning{Bad \string\setline\space argument}}
\newcommand*{\led@warn@BadSetlinenum}{%
  \eledmac@warning{Bad \string\setlinenum\space argument}}
\newcommand*{\led@err@PstartNotNumbered}{%
  \eledmac@error{\string\pstart\space must be used within a
                numbered section}{\@ehc}}
\newcommand*{\led@err@PstartInPstart}{%
  \eledmac@error{\string\pstart\space encountered while another
                \string\pstart\space was in effect}{\@ehc}}
\newcommand*{\led@err@PendNotNumbered}{%
  \eledmac@error{\string\pend\space must be used within a
                numbered section}{\@ehc}}
\newcommand*{\led@err@PendNoPstart}{%
  \eledmac@error{\string\pend\space must follow a \string\pstart}{\@ehc}}
\newcommand*{\led@err@AutoparNotNumbered}{%
  \eledmac@error{\string\autopar\space must be used within a
                numbered section}{\@ehc}}
\newcommand*{\led@warn@BadAction}{%
  \eledmac@warning{Bad action code, value \next@action.}}
\newcommand*{\led@warn@DuplicateLabel}[1]{%
  \eledmac@warning{Duplicate definition of label `#1' on page \the\pageno.}}
\newcommand*{\led@warn@RefUndefined}[1]{%
  \eledmac@warning{Reference `#1' on page \the\pageno\space undefined.
                  Using `000'.}}
\newcommand*{\led@warn@NoMarginpars}{%
  \eledmac@warning{You can't use \string\marginpar\space in numbered text}}
\newcommand*{\led@warn@BadSidenotemargin}{%
  \eledmac@warning{Bad \string\sidenotemmargin\space argument}}
\newcommand*{\led@warn@NoIndexFile}[1]{%
  \eledmac@warning{Undefined index file #1}}
\newcommand*{\led@err@TooManyColumns}{%
  \eledmac@error{Too many columns}{\@ehc}}
\newcommand*{\led@err@UnequalColumns}{%
  \eledmac@error{Number of columns is not equal to the number
                in the previous row (or \protect\\ \space forgotten?)}{\@ehc}}
\newcommand*{\led@err@LowStartColumn}{%
  \eledmac@error{Start column is too low}{\@ehc}}
\newcommand*{\led@err@HighEndColumn}{%
  \eledmac@error{End column is too high}{\@ehc}}
\newcommand*{\led@err@ReverseColumns}{%
  \eledmac@error{Start column is greater than end column}{\@ehc}}
\newcount\section@num
\section@num=0
\let\extensionchars=\empty
\newif\ifnumbering
\newif\ifl@dpairing
  \l@dpairingfalse
\newif\ifpst@rtedL
  \pst@rtedLfalse
\newcount\l@dnumpstartsL
\newif\ifledRcol
\newif\ifnumberingR
\newcommand*{\beginnumbering}{%
  \ifnumbering
    \led@err@NumberingStarted
    \endnumbering
  \fi
  \global\numberingtrue
  \global\advance\section@num \@ne
  \initnumbering@reg
  \message{Section \the\section@num }%
  \line@list@stuff{\jobname.\extensionchars\the\section@num}%
  \l@dend@stuff
  \setcounter{pstart}{1}
}
\newcommand*{\initnumbering@reg}{%
  \global\pst@rtedLfalse
  \global\l@dnumpstartsL \z@
  \global\absline@num \z@
  \global\line@num \z@
  \global\subline@num \z@
  \global\@lock \z@
  \global\sub@lock \z@
  \global\sublines@false
  \global\let\next@page@num=\relax
  \global\let\sub@change=\relax
  \resetprevline@
  }

\def\endnumbering{%
  \ifnumbering
    \global\numberingfalse
    \normal@pars
    \ifl@dpairing
      \global\pst@rtedLfalse
    \else
      \ifx\insertlines@list\empty\else
        \global\noteschanged@true
      \fi
      \ifx\line@list\empty\else
        \global\noteschanged@true
      \fi
    \fi
    \ifnoteschanged@
      \led@mess@NotesChanged
    \fi
  \else
    \led@err@NumberingNotStarted
  \fi
  \autoparfalse}
\newcommand{\pausenumbering}{%
  \endnumbering\global\numberingtrue}
\newcommand*{\resumenumbering}{%
  \ifnumbering
     \global\pst@rtedLtrue
     \global\advance\section@num \@ne
     \led@mess@SectionContinued{\the\section@num}%
     \line@list@stuff{\jobname.\extensionchars\the\section@num}%
     \l@dend@stuff
  \else
    \led@err@NumberingShouldHaveStarted
    \endnumbering
    \beginnumbering
  \fi}

\newif\ifbypage@
\newif\ifbypstart@
\newcommand*{\lineation}[1]{{%
  \ifnumbering
    \led@err@LineationInNumbered
  \else
    \def\@tempa{#1}\def\@tempb{page}%
    \ifx\@tempa\@tempb
        \global\bypage@true
        \global\bypstart@false
    \else
       \def\@tempb{pstart}%
       \ifx\@tempa\@tempb
           \global\bypage@false
           \global\bypstart@true
       \else
          \def\@tempb{section}
          \ifx\@tempa\@tempb
           \global\bypage@false
           \global\bypstart@false
          \else
            \led@warn@BadLineation
        \fi
       \fi
    \fi
  \fi}}
\newcount\line@margin
\newcommand*{\linenummargin}[1]{{%
  \l@dgetline@margin{#1}%
  \ifnum\@l@dtempcntb>\m@ne
    \global\line@margin=\@l@dtempcntb
  \fi}}
\newcommand*{\l@dgetline@margin}[1]{%
  \def\@tempa{#1}\def\@tempb{left}%
  \ifx\@tempa\@tempb
    \@l@dtempcntb \z@
  \else
     \def\@tempb{right}%
     \ifx\@tempa\@tempb
       \@l@dtempcntb \@ne
     \else
       \def\@tempb{outer}%
       \ifx\@tempa\@tempb
         \@l@dtempcntb \tw@
       \else
         \def\@tempb{inner}%
         \ifx\@tempa\@tempb
           \@l@dtempcntb \thr@@
         \else
           \led@warn@BadLinenummargin
           \@l@dtempcntb \m@ne
         \fi
       \fi
     \fi
  \fi}

\newcounter{firstlinenum}
  \setcounter{firstlinenum}{5}
\newcounter{linenumincrement}
  \setcounter{linenumincrement}{5}
\newcounter{firstsublinenum}
  \setcounter{firstsublinenum}{5}
\newcounter{sublinenumincrement}
  \setcounter{sublinenumincrement}{5}

\newcommand*{\firstlinenum}[1]{\setcounter{firstlinenum}{#1}}
\newcommand*{\linenumincrement}[1]{\setcounter{linenumincrement}{#1}}
\newcommand*{\firstsublinenum}[1]{\setcounter{firstsublinenum}{#1}}
\newcommand*{\sublinenumincrement}[1]{\setcounter{sublinenumincrement}{#1}}

\newcount\lock@disp
\newcommand{\lockdisp}[1]{{%
  \l@dgetlock@disp{#1}%
  \ifnum\@l@dtempcntb>\m@ne
    \global\lock@disp=\@l@dtempcntb
  \else
    \led@warn@BadLockdisp
  \fi}}
\newcommand*{\l@dgetlock@disp}[1]{
  \def\@tempa{#1}\def\@tempb{first}%
  \ifx\@tempa\@tempb
    \@l@dtempcntb \z@
  \else
     \def\@tempb{last}%
     \ifx\@tempa\@tempb
       \@l@dtempcntb \@ne
     \else
       \def\@tempb{all}%
       \ifx\@tempa\@tempb
         \@l@dtempcntb \tw@
       \else
         \@l@dtempcntb \m@ne
       \fi
     \fi
  \fi}

\newcount\sublock@disp
\newcommand{\sublockdisp}[1]{{%
  \l@dgetlock@disp{#1}%
  \ifnum\@l@dtempcntb>\m@ne
    \global\sublock@disp=\@l@dtempcntb
  \else
    \led@warn@BadSublockdisp
  \fi}}

\newcommand*{\linenumberstyle}[1]{%
  \def\linenumrep##1{\@nameuse{@#1}{##1}}}
\newcommand*{\sublinenumberstyle}[1]{%
  \def\sublinenumrep##1{\@nameuse{@#1}{##1}}}
\linenumberstyle{arabic}
  \let\linenumr@p\linenumrep
\sublinenumberstyle{arabic}
  \let\sublinenumr@p\sublinenumrep

\newlength{\linenumsep}
  \setlength{\linenumsep}{1pc}
\newcommand*{\numlabfont}{\normalfont\scriptsize}
\newcommand*{\ledlinenum}{%
  \numlabfont\linenumrep{\line@num}%
  \ifsublines@
    \ifnum\subline@num>0\relax
      \unskip\fullstop\sublinenumrep{\subline@num}%
    \fi
  \fi}
\newcommand*{\leftlinenum}{%
  \ledlinenum
  \kern\linenumsep}
\newcommand*{\rightlinenum}{%
  \kern\linenumsep
  \ledlinenum}

\newcommand*{\list@create}[1]{\global\let#1=\empty}
\newcommand*{\list@clear}[1]{\global\let#1=\empty}
\newtoks\@toksa \newtoks\@toksb
\global\@toksa={\\}
\long\def\xright@appenditem#1\to#2{%
  \global\@toksb=\expandafter{#2}%
  \xdef#2{\the\@toksb\the\@toksa\expandafter{#1}}%
  \global\@toksb={}}
\long\def\xleft@appenditem#1\to#2{%
  \global\@toksb=\expandafter{#2}%
  \xdef#2{\the\@toksa\expandafter{#1}\the\@toksb}%
  \global\@toksb={}}
\def\gl@p#1\to#2{\expandafter\gl@poff#1\gl@poff#1#2}
\long\def\gl@poff\\#1#2\gl@poff#3#4{\gdef#4{#1}\gdef#3{#2}}

\newcount\line@num
\newcount\subline@num
\newif\ifsublines@
\newcount\absline@num
\newcount\@lock
\newcount\sub@lock
\list@create{\line@list}
\list@create{\insertlines@list}
\list@create{\actionlines@list}
\list@create{\actions@list}

\newcount\page@num
\newcount\endpage@num
\newcount\endline@num
\newcount\endsubline@num
\newif\ifnoteschanged@
\newcommand*{\resetprevline@}{%
    \renewcommand{\do}[1]{\global\csundef{prevline##1}}%
    \dolistloop{\@series}%
}
\newread\@inputcheck
\newcommand*{\read@linelist}[1]{%
  \list@clearing@reg
  \get@linelistfile{#1}%
  \endgroup

  \global\page@num=\m@ne
  \ifx\actionlines@list\empty
      \gdef\next@actionline{1000000}%
  \else
      \gl@p\actionlines@list\to\next@actionline
      \gl@p\actions@list\to\next@action
  \fi}

\newcommand*{\list@clearing@reg}{%
  \list@clear{\line@list}%
  \list@clear{\insertlines@list}%
  \list@clear{\actionlines@list}%
  \list@clear{\actions@list}}
\newcommand*{\get@linelistfile}[1]{%
  \InputIfFileExists{#1}{%
    \global\noteschanged@false
    \begingroup
      \catcode`\[=1 \catcode`\]=2
      \makeatletter \catcode`\^^M=9}{%
    \led@warn@NoLineFile{#1}%
    \global\noteschanged@true
    \begingroup}%
}

\newcommand{\@l}[2]{%
  \fix@page{#1}%
  \@l@reg}
\newcommand*{\@l@reg}{%
  \ifx\l@dchset@num\relax \else
    \advance\absline@num \@ne
    \set@line@action
    \let\l@dchset@num=\relax
    \advance\absline@num \m@ne
    \advance\line@num \m@ne
  \fi
  \advance\absline@num \@ne
         \ifx\next@page@num\relax \else
             \page@action
             \let\next@page@num=\relax
         \fi
         \ifx\sub@change\relax \else
            \ifnum\sub@change>\z@
               \sublines@true
            \else
               \sublines@false
            \fi
            \sub@action
            \let\sub@change=\relax
         \fi
         \ifcase\@lock
            \or
               \@lock \tw@
            \or \or
               \@lock \z@
         \fi
         \ifcase\sub@lock
            \or
               \sub@lock \tw@
            \or \or
               \sub@lock \z@
         \fi
         \ifsublines@
              \ifnum\sub@lock<\tw@
                \advance\subline@num \@ne
              \fi
         \else
              \ifnum\@lock<\tw@
                \advance\line@num \@ne \subline@num \z@
              \fi
         \fi}

\newcommand*{\@page}[1]{%
  \ifbypage@
    \line@num \z@ \subline@num \z@
  \fi
  \page@num=#1\relax
  \def\next@page@num{#1}}

\newcount\last@page@num
  \last@page@num=-10000
\newcommand*{\fix@page}[1]{%
  \ifnum #1=\last@page@num
  \else
    \ifbypage@
      \line@num=\z@ \subline@num=\z@
    \fi
    \page@num=#1\relax
    \last@page@num=#1\relax
    \def\next@page@num{#1}%
  \fi}

\newcommand*{\@pend}[1]{}
\newcommand*{\@pendR}[1]{}
\newcommand*{\@lopL}[1]{}
\newcommand*{\@lopR}[1]{}

\newcommand*{\sub@on}{\ifsublines@
     \let\sub@change=\relax
  \else
     \def\sub@change{1}%
  \fi}
\newcommand*{\sub@off}{\ifsublines@
     \def\sub@change{-1}%
  \else
     \let\sub@change=\relax
  \fi}

\newcommand*{\@adv}[1]{\ifsublines@
       \advance\subline@num by #1\relax
       \ifnum\subline@num<\z@
         \led@warn@BadAdvancelineSubline
          \subline@num \z@
       \fi
  \else
       \advance\line@num by #1\relax
       \ifnum\line@num<\z@
         \led@warn@BadAdvancelineLine
          \line@num \z@
       \fi
  \fi
  \set@line@action}

\newcommand*{\@set}[1]{\ifsublines@
    \subline@num=#1\relax
  \else
    \line@num=#1\relax
  \fi
  \set@line@action}

\newcommand*{\l@d@set}[1]{%
  \line@num=#1\relax
  \advance\line@num \@ne
  \def\l@dchset@num{#1}}
\let\l@dchset@num\relax


\newcommand*{\page@action}{%
  \xright@appenditem{\the\absline@num}\to\actionlines@list
  \xright@appenditem{\next@page@num}\to\actions@list}
\newcommand*{\set@line@action}{%
  \xright@appenditem{\the\absline@num}\to\actionlines@list
  \ifsublines@
       \@l@dtempcnta=-\subline@num
  \else
       \@l@dtempcnta=-\line@num
  \fi
  \advance\@l@dtempcnta by -5000
  \xright@appenditem{\the\@l@dtempcnta}\to\actions@list}
\newcommand*{\sub@action}{%
  \xright@appenditem{\the\absline@num}\to\actionlines@list
  \ifsublines@
      \xright@appenditem{-1001}\to\actions@list
  \else
      \xright@appenditem{-1002}\to\actions@list
  \fi}
\newcommand*{\lock@on}{\futurelet\next\do@lockon}
\newcommand*{\do@lockon}{%
  \ifx\next\lock@off
    \global\let\lock@off=\skip@lockoff
  \else
    \do@lockonL
  \fi}
\newcommand*{\do@lockonL}{%
  \xright@appenditem{\the\absline@num}\to\actionlines@list
  \ifsublines@
    \xright@appenditem{-1005}\to\actions@list
    \ifnum\sub@lock=\z@
      \sub@lock \@ne
    \else
      \ifnum\sub@lock=\thr@@
        \sub@lock \@ne
      \fi
    \fi
  \else
    \xright@appenditem{-1003}\to\actions@list
    \ifnum\@lock=\z@
      \@lock \@ne
    \else
      \ifnum\@lock=\thr@@
        \@lock \@ne
      \fi
    \fi
  \fi}

\newcommand*{\do@lockoffL}{%
  \xright@appenditem{\the\absline@num}\to\actionlines@list
  \ifsublines@
    \xright@appenditem{-1006}\to\actions@list
    \ifnum\sub@lock=\tw@
      \sub@lock \thr@@
    \else
      \sub@lock \z@
    \fi
  \else
    \xright@appenditem{-1004}\to\actions@list
    \ifnum\@lock=\tw@
      \@lock \thr@@
    \else
      \@lock \z@
    \fi
  \fi}
\newcommand*{\do@lockoff}{\do@lockoffL}
\newcommand*{\skip@lockoff}{\global\let\lock@off=\do@lockoff}
\global\let\lock@off=\do@lockoff

\newcommand*{\n@num}{\n@num@reg}
\newcommand*{\n@num@reg}{%
  \xright@appenditem{\the\absline@num}\to\actionlines@list
  \xright@appenditem{-1007}\to\actions@list}

\newcount\insert@count
\newcommand*{\dummy@ref}[2]{#2}
\newcommand*{\@ref}[2]{%
  \@ref@reg{#1}{#2}}
\newcommand*{\@ref@reg}[2]{%
  \global\insert@count=#1\relax
  \loop\ifnum\insert@count>\z@
    \xright@appenditem{\the\absline@num}\to\insertlines@list
    \global\advance\insert@count \m@ne
  \repeat
  \begingroup
    \let\@ref=\dummy@ref
    \let\page@action=\relax
    \let\sub@action=\relax
    \let\set@line@action=\relax
    \let\@lab=\relax
    #2
    \global\endpage@num=\page@num
    \global\endline@num=\line@num
    \global\endsubline@num=\subline@num
  \endgroup
    \xright@appenditem%
      {\the\page@num|\the\line@num|%
       \ifsublines@ \the\subline@num \else 0\fi|%
       \the\endpage@num|\the\endline@num|%
       \ifsublines@ \the\endsubline@num \else 0\fi}\to\line@list
  #2}

\newwrite\linenum@out
\newif\iffirst@linenum@out@
  \first@linenum@out@true
\newcommand*{\line@list@stuff}[1]{%
  \read@linelist{#1}%
  \iffirst@linenum@out@
     \immediate\closeout\linenum@out
     \global\first@linenum@out@false
     \immediate\openout\linenum@out=#1\relax
  \else
     \closeout\linenum@out
     \openout\linenum@out=#1\relax
  \fi}

\newcommand*{\new@line}{\write\linenum@out{\string\@l[\the\c@page][\thepage]}}
\newcommand*{\flag@start}{%
  \edef\next{\write\linenum@out{%
                  \string\@ref[\the\insert@count][}}%
  \next}
\newcommand*{\flag@end}{\write\linenum@out{]}}
\newcommand*{\page@start}{}

\newcommand*{\startsub}{\dimen0\lastskip
  \ifdim\dimen0>0pt \unskip \fi
  \write\linenum@out{\string\sub@on}%
  \ifdim\dimen0>0pt \hskip\dimen0 \fi}
\def\endsub{\dimen0\lastskip
  \ifdim\dimen0>0pt \unskip \fi
  \write\linenum@out{\string\sub@off}%
  \ifdim\dimen0>0pt \hskip\dimen0 \fi}

\newcommand*{\advanceline}[1]{\write\linenum@out{\string\@adv[#1]}}
\newcommand*{\setline}[1]{%
  \ifnum#1<\z@
    \led@warn@BadSetline
  \else
    \write\linenum@out{\string\@set[#1]}%
  \fi}

\newcommand*{\setlinenum}[1]{%
  \ifnum#1<\z@
    \led@warn@BadSetlinenum
  \else
    \write\linenum@out{\string\l@d@set[#1]}%
  \fi}

\newcommand*{\startlock}{\write\linenum@out{\string\lock@on}}
\def\endlock{\write\linenum@out{\string\lock@off}}

\newif\ifl@dskipnumber
  \l@dskipnumberfalse
\newcommand*{\skipnumbering}{\skipnumbering@reg}
\newcommand*{\skipnumbering@reg}{%
  \write\linenum@out{\string\n@num}%
  \advanceline{-1}}

\list@create{\end@lemmas}
\long\def\dummy@text#1#2/{#1}
\newcommand{\dummy@edtext}[2]{#1}
\newcommand*{\no@expands}{%
  \let\select@@lemmafont=0%
  \let\startsub=\relax  \let\endsub=\relax
  \let\startlock=\relax \let\endlock=\relax
  \let\edlabel=\@gobble
  \let\setline=\@gobble \let\advanceline=\@gobble
  \let\critext=\dummy@text
  \let\edtext=\dummy@edtext
  \l@dtabnoexpands
  \morenoexpands}
\let\morenoexpands=\relax

\newcommand{\@tag}{}
\long\def\critext#1#2/{\leavevmode
  \begingroup
    \global\renewcommand{\@tag}{\no@expands #1}%%
    \set@line
    \global\insert@count=0
    \ignorespaces #2\relax
    \flag@start
  \endgroup
  \showlemma{#1}%
  \ifx\end@lemmas\empty \else
    \gl@p\end@lemmas\to\x@lemma
    \x@lemma
    \global\let\x@lemma=\relax
  \fi
  \flag@end}
\newcommand{\edtext}[2]{\leavevmode
  \begingroup
    \global\renewcommand{\@tag}{\no@expands #1}%%
    \set@line
    \global\insert@count=0
    \ignorespaces #2\relax
    \flag@start
  \endgroup
  \showlemma{#1}%
  \ifx\end@lemmas\empty \else
    \gl@p\end@lemmas\to\x@lemma
    \x@lemma
    \global\let\x@lemma=\relax
  \fi
  \flag@end}

\newif\ifnumberline
\numberlinetrue
\newcommand*{\set@line}{%
  \ifx\line@list\empty
    \global\noteschanged@true
    \xdef\l@d@nums{000|000|000|000|000|000|\edfont@info}%
 \else
   \gl@p\line@list\to\@tempb
   \xdef\l@d@nums{\@tempb|\edfont@info}%
   \global\let\@tempb=\undefined
 \fi}

\newcommand*{\edfont@info}{\f@encoding/\f@family/\f@series/\f@shape}

\newcommand*{\lemma}[1]{\global\renewcommand{\@tag}{\no@expands #1}}
\newcommand*{\linenum}[1]{%
  \xdef\@tempa{#1|||||||\noexpand\\\l@d@nums}%
  \global\let\l@d@nums=\empty
  \expandafter\line@set\@tempa|\\\ignorespaces}
\def\line@set#1|#2\\#3|#4\\{%
  \gdef\@tempb{#1}%
  \ifx\@tempb\empty
        \l@d@add{#3}%
  \else
        \l@d@add{#1}%
  \fi
  \gdef\@tempb{#4}%
  \ifx\@tempb\empty\else
      \l@d@add{|}\line@set#2\\#4\\%
  \fi}
\newcommand{\l@d@add}[1]{\xdef\l@d@nums{\l@d@nums#1}}

\newbox\raw@text
\newif\ifnumberedpar@
\newcount\num@lines
\newbox\one@line
\newcount\par@line

\newcounter{pstart}
\renewcommand{\thepstart}{{\bfseries\@arabic\c@pstart}. }
\newif\ifnumberpstart
\numberpstartfalse
\newcommand*{\pstart}{
\if@nobreak
\let\@oldnobreak\@nobreaktrue
\else
\let\@oldnobreak\@nobreakfalse
\fi
\@nobreaktrue
\ifnumbering \else
    \led@err@PstartNotNumbered
    \beginnumbering
  \fi
  \ifnumberedpar@
    \led@err@PstartInPstart
    \pend
  \fi
  \list@clear{\inserts@list}%
  \global\let\next@insert=\empty
  \begingroup\normal@pars
  \global\setbox\raw@text=\vbox\bgroup\ifautopar\else\ifnumberpstart\ifinstanza\else\ifsidepstartnum\else\thepstart\fi\fi\fi\fi
  \numberedpar@true}
\newcommand*{\pend}{\ifnumbering \else
    \led@err@PendNotNumbered
  \fi
  \ifnumberedpar@ \else
    \led@err@PendNoPstart
  \fi
  \l@dzeropenalties
  \endgraf\global\num@lines=\prevgraf\egroup
  \global\par@line=0
  \csnumdef{pstartline}{0}
  \loop\ifvbox\raw@text
    \csnumdef{pstartline}{\pstartline+1}%
    \do@line
    \ifbypstart@%
     \ifnumequal{\pstartline}{1}{\setline{1}\resetprevline@}{}%
    \fi
  \repeat
  \flush@notes
  \endgroup
  \ignorespaces
  \ifnumberpstart
   \pstartnumtrue
   \fi
  \@oldnobreak
  \addtocounter{pstart}{1}}

\newcommand*{\l@dzeropenalties}{%
  \brokenpenalty \z@ \clubpenalty \z@
  \displaywidowpenalty \z@ \interlinepenalty \z@ \predisplaypenalty \z@
  \postdisplaypenalty \z@ \widowpenalty \z@}

\newif\ifautopar
\autoparfalse
\newcommand*{\autopar}{
  \ifledRcol
    \ifnumberingR \else
    \led@err@AutoparNotNumbered
    \beginnumberingR
    \fi
    \else
    \ifnumbering \else
    \led@err@AutoparNotNumbered
    \beginnumbering
    \fi
  \fi
  \autopartrue
  \everypar={\setbox0=\lastbox
    \endgraf \vskip-\parskip
    \pstart \noindent \kern\wd0 \ifnumberpstart\ifinstanza\else\thepstart\fi\fi
    \let\par=\pend}%
  \ignorespaces}
\newcommand*{\normal@pars}{\everypar={}\let\par\endgraf}

 \newcommand*{\l@dunhbox@line}[1]{\unhbox #1}
 \newcommand*{\do@line}{%
  {\vbadness=10000
   \splittopskip=\z@
   \do@linehook
\l@demptyd@ta
   \global\setbox\one@line=\vsplit\raw@text to\baselineskip}%
  \unvbox\one@line \global\setbox\one@line=\lastbox
  \getline@num
  \ifnum\@lock>\@ne
    \inserthangingsymboltrue
  \else
    \inserthangingsymbolfalse
  \fi
  \affixline@num
  \affixpstart@num
  \hb@xt@ \linewidth{\inserthangingsymbol\l@dld@ta\add@inserts\affixside@note
    \l@dlsn@te
    {\ledllfill\hb@xt@ \wd\one@line{\new@line\l@dunhbox@line{\one@line}}\ledrlfill\l@drd@ta%
    \l@drsn@te
  }}}%
\newcommand*{\do@linehook}{}
\newcommand*{\l@demptyd@ta}{%
  \gdef\l@dld@ta{}%
  \gdef\l@drd@ta{}%
  \gdef\l@dcsnotetext{}}

\newcommand{\l@dlsn@te}{%
  \hb@xt@ \z@{\hss\box\l@dlp@rbox\kern\ledlsnotesep}}
\newcommand{\l@drsn@te}{%
   \hb@xt@ \z@{\kern\ledrsnotesep\box\l@drp@rbox\hss}}

\newcommand*{\ledllfill}{\hfil}
\newcommand*{\ledrlfill}{}

\newcommand*{\getline@num}{%
     \global\advance\absline@num \@ne
  \do@actions
  \do@ballast
  \ifnumberline
  \ifsublines@
     \ifnum\sub@lock<\tw@
       \global\advance\subline@num \@ne
     \fi
  \else
     \ifnum\@lock<\tw@
       \global\advance\line@num \@ne
       \global\subline@num \z@
     \fi
  \fi
  \fi
  }
\newcount\ballast@count
\newcounter{ballast}
  \setcounter{ballast}{0}
\newcommand*{\do@ballast}{\global\ballast@count \z@
  \begingroup
    \advance\absline@num \@ne
    \ifnum\next@actionline=\absline@num
      \ifnum\next@action>-1001\relax
        \global\advance\ballast@count by -\c@ballast
       \fi
     \fi
  \endgroup}
\newcommand*{\do@actions}{%
  \global\let\do@actions@next=\relax
  \ifnum\absline@num<\next@actionline\else
    \ifnum\next@action>-1001
       \global\page@num=\next@action
       \ifbypage@
         \global\line@num=\z@ \global\subline@num=\z@
         \resetprevline@
       \fi
    \else
       \ifnum\next@action<-4999
          \@l@dtempcnta=-\next@action
          \advance\@l@dtempcnta by -5001
          \ifsublines@
             \global\subline@num=\@l@dtempcnta
          \else
             \global\line@num=\@l@dtempcnta
          \fi
       \else
          \@l@dtempcnta=-\next@action
          \advance\@l@dtempcnta by -1000
          \do@actions@fixedcode
       \fi
    \fi
    \ifx\actionlines@list\empty
         \gdef\next@actionline{1000000}%
    \else
         \gl@p\actionlines@list\to\next@actionline
         \gl@p\actions@list\to\next@action
         \global\let\do@actions@next=\do@actions
    \fi
  \fi
\do@actions@next}

\newcommand*{\do@actions@fixedcode}{%
  \ifcase\@l@dtempcnta
  \or%                   % 1001
    \global\sublines@true
  \or%                   % 1002
    \global\sublines@false
  \or%                   % 1003
      \global\@lock=\@ne
  \or%                   % 1004
    \ifnum\@lock=\tw@
      \global\@lock=\thr@@
    \else
      \global\@lock=\z@
    \fi
  \or%                   % 1005
     \global\sub@lock=\@ne
  \or%                   % 1006
    \ifnum\sub@lock=\tw@
      \global\sub@lock=\thr@@
    \else
      \global\sub@lock=\z@
    \fi
  \or%                   % 1007
    \l@dskipnumbertrue
  \else
    \led@warn@BadAction
  \fi}

\newcommand*{\affixline@num}{%
\ifnumberline
\ifl@dskipnumber
  \global\l@dskipnumberfalse
\else
  \ifsublines@
    \@l@dtempcntb=\subline@num
    \ifnum\subline@num>\c@firstsublinenum
      \@l@dtempcnta=\subline@num
      \advance\@l@dtempcnta by-\c@firstsublinenum
      \divide\@l@dtempcnta by\c@sublinenumincrement
      \multiply\@l@dtempcnta by\c@sublinenumincrement
      \advance\@l@dtempcnta by\c@firstsublinenum
    \else
      \@l@dtempcnta=\c@firstsublinenum
    \fi
    \ch@cksub@l@ck
  \else
    \@l@dtempcntb=\line@num
    \ifx\linenumberlist\empty
      \ifnum\line@num>\c@firstlinenum
         \@l@dtempcnta=\line@num
         \advance\@l@dtempcnta by-\c@firstlinenum
         \divide\@l@dtempcnta by\c@linenumincrement
         \multiply\@l@dtempcnta by\c@linenumincrement
         \advance\@l@dtempcnta by\c@firstlinenum
      \else
         \@l@dtempcnta=\c@firstlinenum
      \fi
    \else
      \@l@dtempcnta=\line@num
      \edef\rem@inder{,\linenumberlist,\number\line@num,}%
        \edef\sc@n@list{\def\noexpand\sc@n@list
        ####1,\number\@l@dtempcnta,####2|{\def\noexpand\rem@inder{####2}}}%
        \sc@n@list\expandafter\sc@n@list\rem@inder|%
          \ifx\rem@inder\empty\advance\@l@dtempcnta\@ne\fi
    \fi
    \ch@ck@l@ck
  \fi
  \ifnum\@l@dtempcnta=\@l@dtempcntb
 \if@twocolumn
    \if@firstcolumn
      \gdef\l@dld@ta{\llap{{\leftlinenum}}}%
    \else
      \gdef\l@drd@ta{\rlap{{\rightlinenum}}}%
    \fi
 \else
    \@l@dtempcntb=\line@margin
    \ifnum\@l@dtempcntb>\@ne
      \advance\@l@dtempcntb \page@num
    \fi
    \ifodd\@l@dtempcntb
      \gdef\l@drd@ta{\rlap{{\rightlinenum}}}%
    \else
      \gdef\l@dld@ta{\llap{{\leftlinenum}}}%
    \fi
 \fi
  \else
%%    #1%
  \fi
  \f@x@l@cks
\fi
\fi
}

\newcommand*{\ch@cksub@l@ck}{%
    \ifcase\sub@lock
      \or
        \ifnum\sublock@disp=\@ne
           \@l@dtempcntb=\z@ \@l@dtempcnta=\@ne
        \fi
      \or
        \ifnum\sublock@disp=\tw@ \else
           \@l@dtempcntb=\z@ \@l@dtempcnta=\@ne
        \fi
      \or
        \ifnum\sublock@disp=\z@
           \@l@dtempcntb=\z@ \@l@dtempcnta=\@ne
        \fi
    \fi}
\newcommand*{\ch@ck@l@ck}{%
    \ifcase\@lock
       \or
         \ifnum\lock@disp=\@ne
            \@l@dtempcntb=\z@ \@l@dtempcnta=\@ne
         \fi
       \or
         \ifnum\lock@disp=\tw@ \else
            \@l@dtempcntb=\z@ \@l@dtempcnta=\@ne
         \fi
       \or
         \ifnum\lock@disp=\z@
            \@l@dtempcntb=\z@ \@l@dtempcnta=\@ne
         \fi
    \fi}
\newcommand*{\f@x@l@cks}{%
  \ifcase\@lock
  \or
    \global\@lock=\tw@
  \or \or
    \global\@lock=\z@
  \fi
  \ifcase\sub@lock
  \or
    \global\sub@lock=\tw@
  \or \or
    \global\sub@lock=\z@
  \fi}

\newcommand{\pageparbreak}{\pend\newpage\pstart\noindent}


\newif\ifsidepstartnum
\newcommand*{\affixpstart@num}{%
    \ifsidepstartnum
        \if@twocolumn
            \if@firstcolumn
                  \gdef\l@dld@ta{\llap{{\leftpstartnum}}}%
            \else
                  \gdef\l@drd@ta{\rlap{{\rightpstartnum}}}%
            \fi
        \else
             \@l@dtempcntb=\line@margin
            \ifnum\@l@dtempcntb>\@ne
                  \advance\@l@dtempcntb \page@num
            \fi
            \ifodd\@l@dtempcntb
                  \gdef\l@drd@ta{\rlap{{\rightpstartnum}}}%
            \else
                  \gdef\l@dld@ta{\llap{{\leftpstartnum}}}%
            \fi
        \fi
    \fi

}

\newif\ifpstartnum
\pstartnumtrue
\newcommand*{\leftpstartnum}{
    \ifpstartnum\thepstart
    \kern\linenumsep\fi
    \global\pstartnumfalse
}
\newcommand*{\rightpstartnum}{
    \ifpstartnum
    \kern\linenumsep
    \thepstart
    \fi
    \global\pstartnumfalse
}
\list@create{\inserts@list}
\newcommand*{\add@inserts}{%
  \global\let\add@inserts@next=\relax
  \ifx\inserts@list\empty \else
  \ifx\next@insert\empty
    \ifx\insertlines@list\empty
      \global\noteschanged@true
      \gdef\next@insert{100000}%
    \else
      \gl@p\insertlines@list\to\next@insert
    \fi
  \fi
  \ifnum\next@insert=\absline@num
    \gl@p\inserts@list\to\@insert
    \@insert
    \global\let\@insert=\undefined
    \global\let\next@insert=\empty
    \global\let\add@inserts@next=\add@inserts
  \fi
\fi
\add@inserts@next}

\newcommand*{\add@penalties}{\@l@dtempcnta=\ballast@count
  \ifnum\num@lines>\@ne
    \global\advance\par@line \@ne
    \ifnum\par@line=\@ne
      \advance\@l@dtempcnta \clubpenalty
    \fi
    \@l@dtempcntb=\par@line \advance\@l@dtempcntb \@ne
    \ifnum\@l@dtempcntb=\num@lines
      \advance\@l@dtempcnta \widowpenalty
    \fi
    \ifnum\par@line<\num@lines
      \advance\@l@dtempcnta \interlinepenalty
    \fi
  \fi
    \ifnum\@l@dtempcnta=\z@
      \relax
    \else
      \ifnum\@l@dtempcnta>-10000
        \penalty\@l@dtempcnta
      \else
        \penalty -10000
      \fi
    \fi}

\newcommand*{\flush@notes}{%
  \@xloop
    \ifx\inserts@list\empty \else
      \gl@p\inserts@list\to\@insert
      \@insert
      \global\let\@insert=\undefined
  \repeat}

\def\@xloop#1\repeat{%
  \def\body{#1\expandafter\body\fi}%
  \body}

  \def\select@lemmafont#1|#2|#3|#4|#5|#6|#7|{\select@@lemmafont#7|}
  \def\select@@lemmafont#1/#2/#3/#4|%
    {\fontencoding{#1}\fontfamily{#2}\fontseries{#3}\fontshape{#4}%
    \selectfont}

\newcommandx*{\footnoteoptions@}[3][1=L,usedefault]{%
   \renewcommand{\do}[1]{%
      \ifstrequal{#1}{L}{% In Leftside
         \xright@appenditem{\global\noexpand\settoggle{##1@}{#3}}\to\inserts@list% Switch toogle, in all case
         \global\advance\insert@count \@ne% Increment the left insert counter.
      }%
      {%
          \xright@appenditem{\global\noexpand\settoggle{##1@}{#3}}\to\inserts@listR% Switch toogle, in all case
          \global\advance\insert@countR \@ne% Increment the right insert counter insert.
      }%
   }%
   \notblank{#2}{\docsvlist{#2}}{}% Parsing all options
}
\newcommand*{\normalvfootnote}[2]{%
  \insert\csname #1footins\endcsname\bgroup
  \csuse{Xnotefontsize@#1}
  \footsplitskips
  \spaceskip=\z@skip \xspaceskip=\z@skip
  \csname #1footfmt\endcsname #2[#1]\egroup}
\newcommand*{\footsplitskips}{%
  \interlinepenalty=\interfootnotelinepenalty
  \floatingpenalty=\@MM
  \splittopskip=\ht\strutbox \splitmaxdepth=\dp\strutbox
  \leftskip=\z@skip \rightskip=\z@skip}

\newcommand*{\mpnormalvfootnote}[2]{%
  \global\setbox\@nameuse{mp#1footins}\vbox{%
    \unvbox\@nameuse{mp#1footins}
    \csuse{Xnotefontsize@#1}
    \hsize\columnwidth
    \@parboxrestore
    \color@begingroup
    \csname #1footfmt\endcsname #2[#1]\color@endgroup}}

\newcommand*{\ledsetnormalparstuff}{%
  \normal@pars
  \parindent \z@ \parfillskip \z@ \@plus 1fil}
\newcommandx*{\normalfootfmt}[4][4=Z]{% 4th arg is optional, for backward compatibility
  \ledsetnormalparstuff%
  \hangindent=\csuse{Xhangindent@#4}
  \strut{\printlinefootnote{#1}{#4}}%
  {\select@lemmafont#1|#2}%
  \iftoggle{nosep@}{\hskip\csuse{inplaceoflemmaseparator@#4}}{\ifcsempty{lemmaseparator@#4}%
    {\hskip\csuse{inplaceoflemmaseparator@#4}}%
    {\nobreak\hskip\csuse{beforelemmaseparator@#4}\csuse{lemmaseparator@#4}\hskip\csuse{afterlemmaseparator@#4}%
  }}%
  #3\strut\par}
\def\endashchar{\textnormal{--}}
\newcommand*{\fullstop}{\textnormal{.}}
\newcommand*{\rbracket}{\textnormal{\thinspace]}}

\newif\ifl@d@pnum
  \l@d@pnumfalse
\newif\ifl@d@ssub
  \l@d@ssubfalse
\newif\ifl@d@elin
  \l@d@elinfalse
\newif\ifl@d@esl
  \l@d@eslfalse
\newif\ifl@d@dash
  \l@d@dashfalse
\newcommand*{\l@dparsefootspec}[3]{\l@dp@rsefootspec#1|}
\def\l@dp@rsefootspec#1|#2|#3|#4|#5|#6|#7|{%
  \gdef\l@dparsedstartpage{#1}%
  \gdef\l@dparsedstartline{#2}%
  \gdef\l@dparsedstartsub{#3}%
  \gdef\l@dparsedendpage{#4}%
  \gdef\l@dparsedendline{#5}%
  \gdef\l@dparsedendsub{#6}%
}
\def\l@dparsedstartpage{0}%
\def\l@dparsedstartline{0}%
\def\l@dparsedstartsub{0}%
\def\l@dparsedendpage{0}%
\def\l@dparsedendline{0}%
\def\l@dparsedendsub{0}%

\newcommand*{\setprintlines}[6]{%
  \l@d@pnumfalse \l@d@dashfalse
  \ifbypage@
     \ifnum#4=#1 \else
        \l@d@pnumtrue
        \l@d@dashtrue
     \fi
  \fi
  \ifl@d@pnum \l@d@elintrue \else \l@d@elinfalse \fi
  \ifnum#2=#5 \else
      \l@d@elintrue
      \l@d@dashtrue
  \fi
  \l@d@ssubfalse
  \ifnum#3=0 \else
      \l@d@ssubtrue
  \fi
  \l@d@eslfalse
  \ifnum#6=0 \else
      \ifnum#6=#3
         \ifl@d@elin \l@d@esltrue \else \l@d@eslfalse \fi
      \else
         \l@d@esltrue
         \l@d@dashtrue
      \fi
  \fi}
\def\printlines#1|#2|#3|#4|#5|#6|#7|{\begingroup
    \ifbypstart@%
    \ifl@dpairing%
        \ifledRcol%
            \thepstartR%
         \else%
            \thepstartL%
         \fi%
    \else%
        \thepstart%
    \fi%
  \fi%
  \setprintlines{#1}{#2}{#3}{#4}{#5}{#6}%
  \ifl@d@pnum #1\fullstop\fi
  \linenumrep{#2}
  \ifl@d@ssub \fullstop \sublinenumrep{#3}\fi
  \ifl@d@dash \endashchar\fi
  \ifl@d@pnum #4\fullstop\fi
  \ifl@d@elin \linenumrep{#5}\fi
  \ifl@d@esl \ifl@d@elin \fullstop\fi \sublinenumrep{#6}\fi
\endgroup}
\newcommand*{\normalfootstart}[1]{%
  \vskip\skip\csname #1footins\endcsname
  \leftskip0pt \rightskip0pt
  \csname #1footnoterule\endcsname}
\let\normalfootnoterule=\footnoterule
\newcommand*{\normalfootgroup}[1]{\unvbox\csname #1footins\endcsname}

\newcommand*{\mpnormalfootgroup}[1]{{
  \vskip\skip\@nameuse{mp#1footins}
  \normalcolor
  \@nameuse{#1footnoterule}
  \unvbox\csname mp#1footins\endcsname}}

\newcommand*{\ledfootinsdim}{0.8\vsize}

\newcommand*{\footnormal}[1]{%
  \expandafter\let\csname #1footstart\endcsname=\normalfootstart
  \expandafter\let\csname v#1footnote\endcsname=\normalvfootnote
  \expandafter\let\csname #1footfmt\endcsname=\normalfootfmt
  \expandafter\let\csname #1footgroup\endcsname=\normalfootgroup
  \expandafter\let\csname #1footnoterule\endcsname=%
                                             \normalfootnoterule
  \count\csname #1footins\endcsname=1000
  \dimen\csname #1footins\endcsname=\ledfootinsdim
  \skip\csname #1footins\endcsname=1.2em \@plus .6em \@minus .6em
  \expandafter\let\csname mpv#1footnote\endcsname=\mpnormalvfootnote
  \expandafter\let\csname mp#1footgroup\endcsname=\mpnormalfootgroup
  \count\csname mp#1footins\endcsname=1000
  \dimen\csname mp#1footins\endcsname=\ledfootinsdim
  \skip\csname mp#1footins\endcsname=1.2em \@plus .6em \@minus .6em
}

\newcommand*{\footparagraph}[1]{%
  \expandafter\newcount\csname prevpage#1@num\endcsname
  \expandafter\let\csname #1footstart\endcsname=\parafootstart
  \expandafter\let\csname v#1footnote\endcsname=\para@vfootnote
  \expandafter\let\csname #1footfmt\endcsname=\parafootfmt
  \expandafter\let\csname #1footgroup\endcsname=\para@footgroup
  \count\csname #1footins\endcsname=1000
  \para@footsetup{#1}
  \expandafter\let\csname mpv#1footnote\endcsname=\mppara@vfootnote
  \expandafter\let\csname mp#1footgroup\endcsname=\mppara@footgroup
  \count\csname mp#1footins\endcsname=1000
}
\providecommand{\footfudgefiddle}{64}
\newcommand*{\para@footsetup}[1]{{\csuse{Xnotefontsize@#1}
  \dimen0=\baselineskip
  \multiply\dimen0 by 1024
  \divide \dimen0 by \columnwidth \multiply\dimen0 by \footfudgefiddle\relax
  \expandafter
  \xdef\csname #1footfudgefactor\endcsname{%
    \expandafter\strip@pt\dimen0 }}}

\newcommand*{\parafootstart}[1]{%
  \rightskip=0pt \leftskip=0pt \parindent=0pt
  \vskip\skip\csname #1footins\endcsname
  \csname #1footnoterule\endcsname}
\newcommand*{\para@vfootnote}[2]{%
  \insert\csname #1footins\endcsname
  \bgroup
    \csuse{Xnotefontsize@#1}
    \footsplitskips
    \setbox0=\vbox{\hsize=\maxdimen
      \noindent\csname #1footfmt\endcsname#2[#1]}%
    \setbox0=\hbox{\unvxh0[#1]}%
    \dp0=0pt
    \ht0=\csname #1footfudgefactor\endcsname\wd0
    \box0
    \penalty0
  \egroup}

\newcommand*{\mppara@vfootnote}[2]{%
  \global\setbox\@nameuse{mp#1footins}\vbox{%
    \unvbox\@nameuse{mp#1footins}%
    \csuse{Xnotefontsize@#1}
    \footsplitskips
    \setbox0=\vbox{\hsize=\maxdimen
      \noindent\color@begingroup\csname #1footfmt\endcsname #2[#1]\color@endgroup}%
    \setbox0=\hbox{\unvxh0[#1]}%
    \dp0=\z@
    \ht0=\csname #1footfudgefactor\endcsname\wd0
    \box0
    \penalty0
}}

\newcommandx*{\unvxh}[2][2=Z]{% 2th is optional for retro-compatibility
  \setbox0=\vbox{\unvbox#1%
    \global\setbox1=\lastbox}%
  \unhbox1
  \unskip            % remove \rightskip,
  \unskip            % remove \parfillskip,
  \unpenalty         % remove \penalty of 10000,
  \hskip\csuse{afternote@#2}}   % but add the glue to go between the notes

\newcommandx*{\parafootfmt}[4][4=Z]{%
  \insertparafootsep{#4}%
  \ledsetnormalparstuff%
  \printlinefootnote{#1}{#4}%
  {\select@lemmafont#1|#2}%
  \iftoggle{nosep@}{\hskip\csuse{inplaceoflemmaseparator@#4}}{\ifcsempty{lemmaseparator@#4}%
    {\hskip\csuse{inplaceoflemmaseparator@#4}}%
    {\nobreak\hskip\csuse{beforelemmaseparator@#4}\csuse{lemmaseparator@#4}\hskip\csuse{afterlemmaseparator@#4}%
  }}%
  #3\penalty-10 }
\newcommand*{\para@footgroup}[1]{%
  \unvbox\csname #1footins\endcsname
  \makehboxofhboxes
  \setbox0=\hbox{\unhbox0 \removehboxes}%
  \csuse{Xnotefontsize@#1}
  \noindent\unhbox0\par}

\newcommand*{\mppara@footgroup}[1]{{%
  \vskip\skip\@nameuse{mp#1footins}
  \normalcolor
  \@nameuse{#1footnoterule}%
  \unvbox\csname mp#1footins\endcsname
  \makehboxofhboxes
  \setbox0=\hbox{\unhbox0 \removehboxes}%
  \csuse{Xnotefontsize@#1}
  \noindent\unhbox0\par}}

\newcommand*{\makehboxofhboxes}{\setbox0=\hbox{}%
  \loop
    \unpenalty
    \setbox2=\lastbox
  \ifhbox2
    \setbox0=\hbox{\box2\unhbox0}%
  \repeat}

\newcommand*{\removehboxes}{\setbox0=\lastbox
  \ifhbox0{\removehboxes}\unhbox0 \fi}

\newcommand{\insertparafootsep}[1]{%
   \ifnumequal{\csuse{prevpage#1@num}}{\page@num}%
        {\ifcsdef{prevline#1}% Be sur \prevline#1 exists.
      {\ifnumequal{\csuse{prevline#1}}{\line@num}%
         {\ifcsempty{symplinenum}{\csuse{parafootsep@#1}}{}}%
         {\csuse{parafootsep@#1}}%
      }%
      {\csuse{parafootsep@#1}}%
   }%
   {}%
   \global\csname prevpage#1@num\endcsname=\page@num%
}
\newcount\@k \newdimen\@h
\newcommand*{\rigidbalance}[3]{\setbox0=\box#1 \@k=#2 \@h=#3
  \@@line{\splittopskip=\@h \vbadness=\@M \hfilneg
  \valign{##\vfil\cr\dosplits}}}

\newcommand*{\dosplits}{\ifnum\@k>0 \noalign{\hfil}\splitoff
  \global\advance\@k-1\cr\dosplits\fi}

\newcommand*{\splitoff}{\dimen0=\ht0
  \divide\dimen0 by\@k \advance\dimen0 by\@h
  \setbox2 \vsplit0 to \dimen0
  \unvbox2 }

\newcommand*{\footthreecol}[1]{%
  \expandafter\let\csname v#1footnote\endcsname=\threecolvfootnote
  \expandafter\let\csname #1footfmt\endcsname=\threecolfootfmt
  \expandafter\let\csname #1footgroup\endcsname=\threecolfootgroup
  \threecolfootsetup{#1}
  \expandafter\let\csname mpv#1footnote\endcsname=\mpnormalvfootnote
  \expandafter\let\csname mp#1footgroup\endcsname=\mpthreecolfootgroup
  \mpthreecolfootsetup{#1}
}

\newcommand*{\threecolfootsetup}[1]{%
  \count\csname #1footins\endcsname 333
  \multiply\dimen\csname #1footins\endcsname \thr@@}
\newcommand*{\mpthreecolfootsetup}[1]{%
  \count\csname mp#1footins\endcsname 333
  \multiply\dimen\csname mp#1footins\endcsname \thr@@}

\newcommand*{\threecolvfootnote}[2]{%
  \insert\csname #1footins\endcsname\bgroup
  \csuse{Xnotefontsize@#1}
  \footsplitskips
  \csname #1footfmt\endcsname #2[#1]\egroup}
\newcommandx*{\threecolfootfmt}[4][4=Z]{%
  \normal@pars
  \hsize \csuse{hsizethreecol@#4}
  \parindent=0pt
  \tolerance=5000
  \raggedright
  \hangindent=\csuse{Xhangindent@#4}
  \leavevmode
  \strut{\printlinefootnote{#1}{#4}}%
  {\select@lemmafont#1|#2}%
  \iftoggle{nosep@}{\hskip\csuse{inplaceoflemmaseparator@#4}}{\ifcsempty{lemmaseparator@#4}%
    {\hskip\csuse{inplaceoflemmaseparator@#4}}%
    {\nobreak\hskip\csuse{beforelemmaseparator@#4}\csuse{lemmaseparator@#4}\hskip\csuse{afterlemmaseparator@#4}%
  }}%
  #3\strut\par\allowbreak}
\newcommand*{\threecolfootgroup}[1]{{\notefontsetup
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname #1footins\endcsname \thr@@ \splittopskip}}
\newcommand*{\mpthreecolfootgroup}[1]{{%
  \vskip\skip\@nameuse{mp#1footins}
  \normalcolor
  \@nameuse{#1footnoterule}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname mp#1footins\endcsname \thr@@ \splittopskip}}

\newcommand*{\foottwocol}[1]{%
  \expandafter\let\csname v#1footnote\endcsname=\twocolvfootnote
  \expandafter\let\csname #1footfmt\endcsname=\twocolfootfmt
  \expandafter\let\csname #1footgroup\endcsname=\twocolfootgroup
  \twocolfootsetup{#1}
  \expandafter\let\csname mpv#1footnote\endcsname=\mpnormalvfootnote
  \expandafter\let\csname mp#1footgroup\endcsname=\mptwocolfootgroup
  \mptwocolfootsetup{#1}
}

\newcommand*{\twocolfootsetup}[1]{%
  \count\csname #1footins\endcsname 500
  \multiply\dimen\csname #1footins\endcsname \tw@}
\newcommand*{\twocolvfootnote}[2]{\insert\csname #1footins\endcsname\bgroup
  \csuse{Xnotefontsize@#1}
  \footsplitskips
  \csname #1footfmt\endcsname #2[#1]\egroup}
\newcommandx*{\twocolfootfmt}[4][4=Z]{% 4th arg is optional, for backward compatibility
  \normal@pars
  \hsize \csuse{hsizetwocol@#4}
  \parindent=0pt
  \tolerance=5000
  \raggedright
  \hangindent=\csuse{Xhangindent@#4}
  \leavevmode
  \strut{\printlinefootnote{#1}{#4}}%
  {\select@lemmafont#1|#2}%
  \iftoggle{nosep@}{\hskip\csuse{inplaceoflemmaseparator@#4}}{\ifcsempty{lemmaseparator@#4}%
    {\hskip\csuse{inplaceoflemmaseparator@#4}}%
    {\nobreak\hskip\csuse{beforelemmaseparator@#4}\csuse{lemmaseparator@#4}\hskip\csuse{afterlemmaseparator@#4}%
  }}%
  #3\strut\par\allowbreak}
\newcommand*{\twocolfootgroup}[1]{{\csuse{Xnotefontsize@#1}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname #1footins\endcsname \tw@ \splittopskip}}

\newcommand*{\mptwocolfootsetup}[1]{%
  \count\csname mp#1footins\endcsname 500
  \multiply\dimen\csname mp#1footins\endcsname \tw@}
\newcommand*{\mptwocolfootgroup}[1]{{%
  \vskip\skip\@nameuse{mp#1footins}
  \normalcolor
  \@nameuse{#1footnoterule}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname mp#1footins\endcsname \tw@ \splittopskip}}

\providecommand*{\multiplefootnotemarker}{3sp}
\providecommand*{\multfootsep}{\textsuperscript{\normalfont,}}

\providecommand*{\m@mmf@prepare}{%
  \kern-\multiplefootnotemarker
  \kern\multiplefootnotemarker\relax}
\providecommand*{\m@mmf@check}{%
  \ifdim\lastkern=\multiplefootnotemarker\relax
    \edef\@x@sf{\the\spacefactor}%
    \unkern
    \multfootsep
    \spacefactor\@x@sf\relax
  \fi}

\@ifclassloaded{memoir}{}{%
\let\l@dold@footnotetext\@footnotetext
\renewcommand{\@footnotetext}[1]{%
  \l@dold@footnotetext{#1}%
  \m@mmf@prepare}
\renewcommand*{\@footnotemark}{%
  \leavevmode
  \ifhmode
    \edef\@x@sf{\the\spacefactor}%
    \m@mmf@check
    \nobreak
  \fi
  \@makefnmark
  \m@mmf@prepare
  \ifhmode\spacefactor\@x@sf\fi
  \relax}
}

\let\l@doldold@footnotetext\@footnotetext
\renewcommand{\@footnotetext}[1]{%
  \ifnumberedpar@
    \edtext{}{\l@dbfnote{#1}}%
  \else
    \l@doldold@footnotetext{#1}%
  \fi}
\newcommand{\l@dbfnote}[1]{%
  \ifnumberedpar@
    \xright@appenditem{\noexpand\vl@dbfnote{{#1}}{\@thefnmark}}%
                       \to\inserts@list
    \global\advance\insert@count \@ne
  \fi\ignorespaces}
\newcommand{\vl@dbfnote}[2]{%
  \def\@thefnmark{#2}%
  \l@doldold@footnotetext{#1}}

\newcommand*{\prebodyfootmark}{%
  \leavevmode
  \ifhmode
    \edef\@x@sf{\the\spacefactor}%
    \m@mmf@check
    \nobreak
  \fi}
\newcommand{\postbodyfootmark}{%
  \m@mmf@prepare
  \ifhmode\spacefactor\@x@sf\fi\relax}

\newcommand*{\normal@footnotemarkX}[1]{%
  \prebodyfootmark
  \@nameuse{bodyfootmark#1}%
  \postbodyfootmark}

\newcommand*{\normalbodyfootmarkX}[1]{%
  \hbox{\textsuperscript{\normalfont\@nameuse{@thefnmark#1}}}}
\newcommand*{\normalvfootnoteX}[2]{%
  \insert\@nameuse{footins#1}\bgroup
    \csuse{notefontsizeX@#1}
    \footsplitskips
    \spaceskip=\z@skip \xspaceskip=\z@skip
    \@nameuse{footfmt#1}{#1}{#2}\egroup}

\newcommand*{\mpnormalvfootnoteX}[2]{%
  \global\setbox\@nameuse{mpfootins#1}\vbox{%
    \unvbox\@nameuse{mpfootins#1}
    \csuse{notefontsizeX@#1}
    \hsize\columnwidth
    \@parboxrestore
    \color@begingroup
    \@nameuse{footfmt#1}{#1}{#2}\color@endgroup}}

\newcommand*{\normalfootfmtX}[2]{%
  \ledsetnormalparstuff
  \hangindent=\csuse{hangindentX@#1}%
  {{\csuse{notenumfontX@#1}\@nameuse{footfootmark#1}}\strut%\enspace
    #2\strut\par}}

\newcommand*{\normalfootfootmarkX}[1]{%
  \textsuperscript{\@nameuse{@thefnmark#1}}}

\newcommand*{\normalfootstartX}[1]{%
  \vskip\skip\@nameuse{footins#1}%
  \leftskip=\z@
  \rightskip=\z@
  \@nameuse{footnoterule#1}}

\let\normalfootnoteruleX=\footnoterule

\newcommand*{\normalfootgroupX}[1]{%
  \unvbox\@nameuse{footins#1}}

\newcommand*{\mpnormalfootgroupX}[1]{%
  \vskip\skip\@nameuse{mpfootins#1}
  \normalcolor
  \@nameuse{footnoterule#1}
  \unvbox\@nameuse{mpfootins#1}}

\newcommand{\normalbfnoteX}[2]{%
  \ifnumberedpar@
    \xright@appenditem{\noexpand\vbfnoteX{#1}{#2}{\@nameuse{thefootnote#1}}}%
                       \to\inserts@list
    \global\advance\insert@count \@ne
  \fi\ignorespaces}

\newcommand{\vbfnoteX}[3]{%
  \@namedef{@thefnmark#1}{#3}%
  \@nameuse{regvfootnote#1}{#1}{#2}}

\newcommand{\vnumfootnoteX}[2]{%
  \ifnumberedpar@
    \edtext{}{\normalbfnoteX{#1}{#2}}%
  \else
    \@nameuse{regvfootnote#1}{#1}{#2}%
  \fi}

\newcommand*{\footnormalX}[1]{%
  \expandafter\let\csname footstart#1\endcsname=\normalfootstartX
  \@namedef{@footnotemark#1}{\normal@footnotemarkX{#1}}
  \@namedef{bodyfootmark#1}{\normalbodyfootmarkX{#1}}
  \expandafter\let\csname regvfootnote#1\endcsname=\normalvfootnoteX
  \expandafter\let\csname vfootnote#1\endcsname=\vnumfootnoteX
  \expandafter\let\csname footfmt#1\endcsname=\normalfootfmtX
  \@namedef{footfootmark#1}{\normalfootfootmarkX{#1}}
  \expandafter\let\csname footgroup#1\endcsname=\normalfootgroupX
  \expandafter\let\csname footnoterule#1\endcsname=\normalfootnoteruleX
  \count\csname footins#1\endcsname=1000
  \dimen\csname footins#1\endcsname=\ledfootinsdim
  \skip\csname footins#1\endcsname=1.2em \@plus .6em \@minus .6em
  \expandafter\let\csname mpvfootnote#1\endcsname=\mpnormalvfootnoteX
  \expandafter\let\csname mpfootgroup#1\endcsname=\mpnormalfootgroupX
  \count\csname mpfootins#1\endcsname=1000
  \dimen\csname mpfootins#1\endcsname=\ledfootinsdim
  \skip\csname mpfootins#1\endcsname=1.2em \@plus .6em \@minus .6em
}

\newcommand*{\foottwocolX}[1]{%
  \expandafter\let\csname regvfootnote#1\endcsname=\twocolvfootnoteX
  \expandafter\let\csname footfmt#1\endcsname=\twocolfootfmtX
  \expandafter\let\csname footgroup#1\endcsname=\twocolfootgroupX
  \twocolfootsetupX{#1}
  \expandafter\let\csname mpvfootnote#1\endcsname=\mpnormalvfootnoteX
  \expandafter\let\csname mpfootgroup#1\endcsname=\mptwocolfootgroupX
  \mptwocolfootsetupX{#1}}

\newcommand*{\twocolfootsetupX}[1]{%
  \count\csname footins#1\endcsname 500
  \multiply\dimen\csname footins#1\endcsname by \tw@}
\newcommand*{\mptwocolfootsetupX}[1]{%
  \count\csname mpfootins#1\endcsname 500
  \multiply\dimen\csname mpfootins#1\endcsname by \tw@}

\newcommand*{\twocolvfootnoteX}[2]{%
  \insert\csname footins#1\endcsname\bgroup
    \csuse{notefontsizeX@#1}
    \footsplitskips
    \spaceskip=\z@skip \xspaceskip=\z@skip
    \@nameuse{footfmt#1}{#1}{#2}\egroup}

\newcommand*{\twocolfootfmtX}[2]{%
  \normal@pars
  \hangindent=\csuse{hangindentX@#1}%
  \hsize \csuse{hsizetwocolX@#1}
  \parindent=\z@
%%%  \parfillskip=0pt \@plus 1fil
  \tolerance=5000\relax
  \raggedright
  \leavevmode
  {\csuse{notenumfontX@#1}\@nameuse{footfootmark#1}\strut%\enspace
    #2\strut\par}\allowbreak}

\newcommand*{\twocolfootgroupX}[1]{{\csuse{notefontsizeX@#1}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname footins#1\endcsname \tw@ \splittopskip}}
\newcommand*{\mptwocolfootgroupX}[1]{{%
  \vskip\skip\@nameuse{mpfootins#1}
  \normalcolor
  \@nameuse{footnoterule#1}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname mpfootins#1\endcsname \tw@ \splittopskip}}

\newcommand*{\footthreecolX}[1]{%
  \expandafter\let\csname regvfootnote#1\endcsname=\threecolvfootnoteX
  \expandafter\let\csname footfmt#1\endcsname=\threecolfootfmtX
  \expandafter\let\csname footgroup#1\endcsname=\threecolfootgroupX
  \threecolfootsetupX{#1}
  \expandafter\let\csname mpvfootnote#1\endcsname=\mpnormalvfootnoteX
  \expandafter\let\csname mpfootgroup#1\endcsname=\mpthreecolfootgroupX
  \mpthreecolfootsetupX{#1}}

\newcommand*{\threecolfootsetupX}[1]{%
  \count\csname footins#1\endcsname 333
  \multiply\dimen\csname footins#1\endcsname by \thr@@}
\newcommand*{\mpthreecolfootsetupX}[1]{%
  \count\csname mpfootins#1\endcsname 333
  \multiply\dimen\csname mpfootins#1\endcsname by \thr@@}

\newcommand*{\threecolvfootnoteX}[2]{%
  \insert\csname footins#1\endcsname\bgroup
    \csuse{notefontsizeX@#1}
    \footsplitskips
    \@nameuse{footfmt#1}{#1}{#2}\egroup}

\newcommand*{\threecolfootfmtX}[2]{%
  \hangindent=\csuse{hangindentX@#1}%
  \normal@pars
  \hsize \csuse{hsizethreecolX@#1}
  \parindent=\z@
%%%  \parfillskip=0pt \@plus 1fil
  \tolerance=5000\relax
  \raggedright
  \leavevmode
  {\csuse{notenumfontX@#1}\@nameuse{footfootmark#1}\strut%\enspace
    #2\strut\par}\allowbreak}

\newcommand*{\threecolfootgroupX}[1]{{\csuse{notefontsizeX@#1}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname footins#1\endcsname \thr@@ \splittopskip}}
\newcommand*{\mpthreecolfootgroupX}[1]{{%
  \vskip\skip\@nameuse{mpfootins#1}
  \normalcolor
  \@nameuse{footnoterule#1}
  \splittopskip=\ht\strutbox
  \expandafter
  \rigidbalance\csname mpfootins#1\endcsname \thr@@ \splittopskip}}

\newcommand*{\footparagraphX}[1]{%
  \expandafter\newcount\csname prevpage#1@num\endcsname
  \expandafter\let\csname footstart#1\endcsname=\parafootstartX
  \expandafter\let\csname regvfootnote#1\endcsname=\para@vfootnoteX
  \expandafter\let\csname footfmt#1\endcsname=\parafootfmtX
  \expandafter\let\csname footgroup#1\endcsname=\para@footgroupX
  \expandafter\let\csname footnoterule#1\endcsname=\normalfootnoteruleX
  \count\csname footins#1\endcsname=1000
  \expandafter\let\csname mpvfootnote#1\endcsname=\mppara@vfootnoteX
  \expandafter\let\csname mpfootgroup#1\endcsname=\mppara@footgroupX
  \count\csname mpfootins#1\endcsname=1000
  \para@footsetupX{#1}}

\newcommand*{\para@footsetupX}[1]{{\csuse{notefontsizeX@#1}
  \dimen0=\baselineskip
  \multiply\dimen0 by 1024
  \divide\dimen0 by \hsize \multiply\dimen0 by \footfudgefiddle\relax
  \expandafter
  \xdef\csname footfudgefactor#1\endcsname{%
    \expandafter\strip@pt\dimen0 }}}

\newcommand*{\parafootstartX}[1]{%
  \vskip\skip\@nameuse{footins#1}%
  \leftskip=\z@
  \rightskip=\z@
  \parindent=\z@
  \vskip\skip\@nameuse{footins#1}%
  \@nameuse{footnoterule#1}}

\newcommand*{\para@vfootnoteX}[2]{%
  \insert\csname footins#1\endcsname
  \bgroup
    \csuse{notefontsizeX@#1}
    \footsplitskips
    \setbox0=\vbox{\hsize=\maxdimen
      \noindent\@nameuse{footfmt#1}{#1}{#2}}%
    \setbox0=\hbox{\unvxh0[#1]}%
    \dp0=\z@
    \ht0=\csname footfudgefactor#1\endcsname\wd0
    \box0
    \penalty0
  \egroup}
\newcommand*{\mppara@vfootnoteX}[2]{%
  \global\setbox\@nameuse{mpfootins#1}\vbox{%
    \unvbox\@nameuse{mpfootins#1}
    \csuse{notefontsizeX@#1}
    \footsplitskips
    \setbox0=\vbox{\hsize=\maxdimen
      \noindent\color@begingroup\@nameuse{footfmt#1}{#1}{#2}\color@endgroup}%
    \setbox0=\hbox{\unvxh0[#1]}%
    \dp0=\z@
    \ht0=\csname footfudgefactor#1\endcsname\wd0
    \box0
    \penalty0}}

\newcommand*{\parafootfmtX}[2]{%
  \insertparafootsep{#1}%
  \ledsetnormalparstuff
  {\csuse{notenumfontX@#1}\csuse{notenumfontX@#1}\@nameuse{footfootmark#1}\strut%\enspace
    #2\penalty-10}}

\newcommand*{\para@footgroupX}[1]{%
  \unvbox\csname footins#1\endcsname
  \makehboxofhboxes
  \setbox0=\hbox{\unhbox0 \removehboxes}%
  \csuse{notefontsizeX@#1}
  \noindent\unhbox0\par}
\newcommand*{\mppara@footgroupX}[1]{{%
  \vskip\skip\@nameuse{mpfootins#1}
  \normalcolor
  \@nameuse{footnoterule#1}
  \unvbox\csname mpfootins#1\endcsname
  \makehboxofhboxes
  \setbox0=\hbox{\unhbox0 \removehboxes}%
  \csuse{notefontsizeX@#1}
  \noindent\unhbox0\par}}


\newcommand*{\doxtrafeeti}{%
  \setbox\@outputbox \vbox{%
    \unvbox\@outputbox
    \renewcommand{\do}[1]{\ifvoid\csuse{footins##1}\else\csuse{footstart##1}{##1}\csuse{footgroup##1}{##1}\fi}
    \dolistloop{\@series}%
  }}

\newcommand{\doreinxtrafeeti}{%
  \renewcommand{\do}[1]{\ifvoid\csuse{footins##1}\else\insert\csuse{footins##1}{\unvbox\csuse{footins##1}}\fi}%
  \dolistloop{\@series}%
  }

\newcommand*{\addfootinsX}[1]{%
  \eledmac@warning{AddfootinsX is obsolete in eledmac 1.0. Use newseries instead.}%
  \footnormalX{#1}%
  \g@addto@macro{\doxtrafeeti}{%
    \setbox\@outputbox \vbox{%
      \unvbox\@outputbox
      \ifvoid\@nameuse{footins#1}\else
        \@nameuse{footstart#1}{#1}\@nameuse{footgroup#1}{#1}\fi}}%as
  \g@addto@macro{\doreinxtrafeeti}{%
    \ifvoid\@nameuse{footins#1}\else
      \insert\@nameuse{footins#1}{\unvbox\@nameuse{footins#1}}\fi}%
  \g@addto@macro{\l@dfambeginmini}{%
    \expandafter\expandafter\expandafter\let\expandafter\expandafter
      \csname footnote#1\endcsname \csname mpfootnote#1\endcsname}%
  \g@addto@macro{\l@dfamendmini}{%
    \ifvoid\@nameuse{mpfootins#1}\else\@nameuse{mpfootgroup#1}{#1}\fi}%
}
\newcommand{\newseries}[1]{%
    \renewcommand{\do}[1]{\newseries@{##1}}%
    \docsvlist{#1}
}
\newcommand{\@series}{}
\newcommand{\newseries@}[1]{
    \xifinlist{#1}{\@series}{\eledmac@warning{Series #1 is still existing !}}
    {%
    \csgdef{Xhangindent@#1}{0pt}%
    \csgdef{hangindentX@#1}{0pt}
    \csgdef{hsizetwocol@#1}{0.45 \hsize}%
    \csgdef{hsizetwocolX@#1}{0.45 \hsize}%
    \csgdef{hsizethreecol@#1}{.3 \hsize}%
    \csgdef{hsizethreecolX@#1}{.3 \hsize}%
    \csgdef{Xnotenumfont@#1}{\notenumfont}%
    \csgdef{Xendnotenumfont@#1}{\notenumfont}%
    \csgdef{notenumfontX@#1}{\notenumfont}%
    \csgdef{Xnotefontsize@#1}{\notefontsetup}%
    \csgdef{notefontsizeX@#1}{\notefontsetup}%
    \csgdef{Xendnotefontsize@#1}{\notefontsetup}%
    \csgdef{boxlinenum@#1}{0pt}%
    \csgdef{boxsymlinenum@#1}{0pt}%
    \newtoggle{numberonlyfirstinline@#1}%
    \csgdef{symlinenum@#1}{\symplinenum}%
    \newtoggle{nonumberinfootnote@#1}%
    \csgdef{beforenumberinfootnote@#1}{0pt}%
    \csgdef{afternumberinfootnote@#1}{0.5em}%
    \csgdef{beforesymlinenum@#1}{\csuse{beforenumberinfootnote@#1}}%
    \csgdef{aftersymlinenum@#1}{\csuse{afternumberinfootnote@#1}}%
    \csgdef{inplaceofnumber@#1}{1em}%
    \global\cslet{lemmaseparator@#1}{\rbracket}%
    \csgdef{beforelemmaseparator@#1}{0em}%
    \csgdef{afterlemmaseparator@#1}{0.5em}%
    \csgdef{inplaceoflemmaseparator@#1}{1em}%
    \csgdef{afternote@#1}{1em plus.4em minus.4em}%
    \csgdef{parafootsep@#1}{\parafootftmsep}%

    \expandafter\newinsert\csname mpfootins#1\endcsname
    \expandafter\newinsert\csname footins#1\endcsname
    \expandafter\newinsert\csname #1footins\endcsname
    \expandafter\newinsert\csname mp#1footins\endcsname

    \global\expandafter\newcommand\expandafter *\csname #1footnote\endcsname[2][]{%
        \begingroup%
        \newcommand{\content}{##2}%
        \ifnumberedpar@
            \ifledRcol%
                \footnoteoptions@[R]{##1}{true}%
                \xright@appenditem{\noexpand\csuse{v#1footnote}{#1}%
                {{\l@d@nums}{\csexpandonce{@tag}}{\csexpandonce{content}}}}\to\inserts@listR
                \footnoteoptions@[R]{##1}{false}%
                \global\advance\insert@countR \@ne%
            \else%
                \footnoteoptions@{##1}{true}%
                \xright@appenditem{\noexpand\csuse{v#1footnote}{#1}%
                {{\l@d@nums}{\csexpandonce{@tag}}{\csexpandonce{content}}}}\to\inserts@list
                \global\advance\insert@count \@ne%
                \footnoteoptions@{##1}{false}%
            \fi
        \else
            \csuse{v#1footnote}{#1}{{0|0|0|0|0|0|0}{}{##1}}%
        \fi%
        \ignorespaces%
        \endgroup
        }
    \footnormal{#1}

    \global\expandafter\newcommand\csname footnote#1\endcsname[1]{%
        \begingroup%
            \newcommand{\content}{##1}%
            \stepcounter{footnote#1}%
            \protected@csxdef{@thefnmark#1}{\csuse{thefootnote#1}}%
            \csuse{@footnotemark#1}%
            \csuse{vfootnote#1}{#1}{\csexpandonce{content}}\m@mmf@prepare%
        \endgroup%
    }
    \newcounter{footnote#1}
      \global\expandafter\renewcommand\csname thefootnote#1\endcsname{\arabic{footnote#1}}
    \footnormalX{#1}

    \global\expandafter\newcommand\csname #1endnote\endcsname[2]{{\newlinechar='40
        \newcommand{\content}{##1}%
           \immediate\write\l@d@end{\expandafter\string\csname #1end\endcsname%
          {\ifnumberedpar@\l@d@nums\fi}%
           {\ifnumberedpar@\csexpandonce{@tag}\fi}{\csexpandonce{content}}{#1}}}\ignorespaces%
        }

    \global\csletcs{#1end}{@gobblethree}

    \global\csletcs{#1@@footnote}{#1footnote}

    \listxadd{\@series}{#1}
}
}% End of \newseries
\newseries{A,B,C,D,E,Z}
\newcommand{\settoggle@series}[3]{%
    \renewcommand{\do}[1]{\settoggle{#2@##1}{#3}}
    \ifstrempty{#1}{%
              \dolistloop{\@series}%
        }%
     {%
              \docsvlist{#1}%
        }%
}
\newcommand{\setcommand@series}[3]{%
    \renewcommand{\do}[1]{\csgdef{#2@##1}{#3}}
    \ifstrempty{#1}{%
              \dolistloop{\@series}%
    }%
    {%
              \docsvlist{#1}%
    }%
}%
\newcommand{\newhookcommand@series}[1]{%
  \global\expandafter\newcommand\expandafter*\csname #1\endcsname[2][]{\csuse{setcommand@series}{##1}{#1}{##2}}%
}
\newhookcommand@series{Xhangindent}

\newhookcommand@series{hangindentX}

\newhookcommand@series{hsizetwocol}

\newhookcommand@series{hsizethreecol}

\newhookcommand@series{hsizetwocolX}

\newhookcommand@series{hsizethreecolX}

\newhookcommand@series{Xnotenumfont}

\newhookcommand@series{Xendnotenumfont}

\newhookcommand@series{notenumfontX}

\newhookcommand@series{Xnotefontsize}

\newhookcommand@series{notefontsizeX}

\newhookcommand@series{Xendnotefontsize}

\newhookcommand@series{boxlinenum}

\newhookcommand@series{boxsymlinenum}

\newhookcommand@series{parafootsep}

\newhookcommand@series{symlinenum}

\newhookcommand@series{beforenumberinfootnote}

\newhookcommand@series{afternumberinfootnote}

\newhookcommand@series{beforesymlinenum}

\newhookcommand@series{aftersymlinenum}

\newhookcommand@series{inplaceofnumber}

\newhookcommand@series{lemmaseparator}

\newhookcommand@series{beforelemmaseparator}

\newhookcommand@series{afterlemmaseparator}

\newhookcommand@series{inplaceoflemmaseparator}

\newhookcommand@series{afternote}

\newcommand{\newhooktoggle@series}[1]{%
  \global\expandafter\newcommandx\expandafter*\csname #1\endcsname[2][1,2={true},usedefault]{\settoggle@series{##1}{#1}{##2}}%
}
\newhooktoggle@series{numberonlyfirstinline}
\newhooktoggle@series{nonumberinfootnote}
\newcommand*{\notenumfont}{\normalfont}
\newcommand*{\notefontsetup}{\footnotesize}
\newif\ifledplinenum
  \ledplinenumtrue
\newcommand*{\symplinenum}{}
\newtoggle{nonum@}
\newtoggle{nosep@}
\newcommandx*{\nolemmaseparator}[1][1]{\lemmaseparator[#1]{}}
\newskip\ipn@skip
\newcommand*{\interparanoteglue}[1]{%
             {\notefontsetup\global\ipn@skip=#1 \relax}}
\interparanoteglue{1em plus.4em minus.4em}
\newcommand{\parafootftmsep}{}
\newcommand{\printlinefootnote}[2]{%
   \iftoggle{nonum@}{%Try if the line number must printed for this specific not (by default, yes)
   \hspace{\csuse{inplaceofnumber@#2}}%
   }%
   {%
       {%
           \iftoggle{nonumberinfootnote@#2}%Try if the line number must printed (by default, yes)
           {%
           \hspace{\csuse{inplaceofnumber@#2}}%
           }%
           {%
              {\iftoggle{numberonlyfirstinline@#2}% If for this series the line number must be printed only in the first time.
                 {%
                 \ifcsdef{prevline#2}%
                    {%Be sure the \prevline exists.
                    \ifnumequal{\csuse{prevline#2}}{\line@num}%Try it
                       {%
                       \ifcsempty{symlinenum@#2}% Try if a symbol is define
                        {%
                            \hspace{\csuse{inplaceofnumber@#2}}%
                        }%
                        {\hspace{\csuse{beforesymlinenum@#2}}\csuse{Xnotenumfont@#2}%
                        \ifdimequal{\csuse{boxsymlinenum@#2}}{0pt}%
                         {\csuse{symlinenum@#2}}%
{\hbox to \csuse{boxsymlinenum@#2}{\csuse{symlinenum@#2}\hfill}}%
    \hspace{\csuse{aftersymlinenum@#2}}}%
                       }%
                       {%
                        \hspace{\csuse{beforenumberinfootnote@#2}}\csuse{Xnotenumfont@#2}%
                        \ifdimequal{\csuse{boxlinenum@#2}}{0pt}{%
                            \printlines#1|}%
                            {%
                            \hbox to \csuse{boxlinenum@#2}{\printlines#1|\hfill}%
                            }%
                            \hspace{\csuse{afternumberinfootnote@#2}}%
                        }%
                    }%
                    {%
                    \hspace{\csuse{beforenumberinfootnote@#2}}\csuse{Xnotenumfont@#2}%
                    \ifdimequal{\csuse{boxlinenum@#2}}{0pt}{%
                        \printlines#1|}%
                        {%
                        \hbox to \csuse{boxlinenum@#2}{\printlines#1|\hfill}%
                        }%
                    \hspace{\csuse{afternumberinfootnote@#2}}%
                    }%
              }%
              {%
              \hspace{\csuse{beforenumberinfootnote@#2}}\csuse{Xnotenumfont@#2}%
              \ifdimequal{\csuse{boxlinenum@#2}}{0pt}{%
                     \printlines#1|}%
                     {%
                     \hbox to \csuse{boxlinenum@#2}{\printlines#1|\hfill}%
                     }%
              \hspace{\csuse{afternumberinfootnote@#2}}%
              }%
              \csnumgdef{prevline#2}{\line@num}%
                 }%
        }%
     }%
   }%
}
\countdef\pageno=0 \pageno=1
\newcommand*{\advancepageno}{\ifnum\pageno<\z@ \global\advance\pageno\m@ne
  \else\global\advance\pageno\@ne\fi}

\providecommand{\m@m@makecolfloats}{%
  \xdef\@freelist{\@freelist\@midlist}%
  \global \let \@midlist \@empty
  \@combinefloats}
\providecommand{\m@m@makecoltext}{%
  \ifvbox\@kludgeins
    \@makespecialcolbox
  \else
    \setbox\@outputbox \vbox to\@colht {%
      \@texttop
      \dimen@ \dp\@outputbox
      \unvbox\@outputbox
      \vskip -\dimen@
      \@textbottom}%
  \fi}
\providecommand{\m@m@makecolintro}{}

\gdef\l@d@makecol{%
  \l@ddofootinsert
  \m@m@makecolfloats
  \m@m@makecoltext
  \global \maxdepth \@maxdepth}

\newcommand*{\l@ddofootinsert}{%
%%%   \page@start
   \ifvoid\footins
     \setbox\@outputbox \box\@cclv
   \else
     \setbox\@outputbox \vbox {%
       \boxmaxdepth \@maxdepth
       \@tempdima\dp\@cclv
       \unvbox \@cclv
       \vskip \skip\footins
       \color@begingroup
         \normalcolor
         \footnoterule
         \unvbox \footins
       \color@endgroup
       }%
   \fi
   \l@ddoxtrafeet
}

\newcommand*{\l@ddoxtrafeet}{%
  \doxtrafeeti
  \doxtrafeetii}

\newcommand*{\doxtrafeetii}{%
  \setbox\@outputbox \vbox{%
    \unvbox\@outputbox
    \@opxtrafeetii}}
\newcommand*{\@opxtrafeetii}{%
  \renewcommand{\do}[1]{\ifvoid\csuse{##1footins}\else\csuse{##1footstart}{##1}\csuse{##1footgroup}{##1}\fi}
  \dolistloop{\@series}}
\newcommand*{\l@ddodoreinxtrafeet}{%
  \doreinxtrafeeti
  \doreinxtrafeetii}

\newcommand*{\doreinxtrafeetii}{%
  \renewcommand{\do}[1]{\ifvoid\csuse{##1footins}\else\insert\csuse{##1ootins}{\unvbox\csuse{##1footins}}\fi}
  \dolistloop{\@series}
}

\gdef \l@d@reinserts{%
  \ifvoid\footins\else\insert\footins{\unvbox\footins}\fi
  \l@ddodoreinxtrafeet
  \ifvbox\@kludgeins\insert\@kludgeins{\unvbox\@kludgeins}\fi
}

\@ifclassloaded{memoir}{%
  \g@addto@macro{\m@mdoextrafeet}{\l@ddoxtrafeet}%
  \g@addto@macro{\m@mdodoreinextrafeet}{\l@ddodoreinxtrafeet}%
  }{%
  \gdef\@makecol{\l@d@makecol}%
  \gdef\@reinserts{\l@d@reinserts}%
}

\newcommand*{\addfootins}[1]{%
   \eledmac@warning{addfootins is deprecated, use newseries instead}
  \footnormal{#1}
  \g@addto@macro{\@opxtrafeetii}{%
    \ifvoid\@nameuse{#1footins}\else
      \@nameuse{#1footstart{#1}}\@nameuse{#1footgroup}{#1}\fi}
  \g@addto@macro{\doreinxtrafeetii}{%
    \ifvoid\@nameuse{#1footins}\else
      \insert\@nameuse{#1footins}{\unvbox\@nameuse{#1footins}}\fi}
  \g@addto@macro{\l@dedbeginmini}{%
    \expandafter\let\csname #1footnote\endcsname = \@nameuse{mp#1footnote}}
  \g@addto@macro{\l@dedendmini}{%
    \ifvoid\@nameuse{mp#1footins}\else\@nameuse{mpfootgroup#1{#1}}\fi}
}
\newif\if@led@nofoot
\newcommand*{\@led@extranofeet}{}

\@ifclassloaded{memoir}{%
\g@addto@macro{\@mem@extranofeet}{%
  \renewcommand{\do}[1]{\ifvoid\cuse{##1footins}\else\@mem@nofootfalse\fi%
  \ifvoid\csuse{footins##1}\else\@mem@nofootfalse\fi%
  }
  \dolistloop{\@series}%
  \@led@extranofeet}
}{%
\newcommand*{\@led@testifnofoot}{%
  \@led@nofoottrue
  \ifvoid\footins\else\@led@nofootfalse\fi
  \renewcommand{\do}[1]{\ifvoid\csuse{##1footins}\else\@led@nofootfalse\fi%
  \ifvoid\csuse{footins##1}\else\@led@nofootfalse\fi}%
  \dolistloop{\@series}
  \@led@extranofeet}

\renewcommand{\@doclearpage}{%
  \@led@testifnofoot
  \if@led@nofoot
    \setbox\@tempboxa\vsplit\@cclv to\z@ \unvbox\@tempboxa
    \setbox\@tempboxa\box\@cclv
    \xdef\@deferlist{\@toplist\@botlist\@deferlist}%
    \global \let \@toplist \@empty
    \global \let \@botlist \@empty
    \global \@colroom \@colht
    \ifx \@currlist\@empty
    \else
       \@latexerr{Float(s) lost}\@ehb
       \global \let \@currlist \@empty
    \fi
    \@makefcolumn\@deferlist
    \@whilesw\if@fcolmade \fi{\@opcol\@makefcolumn\@deferlist}%
    \if@twocolumn
      \if@firstcolumn
        \xdef\@dbldeferlist{\@dbltoplist\@dbldeferlist}%
        \global \let \@dbltoplist \@empty
        \global \@colht \textheight
        \begingroup
           \@dblfloatplacement
           \@makefcolumn\@dbldeferlist
           \@whilesw\if@fcolmade \fi{\@outputpage
                                     \@makefcolumn\@dbldeferlist}%
        \endgroup
      \else
        \vbox{}\clearpage
      \fi
    \fi
  \else
    \setbox\@cclv\vbox{\box\@cclv\vfil}%
    \l@d@makecol\@opcol
    \clearpage
  \fi}
}

\list@create{\labelref@list}
%% \newcommand*{\zz@@@}{000|000|000} % set three counters to zero in one go
\newcommand*{\zz@@@}{000|000} % set two counters to zero in one go

\newcommand*{\edlabel}[1]{\@bsphack
  \write\linenum@out{\string\@lab}%
  \ifx\labelref@list\empty
    \xdef\label@refs{\zz@@@}%
  \else
    \gl@p\labelref@list\to\label@refs
  \ifvmode
     \advancelabel@refs
  \fi
  \fi
  \protected@write\@auxout{}%
    {\string\l@dmake@labels\space\thepage|\label@refs|{#1}}%
  \@esphack}

\newcommand{\advancelabel@refs}{%
    \newcounter{line}%
    \setcounter{line}{\expandafter\labelrefsparseline\label@refs}%
    \stepcounter{line}%
    \ifsublines@%
        \newcounter{subline}%
        \setcounter{subline}{\expandafter\labelrefsparsesubline\label@refs}%
        \stepcounter{subline}{1}%
    \def\label@refs{\theline|\thesubline}%
    \else%
        \def\label@refs{\theline|0}%
\fi%
}
\def\labelrefsparseline#1|#2{#1}
\def\labelrefsparsesubline#1|#2{#2}
\newcommand*{\l@dmake@labels}{}
\def\l@dmake@labels#1|#2|#3|#4{%
  \expandafter\ifx\csname the@label#4\endcsname \relax\else
    \led@warn@DuplicateLabel{#4}%
  \fi
  \expandafter\gdef\csname the@label#4\endcsname{#1|#2|#3}%
  \ignorespaces}

\AtBeginDocument{%
  \def\l@dmake@labels#1|#2|#3|#4{}%
}

\newcommand*{\@lab}{\xright@appenditem
  {\linenumrep{\line@num}|%
     \ifsublines@ \sublinenumrep{\subline@num}\else 0\fi}\to\labelref@list}

\newcommand*{\edpageref}[1]{\l@dref@undefined{#1}\l@dgetref@num{1}{#1}}
\newcommand*{\xpageref}[1]{\l@dgetref@num{1}{#1}}

\newcommand*{\lineref}[1]{\l@dref@undefined{#1}\l@dgetref@num{2}{#1}}
\newcommand*{\xlineref}[1]{\l@dgetref@num{2}{#1}}

\newcommand*{\sublineref}[1]{\l@dref@undefined{#1}\l@dgetref@num{3}{#1}}
\newcommand*{\xsublineref}[1]{\l@dgetref@num{3}{#1}}

\newcommand*{\l@dref@undefined}[1]{%
  \expandafter\ifx\csname the@label#1\endcsname\relax
    \led@warn@RefUndefined{#1}%
  \fi}

\newcommand*{\l@dgetref@num}[2]{%
  \expandafter
  \ifx\csname the@label#2\endcsname \relax
    000%
  \else
    \expandafter\expandafter\expandafter
    \l@dlabel@parse\csname the@label#2\endcsname|#1%
  \fi}

\newcommand*{\l@dlabel@parse}{}
\def\l@dlabel@parse#1|#2|#3|#4{%
  \ifcase #4\relax
  \or #1%
  \or #2%
  \or #3%
  \fi}

\newcommand*{\xxref}[2]{%
  {\expandafter\ifx\csname the@label#1\endcsname
   \relax \expandafter\let\csname the@label#1\endcsname\zz@@@\fi
   \expandafter\ifx\csname the@label#2\endcsname \relax
   \expandafter\let\csname the@label#2\endcsname\zz@@@\fi
   \linenum{\csname the@label#1\endcsname|%
    \csname the@label#2\endcsname}}}

\newcommand*{\edmakelabel}[2]{\expandafter\xdef\csname the@label#1\endcsname{#2}}

\newwrite\l@d@end
\newif\ifl@dend@
\newcommand{\l@dend@open}[1]{\global\l@dend@true\immediate\openout\l@d@end=#1\relax}
\newcommand{\l@dend@close}{\global\l@dend@false\immediate\closeout\l@d@end}

\newcommand{\l@dend@stuff}{%
 \ifl@dend@\relax\else
   \l@dend@open{\jobname.end}%
 \fi
 \immediate\write\l@d@end{\string\l@d@section{\the\section@num}}}

\def\endprint#1#2#3#4{{\csuse{Xendnotefontsize@#4}{\csuse{Xendnotenumfont@#4}\printendlines#1|}%
      \enspace{\select@lemmafont#1|#2}\enskip#3\par}}
\providecommand*{\@gobblethree}[3]{}

\let\l@d@section=\@gobble

\newcommand*{\setprintendlines}[6]{%
  \l@d@pnumfalse \l@d@dashfalse
  \ifnum#4=#1 \else
    \l@d@pnumtrue
    \l@d@dashtrue
  \fi
  \ifl@d@pnum \l@d@elintrue \else \l@d@elinfalse \fi
  \ifnum#2=#5 \else
      \l@d@elintrue
      \l@d@dashtrue
  \fi
  \l@d@ssubfalse
  \ifnum#3=0 \else
      \l@d@ssubtrue
  \fi
  \l@d@eslfalse
  \ifnum#6=0 \else
      \ifnum#6=#3
         \ifl@d@elin \l@d@esltrue \else \l@d@eslfalse \fi
      \else
         \l@d@esltrue
         \l@d@dashtrue
      \fi
  \fi}
\def\printendlines#1|#2|#3|#4|#5|#6|#7|{\begingroup
  \setprintendlines{#1}{#2}{#3}{#4}{#5}{#6}%
  \printnpnum{#1} \linenumrep{#2}%
  \ifl@d@ssub \fullstop \sublinenumrep{#3}\fi
  \ifl@d@dash \endashchar\fi
  \ifl@d@pnum \printnpnum{#4}\fi
  \ifl@d@elin \linenumrep{#5}\fi
  \ifl@d@esl \ifl@d@elin \fullstop\fi \sublinenumrep{#6}\fi
\endgroup}

\newcommand*{\printnpnum}[1]{p.#1) }

\newcommand*{\doendnotes}[1]{\l@dend@close
   \begingroup
      \makeatletter
      \expandafter\let\csname #1end\endcsname=\endprint
      \input\jobname.end
   \endgroup}
\newcommand*{\noendnotes}{\global\let\l@dend@stuff=\relax
                \global\chardef\l@d@end=16 }
\let\l@dold@xympar\@xympar
\renewcommand{\@xympar}{%
  \ifnumberedpar@
    \led@warn@NoMarginpars
    \@esphack
  \else
    \l@dold@xympar
  \fi}

\newcount\sidenote@margin
\newcommand*{\sidenotemargin}[1]{{%
  \l@dgetsidenote@margin{#1}%
  \ifnum\@l@dtempcntb>\m@ne
    \global\sidenote@margin=\@l@dtempcntb
  \fi}}
\newcommand*{\l@dgetsidenote@margin}[1]{%
  \def\@tempa{#1}\def\@tempb{left}%
  \ifx\@tempa\@tempb
    \@l@dtempcntb \z@
  \else
    \def\@tempb{right}%
    \ifx\@tempa\@tempb
      \@l@dtempcntb \@ne
    \else
      \def\@tempb{outer}%
      \ifx\@tempa\@tempb
        \@l@dtempcntb \tw@
      \else
        \def\@tempb{inner}%
        \ifx\@tempa\@tempb
          \@l@dtempcntb \thr@@
        \else
          \led@warn@BadSidenotemargin
          \@l@dtempcntb \m@ne
        \fi
      \fi
    \fi
  \fi}
\sidenotemargin{right}

\newbox\l@dlp@rbox
\newbox\l@drp@rbox

\newdimen\ledlsnotewidth \ledlsnotewidth=\marginparwidth
\newdimen\ledrsnotewidth \ledrsnotewidth=\marginparwidth
\newdimen\ledlsnotesep \ledlsnotesep=\linenumsep
\newdimen\ledrsnotesep \ledrsnotesep=\linenumsep
\newcommand*{\ledlsnotefontsetup}{\raggedleft\footnotesize}
\newcommand*{\ledrsnotefontsetup}{\raggedright\footnotesize}

\newcommand*{\ledleftnote}[1]{\edtext{}{\l@dlsnote{#1}}}
\newcommand*{\ledrightnote}[1]{\edtext{}{\l@drsnote{#1}}}
\newcommand*{\ledsidenote}[1]{\edtext{}{\l@dcsnote{#1}}}

\newif\ifrightnoteup
  \rightnoteuptrue
\newcommand*{\l@dlsnote}[1]{%
  \begingroup%
  \newcommand{\content}{#1}%
  \ifnumberedpar@
    \xright@appenditem{\noexpand\vl@dlsnote{\csexpandonce{content}}}%
                       \to\inserts@list
    \global\advance\insert@count \@ne
  \fi\ignorespaces\endgroup}
\newcommand*{\l@drsnote}[1]{%
  \begingroup%
  \newcommand{\content}{#1}%
  \ifnumberedpar@
    \xright@appenditem{\noexpand\vl@drsnote{\csexpandonce{content}}}%
                       \to\inserts@list
    \global\advance\insert@count \@ne
  \fi\ignorespaces\endgroup}
\newcommand*{\l@dcsnote}[1]{\begingroup%
  \newcommand{\content}{#1}%
  \ifnumberedpar@
    \xright@appenditem{\noexpand\vl@dcsnote{\csexpandonce{content}}}%
                       \to\inserts@list
    \global\advance\insert@count \@ne
  \fi\ignorespaces\endgroup}

\newcommand*{\vl@dlsnote}[1]{\setl@dlp@rbox{#1}}
\newcommand*{\vl@drsnote}[1]{\setl@drp@rbox{#1}}
\newcommand*{\vl@dcsnote}[1]{\gdef\l@dcsnotetext{#1}}

\newcommand*{\setl@dlp@rbox}[1]{%
  {\parindent\z@\hsize=\ledlsnotewidth\ledlsnotefontsetup
   \global\setbox\l@dlp@rbox
   \ifleftnoteup
     =\vbox to\z@{\vss #1}%
   \else
     =\vbox to 0.70\baselineskip{\strut#1\vss}%
   \fi}}
%%   \global\setbox\l@dlp@rbox=\vbox to\z@{#3\vss}}}% aligns on top line
\newcommand*{\setl@drp@rbox}[1]{%
  {\parindent\z@\hsize=\ledrsnotewidth\ledrsnotefontsetup
   \global\setbox\l@drp@rbox
   \ifrightnoteup
     =\vbox to\z@{\vss#1}%
   \else
     =\vbox to0.7\baselineskip{\strut#1\vss}%
   \fi}}
\newif\ifleftnoteup
  \leftnoteuptrue
\newcommand*{\savel@dcsnote}[3]{%
  \gdef\l@dcsnotetext{#3}}

\newcommand*{\affixside@note}{%
  \gdef\@templ@d{}%
  \ifx\@templ@d\l@dcsnotetext \else
    \if@twocolumn
      \if@firstcolumn
        \setl@dlp@rbox{\l@dcsnotetext}%
      \else
        \setl@drp@rbox{\l@dcsnotetext}%
      \fi
    \else
      \@l@dtempcntb=\sidenote@margin
      \ifnum\@l@dtempcntb>\@ne
        \advance\@l@dtempcntb by\page@num
      \fi
      \ifodd\@l@dtempcntb
        \setl@drp@rbox{\l@dcsnotetext}%
      \else
        \setl@dlp@rbox{\l@dcsnotetext}%
      \fi
    \fi
  \fi}

\newcommand*{\l@dfeetbeginmini}{\l@dedbeginmini\l@dfambeginmini}
\newcommand*{\l@dfeetendmini}{\l@dedendmini\l@dfamendmini}

\newcommand*{\l@dedbeginmini}{%
  \renewcommand{\do}[1]{\csletcs{v##1footnote}{mpv##1footnote}}%
  \dolistloop{\@series}%
  }
\newcommand*{\l@dedendmini}{%
  \ifl@dpairing
    \ifledRcol
      \flush@notesR
    \else
      \flush@notes
    \fi
  \fi
  \renewcommand{\do}[1]{\ifvoid\csuse{mp##1footins}\else\csuse{mp##1footgroup}{##1}\fi}%
  \dolistloop{\@series}%
  }

\newcommand*{\l@dfambeginmini}{%
   \renewcommand{\do}[1]{\csletcs{vfootnote##1}{mpvfootnote##1}}%
   \dolistloop{\@series}}
\newcommand*{\l@dfamendmini}{%
  \renewcommand{\do}[1]{\ifvoid\csuse{mpfootins##1}\else\csuse{mpfootgroup##1}{##1}\fi}%
  \dolistloop{\@series}}
\def\@iiiminipage#1#2[#3]#4{%
  \leavevmode
  \@pboxswfalse
  \setlength\@tempdima{#4}%
  \def\@mpargs{{#1}{#2}[#3]{#4}}%
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \let\@footnotetext\@mpfootnotetext
      \l@dfeetbeginmini%                   added
      \let\@listdepth\@mplistdepth \@mplistdepth\z@
      \@minipagerestore
      \@setminipage}

\def\endminipage{%
  \par
  \unskip
  \ifvoid\@mpfootins\else
    \l@dunboxmpfoot
  \fi
  \l@dfeetendmini%                 added
  \@minipagefalse
  \color@endgroup
  \egroup
  \expandafter\@iiiparbox\@mpargs{\unvbox\@tempboxa}}

\newcommand*{\l@dunboxmpfoot}{%
    \vskip\skip\@mpfootins
    \normalcolor
    \footnoterule
    \unvbox\@mpfootins}

\newenvironment{ledgroup}{%
  \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
  \let\@footnotetext\@mpfootnotetext
  \l@dfeetbeginmini%
}{%
  \par
  \unskip
  \ifvoid\@mpfootins\else
    \l@dunboxmpfoot
  \fi
  \l@dfeetendmini%
}

\newenvironment{ledgroupsized}[2][l]{%
  \hsize #2\relax
%%  \textwidth #2\relax
%%  \columnwidth #2\relax
  \let\ledllfill\hfil
  \let\ledrlfill\hfil
  \def\@tempa{#1}\def\@tempb{l}%
      \ifx\@tempa\@tempb
    \let\ledllfill\relax
  \else
    \def\@tempb{r}%
    \ifx\@tempa\@tempb
      \let\ledrlfill\relax
    \fi
  \fi
  \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
  \let\@footnotetext\@mpfootnotetext
  \l@dfeetbeginmini%
}{%
  \par
  \unskip
  \ifvoid\@mpfootins\else
    \l@dunboxmpfoot
  \fi
  \l@dfeetendmini%
}

\newcommand{\pagelinesep}{-}
\newcommand{\edindexlab}{$&}
\newcounter{labidx}
\setcounter{labidx}{0}

\newcommand{\doedindexlabel}{\stepcounter{labidx}%
  \edlabel{\edindexlab\thelabidx}}

\newcommand{\thepageline}{%
  \thepage\pagelinesep\lineref{\edindexlab\thelabidx}}

\@ifclassloaded{memoir}{%
  \g@addto@macro{\makememindexhook}{%
    \def\edindex{\@bsphack%
      \@ifnextchar [{\l@d@index}{\l@d@index[\jobname]}}}
  \newcommand{\edindex}[2][\jobname]{\@bsphack\@esphack}
  \def\l@d@index[#1]{%
    \@ifundefined{#1@idxfile}%
    {\ifreportnoidxfile
       \led@warn@NoIndexFile{#1}%
     \fi
     \begingroup
     \@sanitize
     \@nowrindex}%
    {\def\@idxfile{#1}%
     \doedindexlabel
     \begingroup
     \@sanitize
     \l@d@wrindexm@m}}
  \newcommand{\l@d@wrindexm@m}[1]{\l@d@@wrindexhyp#1||\\}
  \def\l@d@@wrindexhyp#1|#2|#3\\{%
    \ifshowindexmark\@showidx{#1}\fi
    \ifx\\#2\\%
      \protected@write\@auxout{}%
        {\string\@@wrindexm@m{\@idxfile}{#1|hyperpage}{\thepageline}}%
    \else
      \def\Hy@temp@A{#2}%
      \ifx\Hy@temp@A\HyInd@ParenLeft
        \protected@write\@auxout{}%
          {\string\@@wrindexm@m{\@idxfile}{#1|#2hyperpage}{\thepageline}}%
      \else
        \protected@write\@auxout{}%
          {\string\@@wrindexm@m{\@idxfile}{#1|#2}{\thepageline}}%
      \fi
    \fi
    \endgroup
    \@esphack}
}{%
  \g@addto@macro{\makeindex}{%
    \def\edindex{\@bsphack
    \doedindexlabel
    \begingroup
    \@sanitize
    \@wredindex}}
  \newcommand{\edindex}[1]{\@bsphack\@esphack}
  \newcommand{\@wredindex}[1]{%
    \protected@write\@indexfile{}%
      {\string\indexentry{#1}{\thepageline}}%
  \endgroup
  \@esphack}
}

\AtBeginDocument{\@ifpackageloaded{hyperref}{}{%
  \def\l@d@@wrindexhyp#1||\\{%
    \ifshowindexmark\@showidx{#1}\fi
    \protected@write\@auxout{}%
      {\string\@@wrindexm@m{\@idxfile}{#1}{\thepageline}}%
    \endgroup
    \@esphack}}}

\newtoks\@emptytoks

\newtoks\l@denvbody

\newcommand{\addtol@denvbody}[1]{%
  \global\l@denvbody\expandafter{\the\l@denvbody#1}}

\newcommand{\l@dcollect@body}[1]{%
  \l@denvbody{\expandafter#1\expandafter{\the\l@denvbody}}%
  \edef\processl@denvbody{\the\l@denvbody\noexpand\end{\@currenvir}}%
  \l@denvbody\@emptytoks \def\l@dbegin@stack{b}%
  \begingroup
    \expandafter\let\csname\@currenvir\endcsname\l@dcollect@@body
    \edef\processl@denvbody{\expandafter\noexpand\csname\@currenvir\endcsname}%
    \processl@denvbody}

\def\l@dpush@begins#1\begin#2{%
  \ifx\end#2\else b\expandafter\l@dpush@begins\fi}

\def\l@dcollect@@body#1\end#2{%
  \edef\l@dbegin@stack{\l@dpush@begins#1\begin\end
                       \expandafter\@gobble\l@dbegin@stack}%
  \ifx\@empty\l@dbegin@stack
    \endgroup
    \@checkend{#2}%
    \addtol@denvbody{#1}%
  \else
    \addtol@denvbody{#1\end{#2}}%
  \fi
  \processl@denvbody % A little tricky! Note the grouping
}

\newcommand*{\hangingsymbol}{}
\newif\ifinstanza
\instanzafalse
\newif\ifinserthangingsymbol
\newcommand{\inserthangingsymbol}{%
\ifinserthangingsymbol%
   \ifinstanza%
      \hfill\hangingsymbol%
   \fi%
\fi%
}
\newcommand*{\ampersand}{\char`\&}

  \chardef\body=\catcode`\@
  \catcode`\@=11
  \chardef\next=\catcode`\&
  \catcode`\&=\active

  \newcount\stanza@count
  \newlength{\stanzaindentbase}
  \setlength{\stanzaindentbase}{20pt}

\def\strip@szacnt#1,#2|{\def\@tempb{#1}\def\@tempa{#2|}}
\newcommand*{\setstanzavalues}[2]{\def\@tempa{#2,,|}%
        \stanza@count\z@
     \def\next{\expandafter\strip@szacnt\@tempa
            \ifx\@tempb\empty\let\next\relax\else
            \expandafter\mathchardef\csname #1@\number\stanza@count
            @\endcsname\@tempb\relax
            \advance\stanza@count\@ne\fi\next}%
      \next}

\newcommand*{\setstanzaindents}[1]{\setstanzavalues{sza}{#1}}
\newcommand*{\setstanzapenalties}[1]{\setstanzavalues{szp}{#1}}

\newcounter{stanzaindentsrepetition}
\newcount\stanza@modulo

\newcommand*{\managestanza@modulo}[0]{
    \advance\stanza@modulo\@ne
    \ifnum\stanza@modulo>\value{stanzaindentsrepetition}
     \stanza@modulo\@ne
    \fi
}
\def\stanza@line{
    \ifnum\value{stanzaindentsrepetition}=0
        \parindent=\csname sza@\number\stanza@count
                 @\endcsname\stanzaindentbase
    \else
        \managestanza@modulo
        \parindent=\csname sza@\number\stanza@modulo
                 @\endcsname\stanzaindentbase
    \fi
    \pstart\stanza@hang\ignorespaces}
\xdef\stanza@hang{\noexpand\leavevmode\noexpand\startlock
            \hangindent\expandafter
            \noexpand\csname sza@0@\endcsname\stanzaindentbase
            \hangafter\@ne}
\def\sza@penalty{\count@\csname szp@\number\stanza@count @\endcsname
         \ifnum\count@>\@M\advance\count@-\@M\penalty-\else
         \penalty\fi\count@}
\let\startstanzahook\relax
\let\endstanzaextra\relax
\xdef\stanza{\noexpand\instanzatrue\expandafter
         \begingroup\startstanzahook%
         \catcode`\&\active\global\stanza@count\@ne\stanza@modulo\@ne
         \noexpand\ifnum\expandafter\noexpand
         \csname sza@0@\endcsname=\z@\let\noexpand\stanza@hang\relax
         \let\noexpand\endlock\relax\noexpand\else\interlinepenalty
         \@M\rightskip\z@ plus 1fil\relax\noexpand\fi\noexpand\ifnum
         \expandafter\noexpand\csname szp@0@\endcsname=\z@
         \let\noexpand\sza@penalty\relax\noexpand\fi \def\noexpand&{%
         \noexpand\endlock\noexpand\pend\noexpand\sza@penalty\global
         \advance\stanza@count\@ne\noexpand\stanza@line}\def\noexpand
         \&{\noexpand\endlock\noexpand\pend\endgroup\noexpand\instanzafalse\expandafter\endstanzaextra}%
         \noexpand\stanza@line}

\newcommand*{\flagstanza}[2][\stanzaindentbase]{%
  \hskip -#1\llap{#2}\hskip #1\ignorespaces}

  \catcode`\&=\next
  \catcode`\@=\body
%%  \let\ampersand=\&
  \setstanzavalues{szp}{0}

\newcommand*{\l@dtabnoexpands}{%
  \let\rtab=0%
  \let\ctab=0%
  \let\ltab=0%
  \let\rtabtext=0%
  \let\ltabtext=0%
  \let\ctabtext=0%
  \let\edbeforetab=0%
  \let\edaftertab=0%
  \let\edatab=0%
  \let\edatabell=0%
  \let\edatleft=0%
  \let\edatright=0%
  \let\edvertline=0%
  \let\edvertdots=0%
  \let\edrowfill=0%
}

\newcount\l@dampcount
  \l@dampcount=1\relax
\newcount\l@dcolcount
  \l@dcolcount=0\relax

\newbox\hilfsbox
\newskip\hilfsskip
\newbox\Hilfsbox
\newcount\hilfscount

\newdimen\dcoli
\newdimen\dcolii
\newdimen\dcoliii
\newdimen\dcoliv
\newdimen\dcolv
\newdimen\dcolvi
\newdimen\dcolvii
\newdimen\dcolviii
\newdimen\dcolix
\newdimen\dcolx
\newdimen\dcolxi
\newdimen\dcolxii
\newdimen\dcolxiii
\newdimen\dcolxiv
\newdimen\dcolxv
\newdimen\dcolxvi
\newdimen\dcolxvii
\newdimen\dcolxviii
\newdimen\dcolxix
\newdimen\dcolxx
\newdimen\dcolxxi
\newdimen\dcolxxii
\newdimen\dcolxxiii
\newdimen\dcolxxiv
\newdimen\dcolxxv
\newdimen\dcolxxvi
\newdimen\dcolxxvii
\newdimen\dcolxxviii
\newdimen\dcolxxix
\newdimen\dcolxxx
\newdimen\dcolerr   % added for error handling

\newcommand{\l@dcolwidth}{\ifcase \the\l@dcolcount \dcoli %???
  \or \dcoli \or \dcolii \or \dcoliii
  \or \dcoliv \or \dcolv \or \dcolvi
  \or \dcolvii \or \dcolviii \or \dcolix \or \dcolx
  \or \dcolxi \or \dcolxii \or \dcolxiii
  \or \dcolxiv \or \dcolxv \or \dcolxvi
  \or \dcolxvii \or \dcolxviii \or \dcolxix \or \dcolxx
  \or \dcolxxi \or \dcolxxii \or \dcolxxiii
  \or \dcolxxiv \or \dcolxxv \or \dcolxxvi
  \or \dcolxxvii \or \dcolxxviii \or \dcolxxix \or \dcolxxx
  \else \dcolerr \fi}

\newcommand*{\stepl@dcolcount}{\advance\l@dcolcount\@ne
  \ifnum\l@dcolcount>30\relax
    \led@err@TooManyColumns
  \fi}

\newcommand{\l@dsetmaxcolwidth}{%
  \ifdim\l@dcolwidth < \wd\hilfsbox
    \l@dcolwidth = \wd\hilfsbox
  \else \relax \fi}

\let\EDTEXT=\edtext
\newcommand{\xedtext}[2]{\EDTEXT{#1}{#2}}
\let\CRITEXT=\critext
\long\def\xcritext #1#2/{\CRITEXT{#1}{#2}/}
\let\EDLABEL=\edlabel
\newcommand*{\xedlabel}[1]{\EDLABEL{#1}}
\let\EDINDEX=\edindex
\ifl@dmemoir
  \newcommand{\xedindex}{\@bsphack%
      \@ifnextchar [{\l@d@index}{\l@d@index[\jobname]}}
  \newcommand{\nulledindex}[2][\jobname]{\@bsphack\@esphack}
\else
  \newcommand{\xedindex}{\@bsphack%
    \doedindexlabel
    \begingroup
    \@sanitize
    \@wredindex}
  \newcommand{\nulledindex}[1]{\@bsphack\@esphack}
\fi

\let\@line@@num=\linenum
\def\l@dgobbledarg #1/{\relax}
\newcommand*{\l@dgobblearg}[1]{\relax}

\let\Relax=\relax
\let\NEXT=\next
\newcount\@hilfs@count

\def\measuremcell #1&{%
    \ifx #1\\ \ifnum\l@dcolcount=0\let\NEXT\relax%
              \else\l@dcheckcols%
                    \l@dcolcount=0%
                    \let\NEXT\measuremcell%
              \fi%
    \else\setbox\hilfsbox=\hbox{$\displaystyle{#1}$}%
      \stepl@dcolcount%
      \l@dsetmaxcolwidth%
      \let\NEXT\measuremcell%
    \fi\NEXT}

\def\measuretcell #1&{%
    \ifx #1\\ \ifnum\l@dcolcount=0\let\NEXT\relax%
              \else\l@dcheckcols%
                    \l@dcolcount=0%
                    \let\NEXT\measuretcell%
              \fi%
    \else\setbox\hilfsbox=\hbox{#1}%
      \stepl@dcolcount%
      \l@dsetmaxcolwidth%
      \let\NEXT\measuretcell%
    \fi\NEXT}

\def\measuremrow #1\\{%
   \ifx #1&\let\NEXT\relax%
   \else\measuremcell #1&\\&\\&%
      \let\NEXT\measuremrow%
   \fi\NEXT}
\def\measuretrow #1\\{%
   \ifx #1&\let\NEXT\relax%
   \else\measuretcell #1&\\&\\&%
     \let\NEXT\measuretrow%
   \fi\NEXT}

\newskip\edtabcolsep
\global\edtabcolsep=10pt

\let\NEXT\relax
\let\Next=\next
\newcommand{\variab}{\relax}

\newcommand*{\l@dcheckcols}{%
  \ifnum\l@dcolcount=1\relax
  \else
    \ifnum\l@dampcount=1\relax
    \else
      \ifnum\l@dcolcount=\l@dampcount\relax
      \else
        \l@d@err@UnequalColumns
      \fi
    \fi
    \l@dampcount=\l@dcolcount
  \fi}

\newcommand{\l@dmodforcritext}{%
  \let\critext\relax%
  \renewcommand{\do}[1]{\global\csletcs{##1footnote}{l@dgobbledarg}}
  \dolistloop{\@series}%
  \let\edindex\nulledindex%
  \let\linenum\@gobble}
\newcommand{\l@drestoreforcritext}{%
  \renewcommand{\do}[1]{\csdef{##1footnote}##1##2/{\csuse{##1@@footnote}{##1}{##2}}}
  \dolistloop{\@series}%
  \let\edindex\xedindex}

\newcommand{\l@dmodforedtext}{%
  \let\edtext\relax
  \renewcommand{\do}[1]{\global\csletcs{##1footnote}{l@dgobblearg}}
  \dolistloop{\@series}%
  \let\edindex\nulledindex
  \let\linenum\@gobble}
\newcommand{\l@drestoreforedtext}{%
  \renewcommand{\do}[1]{\csgdef{##1footnote}##1{\csuse{##1@@footnote}{##1}}}
  \dolistloop{\@series}%
  \let\edindex\xedindex}
\newcommand{\l@dnullfills}{%
  \def\edlabel##1{}%
  \def\edrowfill##1##2##3{}%
}
\newcommand{\l@drestorefills}{%
  \def\edrowfill##1##2##3{\@EDROWFILL@{##1}{##2}{##3}}%
}

\newcommand{\letsforverteilen}{%
  \let\critext\xcritext
  \let\edtext\xedtext
  \let\edindex\xedindex
  \renewcommand{\do}[1]{\global\csletcs{##1footnote}{##1@@footnote}}
  \dolistloop{\@series}%
  \let\linenum\@line@@num
  \hilfsskip=\l@dcolwidth%
  \advance\hilfsskip by -\wd\hilfsbox
  \def\edlabel##1{\xedlabel{##1}}}

\def\setmcellright #1&{\def\edlabel##1{}%
                    \let\edindex\nulledindex
       \ifx #1\\ \ifnum\l@dcolcount=0%\removelastskip
                     \let\Next\relax%
                \else\l@dcolcount=0%
                      \let\Next=\setmcellright%
                \fi%
       \else%
           \disablel@dtabfeet%
           \stepl@dcolcount%
           \setbox\hilfsbox=\hbox{$\displaystyle{#1}$}%
           \letsforverteilen%
           \hskip\hilfsskip$\displaystyle{#1}$%
           \hskip\edtabcolsep%
           \let\Next=\setmcellright%
       \fi\Next}

\def\settcellright #1&{\def\edlabel##1{}%
                        \let\edindex\nulledindex
       \ifx #1\\ \ifnum\l@dcolcount=0%\removelastskip
                    \let\Next\relax%
                \else\l@dcolcount=0%
                      \let\Next=\settcellright%
                \fi%
       \else%
           \disablel@dtabfeet%
           \stepl@dcolcount%
           \setbox\hilfsbox=\hbox{#1}%
           \letsforverteilen%
           \hskip\hilfsskip#1%
           \hskip\edtabcolsep%
           \let\Next=\settcellright%
       \fi\Next}
\def\setmcellleft #1&{\def\edlabel##1{}%
                        \let\edindex\nulledindex
    \ifx #1\\ \ifnum\l@dcolcount=0 \let\Next\relax%
              \else\l@dcolcount=0%
                    \let\Next=\setmcellleft%
              \fi%
     \else   \disablel@dtabfeet%
              \stepl@dcolcount%
              \setbox\hilfsbox=\hbox{$\displaystyle{#1}$}%
              \letsforverteilen
              $\displaystyle{#1}$\hskip\hilfsskip\hskip\edtabcolsep%
              \let\Next=\setmcellleft%
     \fi\Next}

\def\settcellleft #1&{\def\edlabel##1{}%
                        \let\edindex\nulledindex
    \ifx #1\\ \ifnum\l@dcolcount=0 \let\Next\relax%
              \else\l@dcolcount=0%
                    \let\Next=\settcellleft%
              \fi%
     \else   \disablel@dtabfeet%
              \stepl@dcolcount%
              \setbox\hilfsbox=\hbox{#1}%
              \letsforverteilen
              #1\hskip\hilfsskip\hskip\edtabcolsep%
              \let\Next=\settcellleft%
     \fi\Next}
\def\setmcellcenter #1&{\def\edlabel##1{}%
                        \let\edindex\nulledindex
    \ifx #1\\ \ifnum\l@dcolcount=0\let\Next\relax%
             \else\l@dcolcount=0%
                   \let\Next=\setmcellcenter%
             \fi%
    \else    \disablel@dtabfeet%
             \stepl@dcolcount%
             \setbox\hilfsbox=\hbox{$\displaystyle{#1}$}%
             \letsforverteilen%
             \hskip 0.5\hilfsskip$\displaystyle{#1}$\hskip0.5\hilfsskip%
             \hskip\edtabcolsep%
             \let\Next=\setmcellcenter%
     \fi\Next}

\def\settcellcenter #1&{\def\edlabel##1{}%
                        \let\edindex\nulledindex
    \ifx #1\\ \ifnum\l@dcolcount=0 \let\Next\relax%
              \else\l@dcolcount=0%
                    \let\Next=\settcellcenter%
              \fi%
     \else   \disablel@dtabfeet%
              \stepl@dcolcount%
              \setbox\hilfsbox=\hbox{#1}%
              \letsforverteilen%
              \hskip 0.5\hilfsskip #1\hskip 0.5\hilfsskip%
              \hskip\edtabcolsep%
              \let\Next=\settcellcenter%
     \fi\Next}

\let\NEXT=\relax

\def\setmrowright #1\\{%
    \ifx #1& \let\NEXT\relax
    \else \centerline{\setmcellright #1&\\&\\&}
          \let\NEXT=\setmrowright
    \fi\NEXT}
\def\settrowright #1\\{%
    \ifx #1& \let\NEXT\relax
    \else \centerline{\settcellright #1&\\&\\&}
          \let\NEXT=\settrowright
    \fi\NEXT}

\def\setmrowleft #1\\{%
    \ifx #1&\let\NEXT\relax
    \else \centerline{\setmcellleft #1&\\&\\&}
          \let\NEXT=\setmrowleft
    \fi\NEXT}
\def\settrowleft #1\\{%
    \ifx #1& \let\NEXT\relax
    \else \centerline{\settcellleft #1&\\&\\&}
          \let\NEXT=\settrowleft
    \fi\NEXT}

\def\setmrowcenter #1\\{%
    \ifx #1& \let\NEXT\relax%
    \else \centerline{\setmcellcenter #1&\\&\\&}
          \let\NEXT=\setmrowcenter
     \fi\NEXT}
\def\settrowcenter #1\\{%
    \ifx #1& \let\NEXT\relax
    \else \centerline{\settcellcenter #1&\\&\\&}
          \let\NEXT=\settrowcenter
    \fi\NEXT}

\newcommand{\nullsetzen}{%
    \stepl@dcolcount%
    \l@dcolwidth=0pt%
    \ifnum\l@dcolcount=30\let\NEXT\relax%
          \l@dcolcount=0\relax
    \else\let\NEXT\nullsetzen%
    \fi\NEXT}

\newcommand{\edatleft}[3][\@empty]{%
  \ifx#1\@empty
    \vbox to 10pt{\vss\hbox{$\left#2\vrule width0pt height #3
                           depth 0pt \right. $\hss}\vfil}
  \else
    \vbox to 4pt{\vss\hbox{$#1\left#2\vrule width0pt height #3
                depth 0pt \right. $}\vfil}
  \fi}
\newcommand{\edatright}[3][\@empty]{%
  \ifx#1\@empty
    \vbox to 10pt{\vss\hbox{$\left.\vrule width0pt height #3
                depth 0pt \right#2 $\hss}\vfil}
  \else
    \vbox to 4pt{\vss\hbox{$\left.\vrule width0pt height #3
                depth 0pt \right#2 #1 $}\vfil}
  \fi}

\newcommand{\edvertline}[1]{\vbox to 8pt{\vss\hbox{\vrule height #1}\vfil}}

\newcommand{\edvertdots}[1]{\vbox to 1pt{\vss\vbox to #1%
         {\cleaders\hbox{$\m@th\hbox{.}\vbox to 0.5em{ }$}\vfil}}}

\newdimen\edfilldimen
\edfilldimen=0pt

\newcounter{addcolcount}
  \renewcommand{\theaddcolcount}{\roman{addcolcount}}
\newcommand{\l@dtabaddcols}[2]{%
  \l@dcheckstartend{#1}{#2}%
  \ifl@dstartendok
  \setcounter{addcolcount}{#1}%
  \@whilenum \value{addcolcount}<#2\relax \do
  {\advance\edfilldimen by \the \csname dcol\theaddcolcount\endcsname
   \advance\edfilldimen by \edtabcolsep
   \stepcounter{addcolcount}}%
  \advance\edfilldimen by \the \csname dcol\theaddcolcount\endcsname
  \fi
}

\newif\ifl@dstartendok
\newcommand{\l@dcheckstartend}[2]{%
  \l@dstartendoktrue
  \ifnum #1<\@ne
    \l@dstartendokfalse
    \led@err@LowStartColumn
  \fi
  \ifnum #2>30\relax
    \l@dstartendokfalse
    \led@err@HighEndColumn
  \fi
  \ifnum #1>#2\relax
    \l@dstartendokfalse
    \led@err@ReverseColumns
%%%    \eledmac@error{Start column is greater than end column}{\@ehc}%
  \fi
}

\newcommand*{\edrowfill}[3]{%
  \l@dtabaddcols{#1}{#2}%
  \hb@xt@ \the\l@dcolwidth{\hb@xt@ \the\edfilldimen{#3}\hss}}
\let\@edrowfill@=\edrowfill
\def\@EDROWFILL@#1#2#3{\@edrowfill@{#1}{#2}{#3}}

\newcommand{\leftltab}[1]{%
  \hb@xt@\z@{\vbox{\edtabindent%
  \moveleft\Hilfsskip\hbox{\ #1}}\hss}}

\newcommand{\leftrtab}[2]{%
  #2\hb@xt@\z@{\vbox{\edtabindent%
    \advance\Hilfsskip by\dcoli%
    \moveleft\Hilfsskip\hbox{\ #1}}\hss}}

\newcommand{\leftctab}[2]{%
        \hb@xt@\z@{\vbox{\edtabindent\l@dcolcount=\l@dampcount%
        \advance\Hilfsskip by 0.5\dcoli%
        \setbox\hilfsbox=\hbox{\def\edlabel##1{}%
        \disablel@dtabfeet$\displaystyle{#2}$}%
        \advance\Hilfsskip by -0.5\wd\hilfsbox%
        \moveleft\Hilfsskip\hbox{\ #1}}\hss}%
        #2}

\newcommand{\rightctab}[2]{%
        \setbox\hilfsbox=\hbox{\def\edlabel##1{}%
        \disablel@dtabfeet#2}\l@dampcount=\l@dcolcount%
        #1\hb@xt@\z@{\vbox{\edtabindent\l@dcolcount=\l@dampcount%
        \advance\Hilfsskip by 0.5\l@dcolwidth%
        \advance\Hilfsskip by -\wd\hilfsbox%
        \setbox\hilfsbox=\hbox{\def\edlabel##1{}%
        \disablel@dtabfeet$\displaystyle{#1}$}%
        \advance\Hilfsskip by -0.5\wd\hilfsbox%
        \advance\Hilfsskip by \edtabcolsep%
        \moveright\Hilfsskip\hbox{ #2}}\hss}%
        }

\newcommand{\rightltab}[2]{%
        \setbox\hilfsbox=\hbox{\def\edlabel##1{}%
        \disablel@dtabfeet#2}\l@dampcount=\l@dcolcount%
        #1\hb@xt@\z@{\vbox{\edtabindent\l@dcolcount=\l@dampcount%
        \advance\Hilfsskip by\l@dcolwidth%
        \advance\Hilfsskip by-\wd\hilfsbox%
        \setbox\hilfsbox=\hbox{\def\edlabel##1{}%
        \disablel@dtabfeet$\displaystyle{#1}$}%
        \advance\Hilfsskip by-\wd\hilfsbox%
        \advance\Hilfsskip by\edtabcolsep%
        \moveright\Hilfsskip\hbox{ #2}}\hss}%
        }

\newcommand{\rightrtab}[2]{%
        \setbox\hilfsbox=\hbox{\def\edlabel##1{}%
        \disablel@dtabfeet#2}%
        #1\hb@xt@\z@{\vbox{\edtabindent%
        \advance\Hilfsskip by-\wd\hilfsbox%
        \advance\Hilfsskip by\edtabcolsep%
        \moveright\Hilfsskip\hbox{ #2}}\hss}%
        }

\newcommand{\rtab}[1]{%
  \l@dnullfills
    \def\edbeforetab##1##2{\leftrtab{##1}{##2}}%
    \def\edaftertab##1##2{\rightrtab{##1}{##2}}%
    \measurembody{#1}%
  \l@drestorefills
    \variab
    \setmrowright #1\\&\\%
    \enablel@dtabfeet}

\newcommand{\measurembody}[1]{%
  \disablel@dtabfeet%
  \l@dcolcount=0%
  \nullsetzen%
  \l@dcolcount=0
  \measuremrow #1\\&\\%
  \global\l@dampcount=1}

\newcommand{\rtabtext}[1]{%
 \l@dnullfills
    \measuretbody{#1}%
 \l@drestorefills
    \variab
    \settrowright #1\\&\\%
    \enablel@dtabfeet}

\newcommand{\measuretbody}[1]{%
  \disablel@dtabfeet%
  \l@dcolcount=0%
  \nullsetzen%
  \l@dcolcount=0
  \measuretrow #1\\&\\%
  \global\l@dampcount=1}

\newcommand{\ltab}[1]{%
 \l@dnullfills
    \def\edbeforetab##1##2{\leftltab{##1}{##2}}%
    \def\edaftertab##1##2{\rightltab{##1}{##2}}%
    \measurembody{#1}%
  \l@drestorefills
    \variab
    \setmrowleft #1\\&\\%
    \enablel@dtabfeet}

\newcommand{\ltabtext}[1]{%
  \l@dnullfills
    \measuretbody{#1}%
  \l@drestorefills
    \variab
    \settrowleft #1\\&\\%
    \enablel@dtabfeet}

\newcommand{\ctab}[1]{%
  \l@dnullfills
    \def\edbeforetab##1##2{\leftctab{##1}{##2}}%
    \def\edaftertab##1##2{\rightctab{##1}{##2}}%
    \measurembody{#1}%
  \l@drestorefills
    \variab
    \setmrowcenter #1\\&\\%
    \enablel@dtabfeet}

\newcommand{\ctabtext}[1]{%
  \l@dnullfills
    \measuretbody{#1}%
  \l@drestorefills
    \variab
    \settrowcenter #1\\&\\%
    \enablel@dtabfeet}

\newcommand{\spreadtext}[1]{%\l@dcolcount=\l@dampcount%
   \hb@xt@ \the\l@dcolwidth{\hbox{#1}\hss}}
\newcommand{\spreadmath}[1]{%
  \hb@xt@ \the\l@dcolwidth{\hbox{$\displaystyle{#1}$}\hss}}

\def\tabellzwischen #1&{%
     \ifx #1\\ \let\NEXT\relax \l@dcolcount=0
     \else   \stepl@dcolcount%
            \l@dcolwidth = #1 mm
            \let\NEXT=\tabellzwischen
     \fi \NEXT }

\def\edatabell #1\\{%
    \tabellzwischen #1&\\&}
\def\Setzen #1&{%
    \ifx #1\relax \let\NEXT=\relax
    \else \stepl@dcolcount%
          \let\tabelskip=\l@dcolwidth
          \EDTAB #1|
          \let\NEXT=\Setzen
    \fi\NEXT}

\def\EDATAB #1\\{%
    \ifx #1\Relax \centerline{\Setzen #1\relax&}
             \let\Next\relax
    \else \centerline{\Setzen #1&\relax&}
          \let\Next=\EDATAB
    \fi\Next}
\newcommand{\edatab}[1]{%
     \variab%
     \EDATAB #1\\\Relax\\}

\newskip\HILFSskip
\newskip\Hilfsskip

\newcommand{\EDTABINDENT}{%
    \ifnum\l@dcolcount=30\let\NEXT\relax\l@dcolcount=0%
    \else\stepl@dcolcount%
         \advance\Hilfsskip by\l@dcolwidth%
         \ifdim\l@dcolwidth=0pt\advance\hilfscount\@ne
         \else\advance\Hilfsskip by \the\hilfscount\edtabcolsep%
         \hilfscount=1\fi%
         \let\NEXT=\EDTABINDENT%
    \fi\NEXT}%
\newcommand{\edtabindent}{%
    \l@dcolcount=0\relax
    \Hilfsskip=0pt%
    \hilfscount=1\relax
    \EDTABINDENT%
    \hilfsskip=\hsize%
    \advance\hilfsskip -\Hilfsskip%
    \Hilfsskip=0.5\hilfsskip%
    }%

\def\EDTAB #1|#2|{%
    \setbox\tabhilfbox=\hbox{$\displaystyle{#1}$}%
    \setbox\tabHilfbox=\hbox{$\displaystyle{#2}$}%
    \advance\tabelskip -\wd\tabhilfbox%
    \advance\tabelskip -\wd\tabHilfbox%
    \unhbox\tabhilfbox\hskip\tabelskip%
    \unhbox\tabHilfbox}%

\def\EDTABtext #1|#2|{%
    \setbox\tabhilfbox=\hbox{#1}%
    \setbox\tabHilfbox=\hbox{#2}%
    \advance\tabelskip -\wd\tabhilfbox%
    \advance\tabelskip -\wd\tabHilfbox%
    \unhbox\tabhilfbox\hskip\tabelskip%
    \unhbox\tabHilfbox}%
\newbox\tabhilfbox
\newbox\tabHilfbox

\newenvironment{edarrayl}{\l@dcollect@body\ltab}{}
\newenvironment{edarrayc}{\l@dcollect@body\ctab}{}
\newenvironment{edarrayr}{\l@dcollect@body\rtab}{}

\newenvironment{edtabularl}{\l@dcollect@body\ltabtext}{}
\newenvironment{edtabularc}{\l@dcollect@body\ctabtext}{}
\newenvironment{edtabularr}{\l@dcollect@body\rtabtext}{}

\newcommand{\usingcritext}{%
  \def\disablel@dtabfeet{\l@dmodforcritext}%
  \def\enablel@dtabfeet{\l@drestoreforcritext}}
\newcommand{\usingedtext}{%
  \def\disablel@dtabfeet{\l@dmodforedtext}%
  \def\enablel@dtabfeet{\l@drestoreforedtext}}

\usingedtext

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