From f2f5e3da4b29712e1dfda69583e7a669008b3772 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Sat, 30 Mar 2019 21:48:21 +0100 Subject: declare new hands --- ekdosis.dtx | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'ekdosis.dtx') diff --git a/ekdosis.dtx b/ekdosis.dtx index 2245b8d..1328c4e 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -352,13 +352,19 @@ Running "make install" installs the files in the local TeX tree. \luadirect{ekdosis.closeteistream()} } % \end{macrocode} -% Build an process the list of witnesses +% Build and process the list of witnesses and hands % \begin{macrocode} \NewDocumentCommand{\DeclareNewWitness}{m m +m}{ \luadirect{ekdosis.newwitness(\luastringN{#1}, \luastringN{#2}, \luastringN{#3})} } +\NewDocumentCommand{\DeclareNewHand}{m m m +m}{ + \luadirect{ekdosis.newhand(\luastringN{#1}, + \luastringN{#2}, + \luastringN{#3}, + \luastringN{#4})} +} \NewDocumentCommand{\getsiglum}{m}{% \luadirect{tex.sprint(ekdosis.getsiglum(\luastringN{#1}))}% } @@ -579,6 +585,7 @@ end -- Witnesses listWit = {} +idsRend = {} local function isintable(table, value) for i = 1,#table do @@ -590,6 +597,18 @@ local function isintable(table, value) end local sorted_no = 0 + +local function getindex(id, table) + local idfound = nil + for i = 1,#table + do + if table[i].xmlid == id then + idfound = i + break + end + end + return idfound +end function ekdosis.newwitness(id, siglum, description) if xmlidfound(id) @@ -603,8 +622,30 @@ function ekdosis.newwitness(id, siglum, description) sorted_no = sorted_no + 1 table.insert(xmlids, {xmlid = id}) table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end) - table.insert(listWit, {a = id, b = siglum, c = description, d = sorted_no}) - table.sort(listWit, function(a ,b) return(#a.a > #b.a) end) + table.insert(listWit, {xmlid = id, + head = siglum, + msIdentifier = {}, + physDesc = {}, + description = {}, + sorted = sorted_no}) + table.sort(listWit, function(a ,b) return(#a.xmlid > #b.xmlid) end) + end + return true +end + +function ekdosis.newhand(id, witid, siglum, description) + if xmlidfound(id) + then + tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]] + ..id.. + [[" already exists as a xml:id. ]] + .. + [[Please pick another id.}}]]) + else + table.insert(xmlids, {xmlid = id}) + table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end) + local indexwit = getindex(witid, listWit) + table.insert(listWit[indexwit].physDesc, {xmlid = id, head = siglum, description ={}}) end return true end @@ -615,15 +656,15 @@ function ekdosis.getsiglum(str, opt) ctrl = str if opt == "tei" then for i = 1,#listWit do - str = string.gsub(str, "(%f[%w])"..listWit[i].a.."(%,)", "%1#"..listWit[i].a.."%2") - ctrl = string.gsub(ctrl, listWit[i].a.."%,", "") + str = string.gsub(str, "(%f[%w])"..listWit[i].xmlid.."(%,)", "%1#"..listWit[i].xmlid.."%2") + ctrl = string.gsub(ctrl, listWit[i].xmlid.."%,", "") end str = string.gsub(str, "%,(%s-)([%#])", " %2") str = string.gsub(str, "%,$", "") else for i = 1,#listWit do - str = string.gsub(str, listWit[i].a.."%,", listWit[i].b) - ctrl = string.gsub(ctrl, listWit[i].a.."%,", "") + str = string.gsub(str, listWit[i].xmlid.."%,", listWit[i].head) + ctrl = string.gsub(ctrl, listWit[i].xmlid.."%,", "") end end if string.find(ctrl, "[A-Za-z0-9]") -- cgit v1.2.3