From d0454f1b9181963ffe3828af9f54964f71d7097c Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Wed, 25 Mar 2020 18:58:28 +0100
Subject: new command \SetEkdosisAlignment. lem_rdg_totei() produced an empty
 wit in some occasions: fixed.

---
 ekdosis.dtx | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index dcc4d24..09ed564 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -1080,6 +1080,9 @@ Running "make install" installs the files in the local TeX tree.
   initial texts = edition;translation,
   initial apparatus = edition,
 }
+\NewDocumentCommand{\SetEkdosisAlignment}{m}{
+  \ekvset{align}{#1}
+}
 \NewDocumentCommand{\ekd@storecol}{m}{%
   \luadirect{ekdosis.storecurcol(\luastring{\thecolumn})}%
 }
@@ -1534,17 +1537,23 @@ local function lem_rdg_totei(str)
 		 opt = string.match(opt, "%f[%w]wit%s?%=%s?%b{}")
 		    or string.match(opt, "%f[%w]wit%s?%=%s?%w+%f[%W]")
 		    or ""
-		 opt = string.gsub(opt, "wit%s?%=%s?(%b{})", function(bbraces)
-				      bbraces = string.sub(bbraces, 2, -2)
-				      bbraces = ekdosis.getsiglum(bbraces, "tei")
-				      return string.format("%s", bbraces)
-		 end)
-		 opt = string.gsub(opt, "(wit%s?%=%s?)(%w+%f[%W])", function(attr, value)
-				      value = ekdosis.getsiglum(value, "tei")
-				      return string.format("%s", value)
-		 end)
-		 return lem_rdg_totei(string.format("<%s wit=\"%s\">%s</%s>",
-						    cmd, opt, arg, cmd))
+		 if opt == ""
+		 then
+		    return lem_rdg_totei(string.format("<%s>%s</%s>",
+						       cmd, arg, cmd))
+		 else
+		    opt = string.gsub(opt, "wit%s?%=%s?(%b{})", function(bbraces)
+					 bbraces = string.sub(bbraces, 2, -2)
+					 bbraces = ekdosis.getsiglum(bbraces, "tei")
+					 return string.format("%s", bbraces)
+		    end)
+		    opt = string.gsub(opt, "(wit%s?%=%s?)(%w+%f[%W])", function(attr, value)
+					 value = ekdosis.getsiglum(value, "tei")
+					 return string.format("%s", value)
+		    end)
+		    return lem_rdg_totei(string.format("<%s wit=\"%s\">%s</%s>",
+						       cmd, opt, arg, cmd))
+		 end
    end)
    str = gsub(str, spcenc^-0 * dblbkslash * lemrdg * spcenc^-1 * bcbraces * spcenc^-1,
 	      function(bkslash, cmd, arg)
@@ -1983,14 +1992,14 @@ function ekdosis.mkenv()
 			 .. aligned_texts[i].text
 			 .. "}{}{\\begin{nthcolumn}{"
 			 .. aligned_texts[i].column
-			 .."}\\begin{ekdosis}"
-		         .."\\csname ekd@storecol\\endcsname{\\thecolumn}}{\\end{ekdosis}\\end{nthcolumn}}")
+			 .."}\\csname ekd@storecol\\endcsname{\\thecolumn}"
+		         .."\\begin{ekdosis}}{\\end{ekdosis}\\end{nthcolumn}}")
 	 table.insert(environments, "\\NewDocumentEnvironment{"
 			 .. aligned_texts[i].text
 			 .. "*}{O{}}{\\begin{nthcolumn*}{"
 			 .. aligned_texts[i].column
-			 .."}\\begin{ekdosis}"
-		         .."\\csname ekd@storecol\\endcsname{\\thecolumn}}{\\end{ekdosis}\\end{nthcolumn*}}")
+			 .."}\\csname ekd@storecol\\endcsname{\\thecolumn}"
+		         .."\\begin{ekdosis}}{\\end{ekdosis}\\end{nthcolumn*}}")
       else
 	 table.insert(environments, "\\NewDocumentEnvironment{"
 			 .. aligned_texts[i].text
-- 
cgit v1.2.3

