From 092c5e178ad7fb8c7eb0ea6b7830839ca5c687a7 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Mon, 30 Sep 2019 20:27:27 +0200
Subject: set different operators for each layer of apparatus. prevent \note
 from going into the .ekd outfile

---
 ekdosis.dtx | 121 ++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 89 insertions(+), 32 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index ab3afbb..aac91f8 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -444,6 +444,8 @@ idno={}, msName={}, origDate={}][3]{%
 %    \begin{macrocode}
 \newif\ifekd@mapps
 \NewDocumentCommand{\DeclareApparatus}{m}{
+  \newbool{subsq@unit@#1}
+  \booltrue{subsq@unit@#1}
   \unless\ifekd@mapps\global\ekd@mappstrue\fi
   \luadirect{ekdosis.newapparatus(\luastringN{#1})}
 }
@@ -514,6 +516,14 @@ idno={}, msName={}, origDate={}][3]{%
 \NewDocumentCommand{\app}{O{} > { \TrimSpaces } +m}{%
   \presetkeys[ekd]{appnote}{type=default}{}%
   \setkeys[ekd]{appnote}{#1}%
+  \ifekd@mapps%
+    \ifnum%
+      \luadirect{tex.sprint(ekdosis.get_bagunits(\luastringO{\ekdan@type}))}
+      = 1
+      \boolfalse{subsq@unit@\ekdan@type}
+    \fi%
+  \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}%
+  \fi%
   \ekd@isinapptrue%
   \stepcounter{ekd@lab}%
   \zlabel{ekd:\theekd@lab}%
@@ -524,7 +534,8 @@ idno={}, msName={}, origDate={}][3]{%
     ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}},
     "pg_ii")}%
   \luadirect{tex.sprint(ekdosis.removesp(\luastringN{#2}))}%
-  \ekd@isinappfalse}
+  \ekd@isinappfalse%
+  \subsq@unittrue}
 \def\current@ref@arg#1#2{{\textdir TLT\noexpand\bfseries%
     \ifnum%
     \getpagerefnumber{#1}
@@ -535,6 +546,18 @@ idno={}, msName={}, origDate={}][3]{%
       =
       \getrefnumber{#2}
       %
+      \ifekd@mapps%
+      \ifbool{subsq@unit@\ekdan@type}{%
+        \ifnum%
+        \getrefnumber{#1}
+        =
+        \getrefnumber{\luadirect{tex.sprint(ekdosis.getprevnotelab())}}
+        \else
+        \getrefnumber{#1}%
+        \fi%
+      }%
+      {\getrefnumber{#1}}
+      \else
       \ifsubsq@unit%
       %
       \ifnum%
@@ -548,6 +571,7 @@ idno={}, msName={}, origDate={}][3]{%
       \else
       \getrefnumber{#1}%
       \fi
+      \fi
       %
       \else
       \getrefnumber{#1}--%
@@ -570,6 +594,17 @@ idno={}, msName={}, origDate={}][3]{%
       =
       \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}
       %
+      \ifekd@mapps%
+      \ifbool{subsq@unit@\ekdan@type}{%
+        \ifnum%
+        \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}
+        =
+        \getrefnumber{\luadirect{tex.sprint(ekdosis.getprevlnlab())}-b}
+        \else
+        \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}%
+        \fi%
+      }{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}
+      \else
       \ifsubsq@unit%
       %
       \ifnum%
@@ -583,6 +618,7 @@ idno={}, msName={}, origDate={}][3]{%
       \else
       \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}%
       \fi
+      \fi
       %
       \else
       \getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}--%
@@ -606,23 +642,25 @@ idno={}, msName={}, origDate={}][3]{%
   \luadirect{ekdosis.dolnlab(\luastringN{#2})}%
   \bgroup%
   \setkeys[ekd]{lemrdg,lem}{#1}%
-  \ifekd@mapps%
-    \ifnum%
-      \luadirect{tex.sprint(ekdosis.get_bagunits(\luastringO{\ekdan@type}))}
-      = 1
-      \subsq@unitfalse%
-    \fi%
-  \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}%
-  \fi%
   \ifekdl@nolem\edef\lem@app{%
-    \hskip .75em\ifsubsq@unit%
-    \unexpanded\expandafter{\ekd@unit@delim}\else\fi%
+    \hskip .75em
+    \ifekd@mapps
+    \ifbool{subsq@unit@\ekdan@type}%
+    {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+    \else%
+    \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
+    \fi%
     \current@ref\hskip .25em}%
   \else%
   \ifbool{al@rlmode}{%
     \edef\lem@app{%
-      \hskip .75em\ifsubsq@unit%
-        \unexpanded\expandafter{\ekd@unit@delim}\else\fi%
+      \hskip .75em
+      \ifekd@mapps
+      \ifbool{subsq@unit@\ekdan@type}%
+      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      \else%
+      \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
+      \fi%
       \current@ref\hskip .25em
       \ifdefined\ekdlr@alt
         \ifdefined\ekdlr@post%
@@ -647,8 +685,13 @@ idno={}, msName={}, origDate={}][3]{%
   }%
   {%
     \edef\lem@app{%
-      \hskip .75em\ifsubsq@unit%
-        \unexpanded\expandafter{\ekd@unit@delim}\else\fi%
+      \hskip .75em
+      \ifekd@mapps
+      \ifbool{subsq@unit@\ekdan@type}%
+      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      \else%
+      \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
+      \fi%
       \current@ref\hskip .25em
       \ifdefined\ekdlr@alt
         \ifdefined\ekdlr@pre%
@@ -683,7 +726,6 @@ idno={}, msName={}, origDate={}][3]{%
   \append@ln@app{\lem@app}%
   \fi%
   \egroup%
-  \subsq@unittrue%
   \ekd@isinlemfalse%
 }
 \NewDocumentCommand{\rdg}{O{} m}{%
@@ -775,7 +817,7 @@ idno={}, msName={}, origDate={}][3]{%
     \ifnum%
       \luadirect{tex.sprint(ekdosis.get_bagunits(\luastringO{\ekdan@type}))}
       = 1
-      \subsq@unitfalse%
+      \boolfalse{subsq@unit@\ekdan@type}
     \fi%
   \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}%
   \fi%  
@@ -786,17 +828,27 @@ idno={}, msName={}, origDate={}][3]{%
     set.}\fi%
   \ifbool{al@rlmode}%
   {\edef\note@contents{%
-    \hskip .75em\ifsubsq@unit%
-    \unexpanded\expandafter{\ekd@unit@delim}\else\fi%
-    \current@ref@arg{\ekdn@labelb}{\ekdn@labele}\hskip .25em%
+      \hskip .75em
+      \ifekd@mapps
+      \ifbool{subsq@unit@\ekdan@type}%
+      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      \else%
+      \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
+      \fi%
+    \current@ref@arg{\ekdn@labelb}{\ekdn@labele}\hskip .25em
       \ifdefined\ekdn@lem%
           {\textdir TRT\unexpanded\expandafter{\ekdn@lem}}%
           \unexpanded\expandafter{\ekdn@sep}\else\fi%
             {\textdir TRT\unexpanded{#2}}}}%
   {\edef\note@contents{%
-    \hskip .75em\ifsubsq@unit%
-    \unexpanded\expandafter{\ekd@unit@delim}\else\fi%
-    \current@ref@arg{\ekdn@labelb}{\ekdn@labele}\hskip .25em%
+      \hskip .75em
+      \ifekd@mapps
+      \ifbool{subsq@unit@\ekdan@type}%
+      {\unexpanded\expandafter{\ekd@unit@delim}}{}%
+      \else%
+      \ifsubsq@unit\unexpanded\expandafter{\ekd@unit@delim}\fi%
+      \fi%
+      \current@ref@arg{\ekdn@labelb}{\ekdn@labele}\hskip .25em
       \ifdefined\ekdn@lem
         \ltx@ifpackageloaded{babel}%
           {\noexpand\selectlanguage{\languagename}%
@@ -829,7 +881,7 @@ idno={}, msName={}, origDate={}][3]{%
   }%
   |\else|%
   |\append@app|{%
-    |\unskip\footnote|{#1}}
+    |\unskip\footnote|{#1}}%
   |\fi|%
 }
 \NewDocumentCommand{\note@app}{s O{} +m}{%
@@ -843,13 +895,13 @@ idno={}, msName={}, origDate={}][3]{%
   }%
 }
 \NewDocumentCommand{\note}{s O{} +m}{%
-  \ifekd@isinapp
-  \ifekd@isinlem
+  \ifekd@isinapp%
+  \ifekd@isinlem%
   \note@noapp[#2]{#3}%
-  \else
+  \else%
   \IfBooleanTF{#1}{\note@app*[#2]{#3}}{\note@app[#2]{#3}}%
-  \fi
-  \else
+  \fi%
+  \else%
   \note@noapp[#2]{#3}%
   \fi%
 }
@@ -881,7 +933,7 @@ idno={}, msName={}, origDate={}][3]{%
 % \fi
 % \StopEventually{}
 % \Finale
-% \iffalse `'
+% \iffalse
 %<*lua>
 % \fi
 % \begin{ekdlua}
@@ -1740,6 +1792,11 @@ function ekdosis.getprevnotelab()
    return prev_notelab
 end
 
+local function remove_note(str)
+   str = gsub(str, dblbkslash * lpeg.P("note") * cmdargs, "")
+   return str
+end
+
 function ekdosis.mdvappend(str, teitype)
    if teitype == nil
    then
@@ -1750,7 +1807,7 @@ function ekdosis.mdvappend(str, teitype)
       "\\linelabel{" .. current_lnlab .. "-e}"
       ..
       "\\csname append@app\\endcsname{"
-      .. str .. "}"
+      .. remove_note(str) .. "}"
    else
    return "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
       ..
@@ -1759,7 +1816,7 @@ function ekdosis.mdvappend(str, teitype)
       "\\linelabel{" .. current_lnlab .. "-e}"
       ..
       "\\csname append@app\\endcsname" .. "[" .. teitype ..  "]{"
-      .. str .. "}"
+      .. remove_note(str) .. "}"
    end
 end
 
-- 
cgit v1.2.3

