From 6d53e3356c1d8d7ce41d656f455aed3f6a7ba5b0 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Fri, 4 Oct 2019 17:31:09 +0200
Subject: corrected expansion inside hooks, added hook for unit delimiter

---
 ekdosis.dtx | 74 +++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 19 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index bbf23df..fb80c1a 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -443,13 +443,15 @@ idno={}, msName={}, origDate={}][3]{%
 % Multi-layer apparatuses
 %    \begin{macrocode}
 \newif\ifekd@mapps
-\newkeycommand+[\|]{\declare@apparatus}[direction={}, rule={},
-bhook={}, ehook={}][1]{%
+\newkeycommand+[\|]{\declare@apparatus}[enum direction={LR,RL}, rule={},
+  delim={}, bhook={},
+  ehook={\csname ekd@end@apparatus\endcsname}][1]{%
   |\luadirect|{%
     ekdosis.newapparatus(
     |\luastringN|{#1},
     |\luastringN|{\commandkey{direction}},
     |\luastringN|{\commandkey{rule}},
+    |\luastringN|{\commandkey{delim}},
     |\luastringN|{\commandkey{bhook}},
     |\luastringN|{\commandkey{ehook}})}
 }
@@ -484,12 +486,19 @@ bhook={}, ehook={}][1]{%
 \newif\ifrtl@app
 \NewDocumentCommand{\SetRTLapp}{}{\rtl@apptrue}
 \NewDocumentCommand{\SetLTRapp}{}{\rtl@appfalse}
-\edef\ekdsep{: }
+\edef\ekdsep{] }
 \NewDocumentCommand{\SetSeparator}{m}{\edef\ekdsep{#1}}
 \edef\ekd@end@apparatus{}
 \NewDocumentCommand{\SetEndApparatus}{m}{\edef\ekd@end@apparatus{#1}}
 \def\ekd@unit@delim{}
 \NewDocumentCommand{\SetUnitDelimiter}{m}{\def\ekd@unit@delim{#1}}
+\def\ekd@default@rule{\rule{2truein}{0.5pt}}
+\NewDocumentCommand{\SetDefaultRule}{m}{%
+  \def\@tempa{#1}
+  \ifx\@tempa\empty\def\ekd@default@rule{\mbox{}}%
+  \else%
+  \def\ekd@default@rule{#1}%
+  \fi}
 \newif\ifsubsq@unit
 \subsq@unittrue
 \def\add@@apparatus{%
@@ -503,7 +512,8 @@ bhook={}, ehook={}][1]{%
     \footnotesize\apparatus\unless\ifekd@mapps\ekd@end@apparatus\fi%
     \if@pkg@parnotes\parnotes\parnotereset\else\fi%
   }%
-  \unless\ifekd@mapps\unconditional@appin{\rule{2truein}{0.5pt}\newline}\fi
+  \unless\ifekd@mapps\unconditional@appin{%
+    \expandafter{\ekd@default@rule}\newline}\fi
 }
 \def\add@apparatus{%
   \test@apparatus%
@@ -645,17 +655,19 @@ bhook={}, ehook={}][1]{%
   \setkeys[ekd]{lemrdg,lem}{#1}%
   \ifekd@mapps%
     \ifnum%
-      \luadirect{tex.sprint(ekdosis.get_bagunits(\luastringO{\ekdan@type}))}
-      = 1
-      \boolfalse{subsq@unit@\ekdan@type}%
+    \luadirect{tex.sprint(ekdosis.get_bagunits(\luastringO{\ekdan@type}))}
+    = 1
+    \boolfalse{subsq@unit@\ekdan@type}%
     \fi%
-  \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}%
+    \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}%
+    \def\ekd@munit@delim{%
+      \luadirect{tex.sprint(ekdosis.getappdelim(\luastringO{\ekdan@type}))}}%
   \fi%
   \ifekdl@nolem\edef\lem@app{%
     \hskip .75em
     \ifekd@mapps
     \ifbool{subsq@unit@\ekdan@type}%
-    {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+    {\expandafter\noexpand\ekd@munit@delim}{}%
     \else%
     \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
     \fi%
@@ -666,7 +678,7 @@ bhook={}, ehook={}][1]{%
       \hskip .75em
       \ifekd@mapps
       \ifbool{subsq@unit@\ekdan@type}%
-      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      {\expandafter\noexpand\ekd@munit@delim}{}%
       \else%
       \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
       \fi%
@@ -697,7 +709,7 @@ bhook={}, ehook={}][1]{%
       \hskip .75em
       \ifekd@mapps
       \ifbool{subsq@unit@\ekdan@type}%
-      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      {\expandafter\noexpand\ekd@munit@delim}{}%
       \else%
       \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
       \fi%
@@ -830,6 +842,8 @@ bhook={}, ehook={}][1]{%
       \boolfalse{subsq@unit@\ekdan@type}%
     \fi%
   \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}%
+    \def\ekd@munit@delim{%
+      \luadirect{tex.sprint(ekdosis.getappdelim(\luastringO{\ekdan@type}))}}%
   \fi%  
   \ifdefined\ekdn@labelb%
     \luadirect{tex.sprint(ekdosis.setnotelab(\luastringO{\ekdn@labelb}))}%
@@ -841,7 +855,7 @@ bhook={}, ehook={}][1]{%
       \hskip .75em
       \ifekd@mapps
       \ifbool{subsq@unit@\ekdan@type}%
-      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      {\expandafter\noexpand\ekd@munit@delim}{}%
       \else%
       \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
       \fi%
@@ -854,7 +868,7 @@ bhook={}, ehook={}][1]{%
       \hskip .75em
       \ifekd@mapps
       \ifbool{subsq@unit@\ekdan@type}%
-      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      {\expandafter\noexpand\ekd@munit@delim}{}%
       \else%
       \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
       \fi%
@@ -1697,7 +1711,12 @@ end
 local apparatuses = {}
 local bagunits = {}
 
-function ekdosis.newapparatus(teitype, appdir, apprule, appbhook, appehook)
+function ekdosis.newapparatus(teitype,
+			      appdir,
+			      apprule,
+			      appdelim,
+			      appbhook,
+			      appehook)
    if isintable(apparatuses, teitype)
    then
       tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
@@ -1707,6 +1726,7 @@ function ekdosis.newapparatus(teitype, appdir, apprule, appbhook, appehook)
       table.insert(apparatuses, {a = teitype,
 				 direction = appdir,
 				 rule = apprule,
+				 delim = appdelim,
 				 bhook = appbhook,
 				 ehook = appehook})
    end
@@ -1714,6 +1734,17 @@ function ekdosis.newapparatus(teitype, appdir, apprule, appbhook, appehook)
    return true
 end
 
+function ekdosis.getappdelim(str)
+   for i = 1,#apparatuses
+   do
+      if apparatuses[i].a == str then
+	 delimfound = apparatuses[i].delim
+	 break
+      end
+   end
+   return delimfound
+end
+
 function ekdosis.get_bagunits(teitype)
    return bagunits[teitype]
 end
@@ -1770,16 +1801,21 @@ function ekdosis.appout()
 	    then
 	       -- table.insert(output, "BEGIN")
 	       table.insert(output, "\\bgroup{}")
-	       if apparatuses[n].direction ~= ""
+	       if apparatuses[n].direction == "LR"
 	       then
-		  table.insert(output, apparatuses[n].direction)
-	       else
+		  table.insert(output, "\\pardir TLT\\textdir TLT{}")
+	       elseif apparatuses[n].direction == "RL"
+	       then
+		  table.insert(output, "\\pardir TRT\\textdir TRT{}")
 	       end
-	       if apparatuses[n].rule ~= ""
+	       if apparatuses[n].rule == "none"
+	       then
+		  table.insert(output, "\\par\\mbox{}\\newline{}")
+	       elseif apparatuses[n].rule ~= ""
 	       then
 		  table.insert(output, "\\par\\mbox{}" .. apparatuses[n].rule .. "\\newline{}")
 	       else
-		  table.insert(output, "\\par\\rule{2truein}{0.5pt}\\newline{}")
+		  table.insert(output, "\\par\\csname ekd@default@rule\\endcsname\\newline{}")
 	       end
 	       if apparatuses[n].bhook ~= ""
 	       then
-- 
cgit v1.2.3

