aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2020-04-22 19:07:13 +0200
committerRobert Alessi <alessi@robertalessi.net>2020-04-22 19:07:13 +0200
commitde2b09aa1fbcf2d880dd4f9091aa78e7aa353113 (patch)
tree3f5e96b6fdfc3a6d5376124074ea3de9c50bb1d6
parent8976e160e584d67178ab14ee2110429a99623223 (diff)
downloadekdosis-de2b09aa1fbcf2d880dd4f9091aa78e7aa353113.tar.gz
increment xml:ids of <div>s whenever alignment environments are restarted
-rw-r--r--ekdosis.dtx114
1 files 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)
1232 return false 1232 return false
1233end 1233end
1234 1234
1235local function get_a_index(id, table)
1236 local idfound = nil
1237 for i = 1,#table
1238 do
1239 if table[i].a == id then
1240 idfound = i
1241 break
1242 end
1243 end
1244 return idfound
1245end
1246
1235local function getindex(id, table) 1247local function getindex(id, table)
1236 local idfound = nil 1248 local idfound = nil
1237 for i = 1,#table 1249 for i = 1,#table
@@ -1422,11 +1434,15 @@ local close_p = {
1422function ekdosis.newcmdtotag(cmd, tag, attr) 1434function ekdosis.newcmdtotag(cmd, tag, attr)
1423 if isintable(cmdtotags, cmd) 1435 if isintable(cmdtotags, cmd)
1424 then 1436 then
1425 tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" 1437 -- tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
1426 ..cmd.. 1438 -- ..cmd..
1427 "\" already exists as a known command to be processed to TEI. " 1439 -- "\" already exists as a known command to be processed to TEI. "
1428 .. 1440 -- ..
1429 "Please pick another command.}}") 1441 -- "Please pick another command.}}")
1442 local index = get_a_index(cmd, cmdtotags)
1443 table.remove(cmdtotags, index)
1444 table.insert(cmdtotags, {a = cmd, b = tag, c = " "..attr})
1445 table.sort(cmdtotags, function(a ,b) return(#a.a > #b.a) end)
1430 else 1446 else
1431 table.insert(cmdtotags, {a = cmd, b = tag, c = " "..attr}) 1447 table.insert(cmdtotags, {a = cmd, b = tag, c = " "..attr})
1432 table.sort(cmdtotags, function(a ,b) return(#a.a > #b.a) end) 1448 table.sort(cmdtotags, function(a ,b) return(#a.a > #b.a) end)
@@ -1445,11 +1461,18 @@ end
1445function ekdosis.newenvtotag(env, tag, attr, closep) 1461function ekdosis.newenvtotag(env, tag, attr, closep)
1446 if isintable(envtotags, env) 1462 if isintable(envtotags, env)
1447 then 1463 then
1448 tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" 1464 -- tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
1449 ..cmd.. 1465 -- ..cmd..
1450 "\" already exists as a known environment to be processed to TEI. " 1466 -- "\" already exists as a known environment to be processed to TEI. "
1451 .. 1467 -- ..
1452 "Please pick another environment name.}}") 1468 -- "Please pick another environment name.}}")
1469 local index = get_a_index(env, envtotags)
1470 table.remove(envtotags, index)
1471 table.insert(envtotags, {a = env, b = tag, c = " "..attr})
1472 table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end)
1473 if closep == "yes" then
1474 table.insert(close_p, tag)
1475 else end
1453 else 1476 else
1454 table.insert(envtotags, {a = env, b = tag, c = " "..attr}) 1477 table.insert(envtotags, {a = env, b = tag, c = " "..attr})
1455 table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end) 1478 table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end)
@@ -2101,6 +2124,49 @@ function ekdosis.storecoldata(nthcol, chunk)
2101 return true 2124 return true
2102end 2125end
2103 2126
2127local environment_div = {}
2128
2129function ekdosis.newscholar(id, siglum)
2130 if xmlidfound(id)
2131 then
2132 tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
2133 ..id..
2134 "\" already exists as a xml:id. "
2135 ..
2136 "Please pick another id.}}")
2137 else
2138 table.insert(xmlids, {xmlid = id})
2139 table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end)
2140 table.insert(idsRend, {xmlid = id, abbr = siglum})
2141 table.sort(idsRend, function(a ,b) return(#a.xmlid > #b.xmlid) end)
2142 end
2143 return true
2144end
2145
2146
2147local function build_envdiv(str)
2148 if not environment_div[str]
2149 then
2150 environment_div[str] = 1
2151 else
2152 environment_div[str] = environment_div[str] + 1
2153 end
2154 local div = "div-"..str.."_"..environment_div[str]
2155 if xmlidfound(div)
2156 then
2157 tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
2158 ..div..
2159 "\" already exists as a xml:id. "
2160 ..
2161 "ekdosis has generated some random id.}}")
2162 return "div-"..math.random(1000,9999)
2163 else
2164 table.insert(xmlids, {xmlid = div})
2165 table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end)
2166 return div
2167 end
2168end
2169
2104function ekdosis.mkenv() 2170function ekdosis.mkenv()
2105 local environments = {} 2171 local environments = {}
2106 for i = 1,#aligned_texts 2172 for i = 1,#aligned_texts
@@ -2154,21 +2220,21 @@ function ekdosis.mkenv()
2154 end 2220 end
2155 if aligned_texts[i].attribute ~= "" 2221 if aligned_texts[i].attribute ~= ""
2156 then 2222 then
2157 table.insert(environments, "\\EnvtoTEI{" 2223 table.insert(environments, "\\EnvtoTEI{"
2158 .. aligned_texts[i].text 2224 .. aligned_texts[i].text
2159 .."}{div}" 2225 .."}{div}"
2160 .."[xml:id=\"div-" 2226 .."[xml:id=\""
2161 .. aligned_texts[i].text 2227 .. build_envdiv(aligned_texts[i].text)
2162 .. "\" " 2228 .. "\" "
2163 .. aligned_texts[i].attribute 2229 .. aligned_texts[i].attribute
2164 .. "]") 2230 .. "]")
2165 else 2231 else
2166 table.insert(environments, "\\EnvtoTEI{" 2232 table.insert(environments, "\\EnvtoTEI{"
2167 .. aligned_texts[i].text 2233 .. aligned_texts[i].text
2168 .."}{div}" 2234 .."}{div}"
2169 .."[xml:id=\"div-" 2235 .."[xml:id=\""
2170 .. aligned_texts[i].text 2236 .. build_envdiv(aligned_texts[i].text)
2171 .. "\"]") 2237 .. "\"]")
2172 end 2238 end
2173 end 2239 end
2174 str = table.concat(environments) 2240 str = table.concat(environments)