From 4be162d76a3e4fa3450f685f0d2291dbb34a7bdd Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Wed, 1 Apr 2020 10:40:35 +0200
Subject: make \resetlinenumber work over columns which don't cross page
 boudaries

---
 ekdosis.dtx | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 56 insertions(+), 15 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 0c3b6e2..aadd46b 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -1046,9 +1046,8 @@ Running "make install" installs the files in the local TeX tree.
   \luadirect{tex.sprint(ekdosis.appout())}}
 \NewDocumentCommand{\test@apparatus}{}{%
   \luadirect{tex.sprint(ekdosis.testapparatus())}}
-\NewDocumentCommand{\EkdosisStart}{}{%
-  \stepcounter{ekd@lab}%
-  \zlabel{ekd:\theekd@lab}%
+\NewDocumentCommand{\ekd@storecol}{}{%
+  \luadirect{ekdosis.storecurcol(\luastring{\thecolumn})}%
 }
 \NewDocumentCommand{\EkdosisOn}{}{%
   \ekd@statetrue}
@@ -1064,11 +1063,12 @@ Running "make install" installs the files in the local TeX tree.
 }
 \NewDocumentEnvironment{ekdosis}{+b}{%
   \ekd@setlineno%
-  \begin{runninglinenumbers}
-    \EkdosisStart
+  \runninglinenumbers
+    % \EkdosisStart
     \EkdosisOn#1}{%
     \EkdosisOff
-  \end{runninglinenumbers}%
+    % \EkdosisStop
+  \endrunninglinenumbers%
   \iftei@export\luadirect{ekdosis.exporttei(\luastringN{#1})}\else\fi}
 %    \end{macrocode}
 % Alignment:---
@@ -1088,13 +1088,28 @@ Running "make install" installs the files in the local TeX tree.
 \NewDocumentCommand{\SetEkdosisAlignment}{m}{
   \ekvset{ekd@align}{#1}
 }
-\NewDocumentCommand{\ekd@storecol}{m}{%
-  \luadirect{ekdosis.storecurcol(\luastring{\thecolumn})}%
-}
 \patchcmd{\pcol@nextpage}{%
   \endgroup}{%
   \ifekd@pagelineation\resetlinenumber\fi
   \endgroup}{}{}
+\NewDocumentCommand{\EkdosisStart}{}{%
+  \ekd@storecol%
+  \stepcounter{ekd@lab}%
+  \zlabel{ekd:\theekd@lab}%
+  \luadirect{%
+    ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}},
+    "pg_i")}%
+  \ifekd@pagelineation
+    \luadirect{tex.sprint(ekdosis.checkresetlineno())}
+  \fi
+}
+\NewDocumentCommand{\EkdosisStop}{}{%
+  \stepcounter{ekd@lab}%
+  \zlabel{ekd:\theekd@lab}%
+  \luadirect{%
+    ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}},
+    "pg_ii")}%
+}
 \NewDocumentEnvironment{alignment}{O{}}
 {%
   \ekvset{ekd@align}{#1}%
@@ -1913,17 +1928,38 @@ function ekdosis.closestream()
 end
 
 local cur_abs_pg = 0
+local pg_i = nil
+local pg_ii = nil
+local prevcol = nil
+local curcol = "x"
+
+local check_resetlineno = {}
 
 function ekdosis.update_abspg(n)
    cur_abs_pg = n
    return true
 end
 
-function ekdosis.storeabspg(n)
+function ekdosis.storeabspg(n, pg)
+   if pg == "pg_i" then
+      pg_i = n
+   elseif pg == "pg_ii" then
+      pg_ii = n
+      table.insert(check_resetlineno, curcol.."-"..pg_ii)
+   end
    cur_abs_pg = n
    return true
 end
 
+function ekdosis.checkresetlineno()
+   if isfound(check_resetlineno, curcol.."-"..pg_i)
+   then
+      return ""
+   else
+      return "\\resetlinenumber"
+   end
+end
+
 --
 -- Build environments to be aligned
 --
@@ -1955,8 +1991,9 @@ function ekdosis.mkenvdata(str, opt)
    end
 end
 
-local prevcol = nil
-local curcol = "x"
+-- the following two variables are already set above
+-- local prevcol = nil
+-- local curcol = "x"
 
 function ekdosis.storecurcol(n)
       curcol = n
@@ -1983,18 +2020,22 @@ function ekdosis.mkenv()
       then
 	 table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."}{}"
 			 .."{\\begin{nthcolumn}{".. aligned_texts[i].column.."}"
-		         .."\\begin{ekdosis}"
-		         .."\\csname ekd@storecol\\endcsname{\\thecolumn}"
+			 .."\\EkdosisStart"
+			 .."\\begin{ekdosis}"
+--		         .."\\csname ekd@storecol\\endcsname"
 			 .."\\par"
 		         .."}{\\end{ekdosis}"
+			 .."\\EkdosisStop"
 			 .."\\end{nthcolumn}}")
 	 table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."*}{}"
 			 .."{\\begin{nthcolumn*}{".. aligned_texts[i].column.."}[]"
+			 .."\\EkdosisStart"
 		         .."\\begin{ekdosis}"
-		         .."\\csname ekd@storecol\\endcsname{\\thecolumn}"
+--		         .."\\csname ekd@storecol\\endcsname"
 			 .."\\par"
 		         .."}{"
 		         .."\\end{ekdosis}"
+			 .."\\EkdosisStop"
 			 .."\\end{nthcolumn*}}")
       else
 	 table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."}{}"
-- 
cgit v1.2.3

