From c358fe9c92ce563f32134fc5a9ed4bfdeab00fe3 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Thu, 12 Sep 2019 12:47:53 +0200
Subject: rewrote testapparatus() and \test@pparatus; removed unnecessary
 booleans

---
 ekdosis.dtx | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index ef3fd93..941ceed 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -449,7 +449,6 @@ idno={}, msName={}, origDate={}][3]{%
 \@onlypreamble\SetxmlBibResource
 %    \end{macrocode}
 %    \begin{macrocode}
-\newbool{ekd@started}
 \newbool{do@app}
 \newbool{ekd@state}
 \newif\ifekd@isinapp
@@ -494,10 +493,8 @@ idno={}, msName={}, origDate={}][3]{%
   \unconditional@appin{\rule{5cm}{0.5pt}\newline}
 }
 \def\add@apparatus{%
-  \notbool{ekd@started}{\subsq@unitfalse\add@@apparatus%
-    \global\setbool{ekd@started}{true}}
-  {\test@apparatus%
-    \ifbool{do@app}{\subsq@unitfalse\add@@apparatus}{}}%
+  \test@apparatus%
+  \ifbool{do@app}{\subsq@unitfalse\add@@apparatus}{}%
 }
 \NewDocumentCommand{\append@app}{+m}{%
   \ifekd@isinapp%
@@ -516,10 +513,12 @@ idno={}, msName={}, origDate={}][3]{%
   \ekd@isinapptrue%
   \stepcounter{ekd@lab}%
   \zlabel{ekd:\theekd@lab}%
+  \luadirect{ekdosis.storeabspg(
+    \luastring{\zref@extract{ekd:\theekd@lab}{abspage}})}%
+  \ifbool{ekd@state}{\add@apparatus}{}%
   \luadirect{%
     ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}},
     "pg_ii")}%
-  \ifbool{ekd@state}{\add@apparatus}{}%
   \luadirect{tex.sprint(ekdosis.removesp(\luastringN{#1}))}%
   \ekd@isinappfalse}
 \def\current@ref{{\textdir TLT\noexpand\bfseries%
@@ -732,8 +731,7 @@ idno={}, msName={}, origDate={}][3]{%
 }
 \NewDocumentEnvironment{ekdosis}{+b}{%
   \begin{linenumbers}
-    \ifbool{ekd@started}{}%
-    {\EkdosisStart}
+    \EkdosisStart
     \EkdosisOn#1}{%
     \EkdosisOff
   \end{linenumbers}%
@@ -1360,7 +1358,7 @@ function ekdosis.update_abspg(n)
 end
 
 function ekdosis.get_abs_page()
-   return cur_abs_pg
+   return "i:" .. pg_i .. ", ii:" .. pg_ii .. ", abs:" .. cur_abs_pg
 end
 
 function ekdosis.storeabspg(n, pg)
@@ -1419,13 +1417,15 @@ function ekdosis.appout()
 end
 
 function ekdosis.testapparatus()
-   if tonumber(pg_ii) == tonumber(pg_i) then
+   if tonumber(pg_ii) < tonumber(pg_i)
+   or tonumber(pg_ii) < tonumber(cur_abs_pg) then
+      pg_i = cur_abs_pg
+      return "\\booltrue{do@app}"
+   elseif tonumber(pg_ii) == tonumber(pg_i) then
       return "\\boolfalse{do@app}"
    elseif tonumber(pg_ii) > tonumber(pg_i) then
-      pg_i = pg_ii
+      pg_i = cur_abs_pg
       return "\\booltrue{do@app}"
-   else
-      return "\\boolfalse{do@app}"
    end
 end
 
-- 
cgit v1.2.3

