From 7248b185b2a0837a53d47658c03c23d59af5f91a Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Thu, 3 Oct 2019 22:49:24 +0200
Subject: added hooks to \DeclareApparatus

---
 ekdosis.dtx | 63 +++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 14 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 180e041..bbf23df 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -443,11 +443,21 @@ idno={}, msName={}, origDate={}][3]{%
 % Multi-layer apparatuses
 %    \begin{macrocode}
 \newif\ifekd@mapps
-\NewDocumentCommand{\DeclareApparatus}{m}{
+\newkeycommand+[\|]{\declare@apparatus}[direction={}, rule={},
+bhook={}, ehook={}][1]{%
+  |\luadirect|{%
+    ekdosis.newapparatus(
+    |\luastringN|{#1},
+    |\luastringN|{\commandkey{direction}},
+    |\luastringN|{\commandkey{rule}},
+    |\luastringN|{\commandkey{bhook}},
+    |\luastringN|{\commandkey{ehook}})}
+}
+\NewDocumentCommand{\DeclareApparatus}{m O{}}{
   \newbool{subsq@unit@#1}
   \booltrue{subsq@unit@#1}
   \unless\ifekd@mapps\global\ekd@mappstrue\fi
-  \luadirect{ekdosis.newapparatus(\luastringN{#1})}
+  \declare@apparatus[#2]{#1}
 }
 \@onlypreamble\DeclareApparatus
 %    \end{macrocode}
@@ -661,10 +671,10 @@ idno={}, msName={}, origDate={}][3]{%
       \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
       \fi%
       \current@ref\hskip .25em
-      \ifdefined\ekdlr@alt
+      \ifdefined\ekdlr@alt%
         \ifdefined\ekdlr@post%
           \space\unexpanded\expandafter{\ekdlr@post}\space\else\fi
-        {\textdir TRT\unexpanded\expandafter{\ekdlr@alt}}
+        {\textdir TRT\unexpanded\expandafter{\ekdlr@alt}}%
         \ifdefined\ekdlr@pre%
           \space\unexpanded\expandafter{\ekdlr@pre}\space\else\fi
       \else
@@ -692,13 +702,13 @@ idno={}, msName={}, origDate={}][3]{%
       \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
       \fi%
       \current@ref\hskip .25em
-      \ifdefined\ekdlr@alt
+      \ifdefined\ekdlr@alt%
         \ifdefined\ekdlr@pre%
           \space\unexpanded\expandafter{\ekdlr@pre}\space\else\fi
         \ltx@ifpackageloaded{babel}%
           {\noexpand\selectlanguage{\languagename}%
             \unexpanded\expandafter{\ekdlr@alt}}%
-          {\unexpanded\expandafter{\ekdlr@alt}}
+          {\unexpanded\expandafter{\ekdlr@alt}}%
         \ifdefined\ekdlr@post%
           \space\unexpanded\expandafter{\ekdlr@post}\space\else\fi
       \else
@@ -743,10 +753,10 @@ idno={}, msName={}, origDate={}][3]{%
   \else%
   \ifbool{al@rlmode}{%
     \edef\rdg@app{%
-      \ifdefined\ekdlr@alt
+      \ifdefined\ekdlr@alt%
         \ifdefined\ekdlr@post%
           \space\unexpanded\expandafter{\ekdlr@post}\space\else\fi
-        {\textdir TRT\unexpanded\expandafter{\ekdlr@alt}}
+        {\textdir TRT\unexpanded\expandafter{\ekdlr@alt}}%
         \ifdefined\ekdlr@pre%
           \space\unexpanded\expandafter{\ekdlr@pre}\space\else\fi
       \else
@@ -765,13 +775,13 @@ idno={}, msName={}, origDate={}][3]{%
   }%
   {%
     \edef\rdg@app{%
-      \ifdefined\ekdlr@alt
+      \ifdefined\ekdlr@alt%
         \ifdefined\ekdlr@pre%
           \space\unexpanded\expandafter{\ekdlr@pre}\space\else\fi
         \ltx@ifpackageloaded{babel}%
           {\noexpand\selectlanguage{\languagename}%
             \unexpanded\expandafter{\ekdlr@alt}}%
-          {\unexpanded\expandafter{\ekdlr@alt}}
+          {\unexpanded\expandafter{\ekdlr@alt}}%
         \ifdefined\ekdlr@post%
           \space\unexpanded\expandafter{\ekdlr@post}\space\else\fi
       \else
@@ -1687,14 +1697,18 @@ end
 local apparatuses = {}
 local bagunits = {}
 
-function ekdosis.newapparatus(teitype)
+function ekdosis.newapparatus(teitype, appdir, apprule, appbhook, appehook)
    if isintable(apparatuses, teitype)
    then
       tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
 		   ..teitype..
 		   "\" already exists.}}")
    else
-      table.insert(apparatuses, { a = teitype })
+      table.insert(apparatuses, {a = teitype,
+				 direction = appdir,
+				 rule = apprule,
+				 bhook = appbhook,
+				 ehook = appehook})
    end
    bagunits[teitype] = 1
    return true
@@ -1755,13 +1769,34 @@ function ekdosis.appout()
 	    if string.match(t, "<"..cur_abs_pg.."%-"..n..">.-</"..cur_abs_pg.."%-"..n..">")
 	    then
 	       -- table.insert(output, "BEGIN")
-	       table.insert(output, "\\par\\rule{2truein}{0.5pt}\\newline")
+	       table.insert(output, "\\bgroup{}")
+	       if apparatuses[n].direction ~= ""
+	       then
+		  table.insert(output, apparatuses[n].direction)
+	       else
+	       end
+	       if apparatuses[n].rule ~= ""
+	       then
+		  table.insert(output, "\\par\\mbox{}" .. apparatuses[n].rule .. "\\newline{}")
+	       else
+		  table.insert(output, "\\par\\rule{2truein}{0.5pt}\\newline{}")
+	       end
+	       if apparatuses[n].bhook ~= ""
+	       then
+		  table.insert(output, apparatuses[n].bhook)
+	       else
+	       end
 	       for i in string.gmatch(t,
 				      "<"..cur_abs_pg.."%-"..n..">.-</"..cur_abs_pg.."%-"..n..">")
 	       do
 		  table.insert(output, i)
 	       end
-	       table.insert(output, "\\csname ekd@end@apparatus\\endcsname")
+	       if apparatuses[n].ehook ~= ""
+	       then
+		  table.insert(output, apparatuses[n].ehook)
+	       else
+	       end
+	       table.insert(output, "\\egroup{}")
 	       -- table.insert(output, "END")
 	    end
 	    n = n + 1
-- 
cgit v1.2.3

