From de2b09aa1fbcf2d880dd4f9091aa78e7aa353113 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Wed, 22 Apr 2020 19:07:13 +0200 Subject: increment xml:ids of
s whenever alignment environments are restarted --- ekdosis.dtx | 114 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 24 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index 72d9904..63b3b75 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -1232,6 +1232,18 @@ local function isintable(table, value) return false end +local function get_a_index(id, table) + local idfound = nil + for i = 1,#table + do + if table[i].a == id then + idfound = i + break + end + end + return idfound +end + local function getindex(id, table) local idfound = nil for i = 1,#table @@ -1422,11 +1434,15 @@ local close_p = { function ekdosis.newcmdtotag(cmd, tag, attr) if isintable(cmdtotags, cmd) then - tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" - ..cmd.. - "\" already exists as a known command to be processed to TEI. " - .. - "Please pick another command.}}") + -- tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" + -- ..cmd.. + -- "\" already exists as a known command to be processed to TEI. " + -- .. + -- "Please pick another command.}}") + local index = get_a_index(cmd, cmdtotags) + table.remove(cmdtotags, index) + table.insert(cmdtotags, {a = cmd, b = tag, c = " "..attr}) + table.sort(cmdtotags, function(a ,b) return(#a.a > #b.a) end) else table.insert(cmdtotags, {a = cmd, b = tag, c = " "..attr}) table.sort(cmdtotags, function(a ,b) return(#a.a > #b.a) end) @@ -1445,11 +1461,18 @@ end function ekdosis.newenvtotag(env, tag, attr, closep) if isintable(envtotags, env) then - tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" - ..cmd.. - "\" already exists as a known environment to be processed to TEI. " - .. - "Please pick another environment name.}}") + -- tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" + -- ..cmd.. + -- "\" already exists as a known environment to be processed to TEI. " + -- .. + -- "Please pick another environment name.}}") + local index = get_a_index(env, envtotags) + table.remove(envtotags, index) + table.insert(envtotags, {a = env, b = tag, c = " "..attr}) + table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end) + if closep == "yes" then + table.insert(close_p, tag) + else end else table.insert(envtotags, {a = env, b = tag, c = " "..attr}) table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end) @@ -2101,6 +2124,49 @@ function ekdosis.storecoldata(nthcol, chunk) return true end +local environment_div = {} + +function ekdosis.newscholar(id, siglum) + 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) + table.insert(idsRend, {xmlid = id, abbr = siglum}) + table.sort(idsRend, function(a ,b) return(#a.xmlid > #b.xmlid) end) + end + return true +end + + +local function build_envdiv(str) + if not environment_div[str] + then + environment_div[str] = 1 + else + environment_div[str] = environment_div[str] + 1 + end + local div = "div-"..str.."_"..environment_div[str] + if xmlidfound(div) + then + tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" + ..div.. + "\" already exists as a xml:id. " + .. + "ekdosis has generated some random id.}}") + return "div-"..math.random(1000,9999) + else + table.insert(xmlids, {xmlid = div}) + table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end) + return div + end +end + function ekdosis.mkenv() local environments = {} for i = 1,#aligned_texts @@ -2154,21 +2220,21 @@ function ekdosis.mkenv() end if aligned_texts[i].attribute ~= "" then - table.insert(environments, "\\EnvtoTEI{" - .. aligned_texts[i].text - .."}{div}" - .."[xml:id=\"div-" - .. aligned_texts[i].text - .. "\" " - .. aligned_texts[i].attribute - .. "]") + table.insert(environments, "\\EnvtoTEI{" + .. aligned_texts[i].text + .."}{div}" + .."[xml:id=\"" + .. build_envdiv(aligned_texts[i].text) + .. "\" " + .. aligned_texts[i].attribute + .. "]") else - table.insert(environments, "\\EnvtoTEI{" - .. aligned_texts[i].text - .."}{div}" - .."[xml:id=\"div-" - .. aligned_texts[i].text - .. "\"]") + table.insert(environments, "\\EnvtoTEI{" + .. aligned_texts[i].text + .."}{div}" + .."[xml:id=\"" + .. build_envdiv(aligned_texts[i].text) + .. "\"]") end end str = table.concat(environments) -- cgit v1.2.3