From dbe3fc48b63e793a72baa585ead8e1ad18fbb213 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Fri, 25 Oct 2019 17:57:54 +0200
Subject: make 3rd argument of TeX|EnvtoTei optional; nullify nullify TEI tag
 if arg2 is void

---
 ekdosis.dtx | 51 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 20 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 105dea3..d5c6bd5 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -355,7 +355,6 @@ Running "make install" installs the files in the local TeX tree.
   \@namedef{opt@#2.sty}{#1}}
 \dontusepackage{etex}
 \RequirePackage{luacode}
-\RequirePackage{manyfoot}
 \RequirePackage{paracol}
 \RequirePackage{keycommand}
 \RequirePackage{xparse}
@@ -425,12 +424,12 @@ idno={}, msName={}, origDate={}][3]{%
 %    \end{macrocode}
 % Add a \hologo{(La)TeX} command to be processed as a |TEI xml| tag:
 %    \begin{macrocode}
-\NewDocumentCommand{\TeXtoTEI}{m m m}{%
+\NewDocumentCommand{\TeXtoTEI}{m m O{}}{%
   \luadirect{ekdosis.newcmdtotag(\luastringN{#1},
     \luastringN{#2},
     \luastringN{#3})}
 }
-\NewDocumentCommand{\EnvtoTEI}{s m m m}{%
+\NewDocumentCommand{\EnvtoTEI}{s m m O{}}{%
   \IfBooleanTF{#1}{%
   \luadirect{ekdosis.newenvtotag(\luastringN{#2},
     \luastringN{#3},
@@ -562,16 +561,12 @@ idno={}, msName={}, origDate={}][3]{%
   \fi}
 \newif\ifsubsq@unit
 \subsq@unittrue
-\SetFootnoteHook{\hskip -1.8em}
-\newfootnote{@ekd}
 \def\add@@apparatus{%
   \if@pkg@parnotes\parnotes\else\fi%
   \if@pkg@footins%
   \bgroup%
   \ifrtl@app\setRL\fi%
   \blfootnote{%
-  % \Footnotetext@ekd{\relax}{%
-    % \ifrtl@app\setRL\else\setLR\fi%
     \if@pkg@parnotes%
     \if@parnotesroman%
     \renewcommand*{\theparnotemark}{\roman{parnotemark}}\else\fi%
@@ -582,7 +577,7 @@ idno={}, msName={}, origDate={}][3]{%
   \egroup%
   \fi%
   \if@pkg@float%
-  \keyparbox[b!]{}{\ifrtl@app\setRL\else\setLR\fi%
+  \keyparbox[b!]{}{\ifrtl@app\setRL\fi%
     \if@pkg@parnotes%
     \if@parnotesroman%
     \renewcommand*{\theparnotemark}{\roman{parnotemark}}\else\fi%
@@ -1501,24 +1496,35 @@ end
 local function envtotei(str)
    for i = 1,#envtotags
    do
-      -- if tei_p_open and envtotags[i].b == "p" or envtotags[i].b == "lg"
-      if tei_p_open and isfound(close_p, envtotags[i].b)
+      if envtotags[i].b ~= ""
       then
-	 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
-		       * bsqbracketsii * bcbracesii * spcenc^-1,
-		    "</p>\n<"..envtotags[i].b..envtotags[i].c..">")
-	 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
-		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
-		    "</"..envtotags[i].b..">\n<p>")
+	 -- if tei_p_open and envtotags[i].b == "p" or envtotags[i].b == "lg"
+	 if tei_p_open and isfound(close_p, envtotags[i].b)
+	 then
+	    str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
+			  * bsqbracketsii * bcbracesii * spcenc^-1,
+		       "</p>\n<"..envtotags[i].b..envtotags[i].c..">")
+	    str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
+		       "</"..envtotags[i].b..">\n<p>")
+	 else
+	    str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
+			  * bsqbracketsii * bcbracesii * spcenc^-1,
+		       "<"..envtotags[i].b..envtotags[i].c..">")
+	    str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
+			  * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
+		       "</"..envtotags[i].b..">")
+	 end
       else
 	 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
 		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
 		       * bsqbracketsii * bcbracesii * spcenc^-1,
-		    "<"..envtotags[i].b..envtotags[i].c..">")
+		    "")
 	 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
 		       * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
-		    "</"..envtotags[i].b..">")
+		    "")
       end
    end
    str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
@@ -1546,8 +1552,13 @@ local function cmdtotei(str)
 			   end)
 			   body = cmdtotei(body)
 			   -- return string.format("<"..cmdtotags[i].b..cmdtotags[i].c.." %s>%s</"..cmdtotags[i].b..">", arg, body)
-			   return string.format("<"..cmdtotags[i].b..cmdtotags[i].c..">%s</" ..
+			   if cmdtotags[i].b ~= ""
+			   then
+			      return string.format("<"..cmdtotags[i].b..cmdtotags[i].c..">%s</" ..
 						   cmdtotags[i].b..">", body)
+			   else
+			      return ""
+			   end
       end)
    end
    -- temporarily:
-- 
cgit v1.2.3

