From f23360399b1da0876dc6dddcf1c70687101c92db Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sat, 3 Oct 2020 20:55:28 +0200
Subject: subvariation: new command \rdgGrp

---
 ekdosis.dtx | 97 ++++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 70 insertions(+), 27 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 5d17daa..642ca56 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -6578,6 +6578,14 @@ Sample text with a \textcolor{red}{word} in red.
   bool nordg = \ifekdr@nordg
 }
 %    \end{macrocode}
+% \begin{macro}{\rdgGrp}
+% \changes{v1.1}{2020/10/03}{new command for subvariation}
+%    \begin{macrocode}
+\NewDocumentCommand{\rdgGrp}{O{} > {\TrimSpaces } m}{%
+  \luadirect{tex.sprint(ekdosis.removesp(\luastringN{#2}))}%
+}
+%    \end{macrocode}
+% \end{macro}
 % \begin{macro}{\lem}
 % \cs{lem}\oarg{options}\marg{lemma text} inserts \meta{lemma text}
 % both in the edition text and in the apparatus criticus by default,
@@ -7883,6 +7891,37 @@ local function app_totei(str)
    return str
 end
 
+local function rdgGrp_totei(str)
+   str = gsub(str,
+	      dblbkslash *
+		 lpeg.Cs("rdgGrp") *
+		 spcenc^-1 *
+		 bsqbrackets *
+		 bcbraces *
+		 spcenc^-1,
+	      function(bkslash, cmd, opt, arg)
+		 opt = string.sub(opt, 2, -2)
+		 arg = string.sub(arg, 2, -2)
+		 teiwit = get_attr_value(opt, "wit")
+		 if teiwit ~= "" then teiwit = " wit=\""..ekdosis.getsiglum(teiwit, "tei").."\"" else end
+		 teisource = get_attr_value(opt, "source")
+		 if teisource ~= "" then teisource = " source=\""..ekdosis.getsiglum(teisource, "tei").."\"" else end
+		 teiresp = get_attr_value(opt, "resp")
+		 if teiresp ~= "" then teiresp = " resp=\""..ekdosis.getsiglum(teiresp, "tei").."\"" else end
+		 teitype = get_attr_value(opt, "type")
+		 if teitype ~= "" then teitype = " type=\""..teitype.."\"" else end
+		 if opt == ""
+		 then
+		    return rdgGrp_totei(string.format("<%s>%s</%s>",
+						       cmd, arg, cmd))
+		 else
+		    return rdgGrp_totei(string.format("<%s%s%s%s%s>%s</%s>",
+						       cmd, teiwit, teisource, teiresp, teitype, arg, cmd))
+		 end
+   end)
+   return str
+end
+
 local function lem_rdg_totei(str)
    str = gsub(str,
 	      spcenc^-1 *
@@ -8486,6 +8525,7 @@ local function textotei(str)
    str = texpatttotei(str)
    str = note_totei(str)
    str = app_totei(str)
+   str = rdgGrp_totei(str)
    str = lem_rdg_totei(str)
    str = relocate_notes(str)
    str = versetotei(str)
@@ -8593,40 +8633,43 @@ function ekdosis.openteistream()
       f:write("</witness>", "\n")
    end
    f:write("</listWit>", "\n")
-   f:write("<listPerson xml:id=\"scholars\">", "\n")
-   for i = 1,#listPerson do
-      f:write('<person xml:id=\"', listPerson[i].xmlid, "\">", "\n")
-      f:write('<persName>', "\n")
-      f:write('<abbr type="siglum">', textotei(listPerson[i].abbr), "</abbr>", "\n")
-      if listPerson[i].persName.name ~= nil
-      then
-	 f:write(textotei(listPerson[i].persName.name))
-      else
-	 if listPerson[i].persName.forename ~= ""
-	 then
-	    f:write("<forename>", textotei(listPerson[i].persName.forename), "</forename>", "\n")
-	 else
-	    f:write("<forename><!-- forename --></forename>", "\n")
-	 end
-	 if textotei(listPerson[i].persName.surname) ~= ""
+   if next(listPerson) ~= nil
+   then
+      f:write("<listPerson xml:id=\"scholars\">", "\n")
+      for i = 1,#listPerson do
+	 f:write('<person xml:id=\"', listPerson[i].xmlid, "\">", "\n")
+	 f:write('<persName>', "\n")
+	 f:write('<abbr type="siglum">', textotei(listPerson[i].abbr), "</abbr>", "\n")
+	 if listPerson[i].persName.name ~= nil
 	 then
-	    f:write("<surname>", textotei(listPerson[i].persName.surname), "</surname>", "\n")
+	    f:write(textotei(listPerson[i].persName.name))
 	 else
-	    f:write("<surname><!-- surname --></surname>", "\n")
+	    if listPerson[i].persName.forename ~= ""
+	    then
+	       f:write("<forename>", textotei(listPerson[i].persName.forename), "</forename>", "\n")
+	    else
+	       f:write("<forename><!-- forename --></forename>", "\n")
+	    end
+	    if textotei(listPerson[i].persName.surname) ~= ""
+	    then
+	       f:write("<surname>", textotei(listPerson[i].persName.surname), "</surname>", "\n")
+	    else
+	       f:write("<surname><!-- surname --></surname>", "\n")
+	    end
+	    if textotei(listPerson[i].persName.addName) ~= ""
+	    then
+	       f:write("<addName>", textotei(listPerson[i].persName.addName), "</addName>", "\n")
+	    end
 	 end
-	 if textotei(listPerson[i].persName.addName) ~= ""
+	 if listPerson[i].note ~= ""
 	 then
-	    f:write("<addName>", textotei(listPerson[i].persName.addName), "</addName>", "\n")
+	    f:write("<note>", textotei(listPerson[i].note), "</note>", "\n")
 	 end
+	 f:write('</persName>', "\n")      
+	 f:write('</person>', "\n")      
       end
-      if listPerson[i].note ~= ""
-      then
-	 f:write("<note>", textotei(listPerson[i].note), "</note>", "\n")
-      end
-      f:write('</persName>', "\n")      
-      f:write('</person>', "\n")      
+      f:write("</listPerson>", "\n")
    end
-   f:write("</listPerson>", "\n")
    f:write("</sourceDesc>", "\n")
    f:write("</fileDesc>", "\n")
    f:write("<encodingDesc>", "\n")
-- 
cgit v1.2.3

