From 9f476bf2b9667427de8968f7e7db4fd97f7ffa01 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sun, 21 Apr 2019 19:24:57 +0200
Subject: new function \DeclareNewShorthand. replaced head with abbr in TEI
 header

---
 ekdosis.dtx | 47 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 10 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 8a6cbb7..fdf582f 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -404,6 +404,12 @@ idno={}, msName={}, origDate={}][3]{%
     \luastringN{#2})}
 }
 \@onlypreamble\DeclareNewScholar
+\NewDocumentCommand{\DeclareNewShorthand}{m m m}{
+  \luadirect{ekdosis.newshorthand(\luastringN{#1},
+    \luastringN{#2},
+    \luastringN{#3})}
+}
+\@onlypreamble\DeclareNewShorthand
 \NewDocumentCommand{\getsiglum}{m}{%
   \luadirect{tex.sprint(ekdosis.getsiglum(\luastringN{#1}))}%
 }
@@ -672,6 +678,7 @@ end
 -- Witnesses
 listWit = {}
 idsRend = {}
+shorthands = {}
 
 local function isintable(table, value)
    for i = 1,#table do
@@ -712,10 +719,10 @@ function ekdosis.newwitness(id,
    else
       table.insert(xmlids, {xmlid = id})
       table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end)
-      table.insert(idsRend, {xmlid = id, head = siglum})
+      table.insert(idsRend, {xmlid = id, abbr = siglum})
       table.sort(idsRend, function(a ,b) return(#a.xmlid > #b.xmlid) end)
       table.insert(listWit, {xmlid = id,
-			     head = siglum,
+			     abbr = siglum,
 			     msIdentifier = {
 				settlement = Settlement,
 				repository = Repository,
@@ -743,16 +750,33 @@ function ekdosis.newhand(id, witid, siglum, description)
    else
       table.insert(xmlids, {xmlid = id})
       table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end)
-      table.insert(idsRend, {xmlid = id, head = siglum})
+      table.insert(idsRend, {xmlid = id, abbr = siglum})
       table.sort(idsRend, function(a ,b) return(#a.xmlid > #b.xmlid) end)
       local indexwit = getindex(witid, listWit)
-      -- listWit[indexwit].handDesc = {xmlid = id, head = siglum, handNote = description}
+      -- listWit[indexwit].handDesc = {xmlid = id, abbr = siglum, handNote = description}
       if listWit[indexwit].handDesc == nil
       then
 	 listWit[indexwit].handDesc = {}
       else
       end
-      table.insert(listWit[indexwit].handDesc, {xmlid = id, head = siglum, handNote = description})
+      table.insert(listWit[indexwit].handDesc, {xmlid = id, abbr = siglum, handNote = description})
+   end
+   return true
+end
+
+function ekdosis.newshorthand(id, rend, xmlids)
+   if isintable(shorthands, id)
+   then
+      tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]]
+      	 ..id..
+      	 [[" already exists as a shorthand. ]]
+      	 ..
+      	 [[Please pick another shorthand.}}]])
+   else
+      table.insert(shorthands, { a = id, b = rend, c = xmlids })
+      table.sort(shorthands, function(a ,b) return(#a.a > #b.a) end)
+      table.insert(idsRend, {xmlid = id, abbr = rend})
+      table.sort(idsRend, function(a ,b) return(#a.xmlid > #b.xmlid) end)
    end
    return true
 end
@@ -775,7 +799,7 @@ function ekdosis.newscholar(id, siglum)
    else
       table.insert(xmlids, {xmlid = id})
       table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end)
-      table.insert(idsRend, {xmlid = id, head = siglum})
+      table.insert(idsRend, {xmlid = id, abbr = siglum})
       table.sort(idsRend, function(a ,b) return(#a.xmlid > #b.xmlid) end)
    end
    return true
@@ -786,6 +810,9 @@ function ekdosis.getsiglum(str, opt)
    str = string.gsub(str, "%s-(%,)", "%1")
    ctrl = str
    if opt == "tei" then
+      for i = 1,#shorthands do
+	 str = string.gsub(str, shorthands[i].a, shorthands[i].c)
+      end
       for i = 1,#idsRend do
 	 str  = string.gsub(str, "(%f[%w])"..idsRend[i].xmlid.."(%,)", "%1#"..idsRend[i].xmlid.."%2")
 	 ctrl = string.gsub(ctrl, idsRend[i].xmlid.."%,", "")
@@ -794,7 +821,7 @@ function ekdosis.getsiglum(str, opt)
       str = string.gsub(str, "%,$", "")
    else
       for i = 1,#idsRend do
-	 str  = string.gsub(str, idsRend[i].xmlid.."%,", idsRend[i].head)
+	 str  = string.gsub(str, idsRend[i].xmlid.."%,", idsRend[i].abbr)
 	 ctrl = string.gsub(ctrl, idsRend[i].xmlid.."%,", "")
       end
    end
@@ -918,7 +945,7 @@ function ekdosis.openteistream()
    f:write("<listWit>", "\n")
    for i = 1,#listWit do
       f:write("<msDesc xml:id=\"", listWit[i].xmlid, "\">", "\n")
-      f:write("<head>", ekdosis.textotei(listWit[i].head), "</head>", "\n")
+      f:write("<abbr>", ekdosis.textotei(listWit[i].abbr), "</abbr>", "\n")
       if listWit[i].msIdentifier.settlement == ""
 	 and listWit[i].msIdentifier.repository == ""
 	 and listWit[i].msIdentifier.idno == ""
@@ -947,7 +974,7 @@ function ekdosis.openteistream()
 	 while listWit[i].handDesc[j]
 	 do
 	    f:write("<handDesc xml:id=\"", listWit[i].handDesc[j].xmlid, "\">", "\n")
-	    f:write("<head>", ekdosis.textotei(listWit[i].handDesc[j].head), "</head>", "\n")
+	    f:write("<abbr>", ekdosis.textotei(listWit[i].handDesc[j].abbr), "</abbr>", "\n")
 	    if listWit[i].handDesc[j].handNote == "" then else
 	       f:write("<handNote>\n<p>", ekdosis.textotei(listWit[i].handDesc[j].handNote), "</p>\n</handNote>", "\n")
 	    end
@@ -1022,7 +1049,7 @@ end
 -- begin basic TeX Conspectus siglorum
 function ekdosis.basic_cs(msid)
    local indexwit = getindex(msid, listWit)
-   siglum = listWit[indexwit].head
+   siglum = listWit[indexwit].abbr
    if listWit[indexwit].detailsDesc == ""
    then
       name = listWit[indexwit].msIdentifier.msName
-- 
cgit v1.2.3

