From abe62902304bebf9b483592f51ac734d15077013 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Fri, 28 Jul 2023 15:47:53 +0200
Subject: a bit of tidy up in the code

---
 ekdosis.dtx | 361 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 201 insertions(+), 160 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 0d7d805..4e01f26 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -538,7 +538,7 @@ Alessi <alessi@robertalessi.net>
 \end{filecontents}
 \begin{filecontents}[overwrite]{\jobname-ekd.cfg}
 %% ekdosis:---
-\footnotelayout{m}
+\SetFootnotes{arrangement=merge}
 \SetCritSymbols{suppbegin = ⟨,suppend = ⟩}
 \EnvtoTEI{ancientgreek}{p}[xml:lang="grc"]
 \DeclareApparatus{fontium}[
@@ -4616,7 +4616,7 @@ argument of the
 %     them.}
 %   \end{specimen}
 % \end{alignment}
-% \SetFootnotes{reset}
+% \SetFootnotes{arangement=merge}
 % 
 % \texttt{TEI xml} output:---
 %
@@ -9715,192 +9715,233 @@ Sample text with a \textcolor{red}{word} in red.
 % line label\---which are manually inserted---and returns the formatted
 % reference to be inserted in the apparatus criticus.
 %    \begin{macrocode}
-\def\current@ref@arg#1#2{{%\textdir TLT%
-    \unexpanded\expandafter{\ekd@refnumstyle}%
-    \ifnum%
+\def\current@ref@arg#1#2{
+  \bgroup %\textdir TLT%
+  \unexpanded\expandafter{\ekd@refnumstyle}%
+  \ifnum
     \pdf@strcmp{\getpagerefnumber{#1}}{\getpagerefnumber{#2}}
     =
     0
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{#1}}{\getrefnumber{#2}}
-    =
-    0
-    %
-    \ifekd@mapps%
-    \ifbool{subsq@unit@\ekdan@type}{%
-      \ifnum%
-      \pdf@strcmp{\getrefnumber{#1}}{%
-        \getrefnumber{\luadirect{tex.sprint(ekdosis.getprevnotelab())}}}
+    \ifnum
+      \pdf@strcmp{\getrefnumber{#1}}{\getrefnumber{#2}}
       =
       0
+      % 
+      \ifekd@mapps
+        \ifbool{subsq@unit@\ekdan@type}{%
+            \ifnum
+              \pdf@strcmp{\getrefnumber{#1}}{%
+                \getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getprevnotelab())}}}
+              =
+              0
+            \else
+              \LRnum{\getrefnumber{#1}}%
+              \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+            \fi
+          }%
+          {\LRnum{\getrefnumber{#1}}%
+            \unexpanded\expandafter{\ekd@postrefnum}}% issue the no
       \else
-      \LRnum{\getrefnumber{#1}}\unexpanded\expandafter{\ekd@postrefnum}% issue the no
-      \fi%
-    }%
-    {\LRnum{\getrefnumber{#1}}\unexpanded\expandafter{\ekd@postrefnum}}% issue the no
-    \else
-    \ifsubsq@unit%
-    %
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{#1}}{%
-      \getrefnumber{\luadirect{tex.sprint(ekdosis.getprevnotelab())}}}
-    =
-    0
-    \else
-    \LRnum{\getrefnumber{#1}}\unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    %
-    \else
-    \LRnum{\getrefnumber{#1}}\unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    \fi
-    %
+        \ifsubsq@unit
+          % 
+          \ifnum
+            \pdf@strcmp{\getrefnumber{#1}}{%
+              \getrefnumber{\luadirect{tex.sprint(
+                  ekdosis.getprevnotelab())}}}
+            =
+            0
+          \else
+            \LRnum{\getrefnumber{#1}}%
+            \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+          \fi
+          % 
+        \else
+          \LRnum{\getrefnumber{#1}}%
+          \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+        \fi
+      \fi
+      % 
     \else
-    \ifekd@elidednumbers
-    \luadirect{tex.sprint(ekdosis.numrange(\luastring{\getrefnumber{#1}},
-      \luastring{\getrefnumber{#2}}))}%
+      \ifekd@elidednumbers
+        \luadirect{tex.sprint(
+          ekdosis.numrange(\luastring{\getrefnumber{#1}},
+          \luastring{\getrefnumber{#2}}))}%
         \unexpanded\expandafter{\ekd@postrefnum}% issue the nos
-    \else
-    \LRnum{\getrefnumber{#1}}--%
-    \LRnum{\getrefnumber{#2}}\unexpanded\expandafter{\ekd@postrefnum}% issue the nos
+      \else
+        \LRnum{\getrefnumber{#1}}--\LRnum{\getrefnumber{#2}}%
+        \unexpanded\expandafter{\ekd@postrefnum}% issue the nos
+      \fi
     \fi
-    \fi%
-    \else
+  \else
     \ifboolexpr{bool {ekd@pagelineation} or bool {ekd@pagevlineation}}
       {\LRnum{\getrefnumber{#1}}--%
-      \LRnum{\getpagerefnumber{#2}}.%
-      \LRnum{\getrefnumber{#2}}\unexpanded\expandafter{\ekd@postrefnum}}% issue pg and ln nos
-      {\LRnum{\getrefnumber{#1}}--%
-      \LRnum{\getrefnumber{#2}}\unexpanded\expandafter{\ekd@postrefnum}}% issue the nos
-    \fi%
-    \ifekdn@forcenum
-      \LRnum{\getrefnumber{#1}}\unexpanded\expandafter{\ekd@postrefnum}% force the no
-    \fi
-  }%
+        \LRnum{\getpagerefnumber{#2}}.%
+        \LRnum{\getrefnumber{#2}}%
+        \unexpanded\expandafter{\ekd@postrefnum}}% issue pg and ln nos
+      {\LRnum{\getrefnumber{#1}}--\LRnum{\getrefnumber{#2}}%
+        \unexpanded\expandafter{\ekd@postrefnum}}% issue the nos
+  \fi
+  \ifekdn@forcenum
+    \LRnum{\getrefnumber{#1}}%
+    \unexpanded\expandafter{\ekd@postrefnum}% force the no
+  \fi
+  \egroup
 }
 %    \end{macrocode}
 % \cs{current@ref} is pretty much the same as \cs{current@reg@arg},
 % but takes no argument. It is used by commands such as \cs{lem} when
 % references to page and line numbers can be returned by \textsf{Lua}.
 %    \begin{macrocode}
-\def\current@ref{{%\textdir TLT%
-    \unexpanded\expandafter{\ekd@refnumstyle}%
-    \ifnum%
+\def\current@ref{%
+  \bgroup %\textdir TLT%
+  \unexpanded\expandafter{\ekd@refnumstyle}%
+  \ifnum % if the whole lemma falls on the same page...
     \pdf@strcmp{%
       \getpagerefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      {\getpagerefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}
+    {\getpagerefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}
     =
     0
-    \ifnum%
-    \pdf@strcmp{%
-      \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
+    \ifnum % ... and on the same line
+      \pdf@strcmp{%
+        \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
       {\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}
-    =
-    0
-    %
-    \ifekd@mapps%
-    \ifbool{subsq@unit@\ekdan@type}{%
-      \ifnum%
-      \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      {\getrefnumber{\luadirect{tex.sprint(ekdosis.getprevlnlab())}-b}}
       =
       0
-    %%%begin
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}%
-    {\getrefnumber{\luadirect{tex.sprint(ekdosis.getprevlnlab())}-e}}
-    =
-    0
-    \ifekd@appinapp
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-    {\getrefnumber{\luadirect{tex.sprint(ekdosis.getprevprevlnlab())}-b}}
-    =
-    0
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    \fi
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    %%% end
+      % 
+      \ifekd@mapps % then, if multiple layers have been defined...
+        \ifbool{subsq@unit@\ekdan@type}{%
+            \ifnum
+              \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getlnlab())}-b}}%
+              {\getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getprevlnlab())}-b}}
+              =
+              0
+              %%% begin
+              \ifnum
+                \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(
+                      ekdosis.getlnlab())}-e}}%
+                {\getrefnumber{\luadirect{tex.sprint(
+                      ekdosis.getprevlnlab())}-e}}
+                =
+                0
+                \ifekd@appinapp
+                  \ifnum
+                    \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(
+                          ekdosis.getlnlab())}-b}}%
+                    {\getrefnumber{\luadirect{tex.sprint(
+                          ekdosis.getprevprevlnlab())}-b}}
+                    =
+                    0
+                  \else
+                    \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                          ekdosis.getlnlab())}-b}}%
+                    \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+                  \fi
+                \fi
+              \else
+                \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                      ekdosis.getlnlab())}-b}}%
+                \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+              \fi
+              %%% end
+            \else
+              \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getlnlab())}-b}}%
+              \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+            \fi
+          }{\LRnum{\getrefnumber{\luadirect{tex.sprint(
+                  ekdosis.getlnlab())}-b}}%
+            \unexpanded\expandafter{\ekd@postrefnum}}% issue the no
       \else
-      \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-        \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-      \fi%
-    }{\LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}}% issue the no
-    \else
-    \ifsubsq@unit%
-    %
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-    {\getrefnumber{\luadirect{tex.sprint(ekdosis.getprevlnlab())}-b}}
-    =
-    0
-    %%%begin
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}%
-    {\getrefnumber{\luadirect{tex.sprint(ekdosis.getprevlnlab())}-e}}
-    =
-    0
-    \ifekd@appinapp
-    \ifnum%
-    \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-    {\getrefnumber{\luadirect{tex.sprint(ekdosis.getprevprevlnlab())}-b}}
-    =
-    0
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    \fi
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    %%% end
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    %
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% issue the no
-    \fi
-    \fi
-    %
+        \ifsubsq@unit
+          % 
+          \ifnum
+            \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(
+                  ekdosis.getlnlab())}-b}}%
+            {\getrefnumber{\luadirect{tex.sprint(
+                  ekdosis.getprevlnlab())}-b}}
+            =
+            0
+            %%% begin
+            \ifnum
+              \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getlnlab())}-e}}%
+              {\getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getprevlnlab())}-e}}
+              =
+              0
+              \ifekd@appinapp
+                \ifnum
+                  \pdf@strcmp{\getrefnumber{\luadirect{tex.sprint(
+                        ekdosis.getlnlab())}-b}}%
+                  {\getrefnumber{\luadirect{tex.sprint(
+                        ekdosis.getprevprevlnlab())}-b}}
+                  =
+                  0
+                \else
+                  \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                        ekdosis.getlnlab())}-b}}%
+                  \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+                \fi
+              \fi
+            \else
+              \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                    ekdosis.getlnlab())}-b}}%
+              \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+            \fi
+            %%% end
+          \else
+            \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                  ekdosis.getlnlab())}-b}}%
+            \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+          \fi
+          % 
+        \else
+          \LRnum{\getrefnumber{\luadirect{tex.sprint(
+                ekdosis.getlnlab())}-b}}%
+          \unexpanded\expandafter{\ekd@postrefnum}% issue the no
+        \fi
+      \fi
+      % 
     \else
-    \ifekd@elidednumbers
-    \luadirect{tex.sprint(ekdosis.numrange(
-      \luastring{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}},
-      \luastring{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}))}%
+      \ifekd@elidednumbers
+        \luadirect{tex.sprint(ekdosis.numrange(
+          \luastring{\getrefnumber{\luadirect{tex.sprint(
+                ekdosis.getlnlab())}-b}},
+          \luastring{\getrefnumber{\luadirect{tex.sprint(
+                ekdosis.getlnlab())}-e}}))}%
         \unexpanded\expandafter{\ekd@postrefnum}% issue the nos
-    \else
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}--%
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}%
+      \else
+        \LRnum{\getrefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-b}}--%
+        \LRnum{\getrefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-e}}%
         \unexpanded\expandafter{\ekd@postrefnum}% issue the nos
+      \fi
     \fi
-    \fi%
-    \else
+  \else
     \ifboolexpr{bool {ekd@pagelineation} or bool {ekd@pagevlineation}}
-      {\LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}--%
-      \LRnum{\getpagerefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}.%
-      \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}%
+      {\LRnum{\getrefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-b}}--%
+        \LRnum{\getpagerefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-e}}.%
+        \LRnum{\getrefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-e}}%
         \unexpanded\expandafter{\ekd@postrefnum}}% issue pg and ln nos
-      {\LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}--%
-      \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}%
+      {\LRnum{\getrefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-b}}--%
+        \LRnum{\getrefnumber{\luadirect{tex.sprint(
+              ekdosis.getlnlab())}-e}}%
         \unexpanded\expandafter{\ekd@postrefnum}}% issue the nos
-    \fi%
-    \ifekdl@forcenum
-    \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}%
-      \unexpanded\expandafter{\ekd@postrefnum}% force the no
-    \fi
-  }%
+  \fi
+  \ifekdl@forcenum
+    \LRnum{\getrefnumber{\luadirect{tex.sprint(
+          ekdosis.getlnlab())}-b}}%
+    \unexpanded\expandafter{\ekd@postrefnum}% force the no
+  \fi
+  \egroup
 }
 %    \end{macrocode}
 % Define keys to be used by the optional arguments of \cs{lem} and
@@ -10463,17 +10504,17 @@ Sample text with a \textcolor{red}{word} in red.
 \ekvdefinekeys{ekd@footnotes}{
   choice arrangement = {
     column = \unless\ifekd@alignmentstarted
-             \footnotelayout{c}\fi,
+             \pcol@fnlayout@c\fi,
     page = \unless\ifekd@alignmentstarted
-             \footnotelayout{p}\fi,
+             \pcol@fnlayout@p\fi,
     merge = \unless\ifekd@alignmentstarted
-              \footnotelayout{m}\fi},
+              \pcol@fnlayout@m\fi},
   unknown-choice arrangement = \PackageError{ekdosis}{unknown
     arrangement=#1}{`arrangement' must be either `column',
     `page' or `merge'.},
   noval reset = \ekd@parafootnotesfalse
                 \unless\ifekd@alignmentstarted
-                \footnotelayout{c}\fi,
+                \pcol@fnlayout@c\fi,
   bool paragraph = \ifekd@parafootnotes,
   store type = \ekdfn@type,
   initial type = default,
-- 
cgit v1.2.3

