summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua')
-rw-r--r--Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua324
1 files changed, 247 insertions, 77 deletions
diff --git a/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua b/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
index 64e444d5912..55d42fbc7bc 100644
--- a/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
+++ b/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
@@ -1,7 +1,7 @@
--[[
This file is part of the `ekdosis' package
-ekdosis -- Typesetting TEI xml compliant critical editions
+ekdosis -- Typesetting TEI xml-compliant critical editions
Copyright (C) 2020 Robert Alessi
Please send error reports and suggestions for improvements to Robert
@@ -90,7 +90,8 @@ local citecmds = lpeg.Cs(lpeg.P("icite")
local next = next
-- General
-xmlids = {}
+local xmlids = {}
+table.insert(xmlids, {xmlid = "scholars"} )
local function xmlidfound(element)
for i = 1,#xmlids do
@@ -112,9 +113,12 @@ local function checkxmlid(str)
end
-- Witnesses
-listWit = {}
-idsRend = {}
-shorthands = {}
+local listWit = {}
+-- Persons/Scholars
+local listPerson = {}
+
+local idsRend = {}
+local shorthands = {}
local function isfound(table, value)
for i = 1,#table do
@@ -257,14 +261,67 @@ function ekdosis.newshorthand(id, rend, xmlids)
return true
end
+function ekdosis.newscholar(id,
+ siglum,
+ rawname,
+ Forename,
+ Surname,
+ AddName,
+ Note)
+ if xmlidfound(id)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..id..
+ "\" already exists as an xml:id. "
+ ..
+ "Please pick another id.}}")
+ elseif not checkxmlid(id)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..id..
+ "\" is not a valid xml:id. \\MessageBreak "
+ ..
+ "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)
+ if rawname ~= ""
+ then
+ table.insert(listPerson, {xmlid = id,
+ abbr = siglum,
+ note = Note,
+ persName = {
+ name = rawname}
+ })
+ else
+ table.insert(listPerson, {xmlid = id,
+ abbr = siglum,
+ note = Note,
+ persName = {
+ forename = Forename,
+ surname = Surname,
+ addName = AddName}
+ })
+ end
+ end
+ return true
+end
+
local xmlbibresource = nil
-function ekdosis.setxmlbibresource(str)
- xmlbibresource = str..".xml"
+function ekdosis.addxmlbibresource(str)
+ if string.find(str, "%.xml$")
+ then
+ xmlbibresource = str
+ else
+ xmlbibresource = str..".xml"
+ end
return true
end
-function ekdosis.newscholar(id, siglum)
+function ekdosis.newsource(id, siglum)
if xmlidfound(id)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
@@ -326,6 +383,7 @@ local cmdtotags = {
{a="LRfootnote", b="note", c=" place=\"bottom\""},
{a="RLfootnote", b="note", c=" place=\"bottom\""},
{a="enquote *", b="quote", c=""},
+ {a="marginpar", b="note", c=" place=\"margin\""},
{a="footnote", b="note", c=" place=\"bottom\""},
{a="enquote", b="quote", c=""},
{a="txtrans", b="s", c=" xml:lang=\"ar-Latn\" type=\"transliterated\""},
@@ -335,15 +393,21 @@ local cmdtotags = {
{a="textsf", b="hi", c=" rend=\"sf\""},
{a="arbup", b="hi", c=" rend=\"sup\""},
{a="txarb", b="s", c=" xml:lang=\"arb\""},
- {a="mbox", b="", c=""},
{a="arb", b="foreign",
c=" xml:lang=\"ar-Latn\" type=\"transliterated\" subtype=\"arabtex\""}
}
local texpatttotags = {
+ {a="\\addentries%s+%[(.-)%]{(.-)}", b=""},
+ {a="\\addentries%s+{(.-)}", b=""},
+ {a="\\setverselinenums%s+{(.-)}{(.-)}", b=""},
+ {a="\\resetlinenumber%s+%[(.-)%]", b=""},
+ {a="\\resetlinenumber%s+", b=""},
+ {a="\\poemlines%s+{(.-)}", b=""},
{a="\\pagebreak%s+%[[1-4]%]", b=""},
{a="\\pagebreak%s+", b=""},
{a="\\altrfont%s+", b=""},
+ {a="\\mbox%s+{(.-)}", b="%1"},
{a="\\LR%s+{(.-)}", b="%1"},
{a="\\RL%s+{(.-)}", b="%1"}
}
@@ -420,6 +484,10 @@ end
-- Get values of attributes
local function get_attr_value(str, attr)
str = str..","
+ str = string.gsub(str, "%b{}", function(body)
+ body = string.gsub(body, attr, attr.."@ekd")
+ return string.format("%s", body)
+ end)
local attrval = string.match(str, "%f[%w]"..attr.."%s?%=%s?%b{}")
or string.match(str, "%f[%w]"..attr.."%s?%=%s?.-%,")
or ""
@@ -428,6 +496,7 @@ local function get_attr_value(str, attr)
return string.format("%s", bbraces)
end)
attrval = string.gsub(attrval, attr.."%s?%=%s?(.-)%s?%,", "%1")
+ str = string.gsub(str, attr.."@ekd", attr)
return attrval
end
@@ -452,16 +521,21 @@ local function note_totei(str)
if teitype ~= "" then teitype = " type=\""..teitype.."\"" else end
right = get_attr_value(opt, "labelb")
left = get_attr_value(opt, "labele")
- if left ~= ""
+ if right == ""
then
- return string.format(
- "<%s%s target=\"#range(right(%s),left(%s))\">%s</%s><anchor xml:id=\"%s\"/>",
- cmd, teitype, right, left, arg, cmd, right)
- elseif left == ""
- then
- return string.format(
- "<%s%s target=\"#right(%s)\">%s</%s><anchor xml:id=\"%s\"/>",
- cmd, teitype, right, arg, cmd, right)
+ return string.format("<%s>%s</%s>", cmd, arg, cmd)
+ else
+ if left ~= ""
+ then
+ return string.format(
+ "<%s%s target=\"#range(right(%s),left(%s))\">%s</%s><anchor xml:id=\"%s\"/>",
+ cmd, teitype, right, left, arg, cmd, right)
+ elseif left == ""
+ then
+ return string.format(
+ "<%s%s target=\"#right(%s)\">%s</%s><anchor xml:id=\"%s\"/>",
+ cmd, teitype, right, arg, cmd, right)
+ end
end
end)
return str
@@ -486,6 +560,31 @@ 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)
+ 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>",
+ cmd, teitype, arg, cmd))
+ end
+ end)
+ return str
+end
+
local function lem_rdg_totei(str)
str = gsub(str,
spcenc^-1 *
@@ -502,6 +601,10 @@ local function lem_rdg_totei(str)
--
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
--
@@ -511,8 +614,8 @@ local function lem_rdg_totei(str)
cmd, arg, cmd))
else
-- opt = ekdosis.getsiglum(opt, "tei")
- return lem_rdg_totei(string.format("<%s%s%s>%s</%s>",
- cmd, teiwit, teitype, arg, cmd))
+ return lem_rdg_totei(string.format("<%s%s%s%s%s>%s</%s>",
+ cmd, teiwit, teisource, teiresp, teitype, arg, cmd))
end
end)
str = gsub(str, spcenc^-0 * dblbkslash * lemrdg * spcenc^-1 * bcbraces * spcenc^-1,
@@ -530,7 +633,7 @@ end
local function linestotei(str)
-- str = "\n<l>"..str
- str = string.gsub(str, "^%s?(.-)%s?$", "\n<l>%1</l>\n")
+ str = string.gsub(str, "^%s?(.-)\\\\[%!%*]?%s?$", "\n<l>%1</l>\n")
-- str = gsub(str, endpoem, "</l>\n")
str = gsub(str, poemline * spcenc^-1 * lpeg.P("&gt;"), "\n<lb/>")
str = gsub(str, poemline * spcenc^-1, "</l>\n<l>")
@@ -617,7 +720,7 @@ local function icitetotei(str)
* bsqbrackets
* bsqbrackets
* bcbraces
- * bsqbrackets^-1,
+ * (bsqbrackets + bcbraces)^-1,
function(cmd, pre, post, body, opt)
pre = string.sub(pre, 2, -2)
post = string.sub(post, 2, -2)
@@ -638,7 +741,7 @@ local function icitetotei(str)
* spcenc^-1
* bsqbrackets
* bcbraces
- * bsqbrackets^-1,
+ * (bsqbrackets + bcbraces)^-1,
function(cmd, post, body, opt)
post = string.sub(post, 2, -2)
body = string.sub(body, 2, -2)
@@ -657,7 +760,7 @@ local function icitetotei(str)
* citecmds
* spcenc^-1
* bcbraces
- * bsqbrackets^-1,
+ * (bsqbrackets + bcbraces)^-1,
function(cmd, body, opt)
body = string.sub(body, 2, -2)
if not checkxmlid(body)
@@ -709,6 +812,19 @@ local function cmdtotei(str)
return string.format("<ref target=\"%s\">%s</ref>",
teisiglum, printsiglum)
end)
+ str = string.gsub(str, "\\(gap)%s?(%b{})",
+ function(cmd, body)
+ body = string.sub(body, 2, -2)
+ teireason = get_attr_value(body, "reason")
+ if teireason ~= "" then teireason = " reason=\""..teireason.."\"" else end
+ teiunit = get_attr_value(body, "unit")
+ if teiunit ~= "" then teiunit = " unit=\""..teiunit.."\"" else end
+ teiquantity = get_attr_value(body, "quantity")
+ if teiquantity ~= "" then teiquantity = " quantity=\""..teiquantity.."\"" else end
+ teiextent = get_attr_value(body, "extent")
+ if teiextent ~= "" then teiextent = " extent=\""..teiextent.."\"" else end
+ return string.format("<gap%s%s%s%s/>", teireason, teiunit, teiquantity, teiextent)
+ end)
str = gsub(str, lpeg.P("\\") * labelrefcmds * spcenc^-1 * bcbraces,
function(cmd, body)
body = string.sub(body, 2, -2)
@@ -1072,6 +1188,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)
@@ -1117,68 +1234,113 @@ function ekdosis.openteistream()
f:write("<distributor><!-- Distributor name --></distributor>", "\n")
f:write("</publicationStmt>", "\n")
f:write("<sourceDesc>", "\n")
- f:write("<listWit>", "\n")
- for i = 1,#listWit do
- f:write('<witness xml:id=\"', listWit[i].xmlid, "\">", "\n")
- f:write('<abbr type="siglum">', textotei(listWit[i].abbr), "</abbr>", "\n")
- f:write(textotei(listWit[i].detailsDesc), "\n")
- f:write("<msDesc>", "\n")
- if listWit[i].msIdentifier.settlement == ""
- and listWit[i].msIdentifier.institution == ""
- and listWit[i].msIdentifier.repository == ""
- and listWit[i].msIdentifier.collection == ""
- and listWit[i].msIdentifier.idno == ""
- and listWit[i].msIdentifier.msName == ""
+ if next(listWit) == nil and next(listPerson) == nil
+ then
+ f:write("<p>No source, born digital</p>", "\n")
+ else
+ if next(listWit) ~= nil
then
- f:write("<msIdentifier/>", "\n")
- else
- f:write("<msIdentifier>", "\n")
- if listWit[i].msIdentifier.settlement ~= "" then
- f:write("<settlement>", textotei(listWit[i].msIdentifier.settlement), "</settlement>", "\n")
+ f:write("<listWit>", "\n")
+ for i = 1,#listWit do
+ f:write('<witness xml:id=\"', listWit[i].xmlid, "\">", "\n")
+ f:write('<abbr type="siglum">', textotei(listWit[i].abbr), "</abbr>", "\n")
+ f:write(textotei(listWit[i].detailsDesc), "\n")
+ f:write("<msDesc>", "\n")
+ if listWit[i].msIdentifier.settlement == ""
+ and listWit[i].msIdentifier.institution == ""
+ and listWit[i].msIdentifier.repository == ""
+ and listWit[i].msIdentifier.collection == ""
+ and listWit[i].msIdentifier.idno == ""
+ and listWit[i].msIdentifier.msName == ""
+ then
+ f:write("<msIdentifier/>", "\n")
+ else
+ f:write("<msIdentifier>", "\n")
+ if listWit[i].msIdentifier.settlement ~= "" then
+ f:write("<settlement>", textotei(listWit[i].msIdentifier.settlement), "</settlement>", "\n")
else end
- if listWit[i].msIdentifier.institution ~= "" then
- f:write("<institution>", textotei(listWit[i].msIdentifier.institution), "</institution>", "\n")
+ if listWit[i].msIdentifier.institution ~= "" then
+ f:write("<institution>", textotei(listWit[i].msIdentifier.institution), "</institution>", "\n")
else end
- if listWit[i].msIdentifier.repository ~= "" then
- f:write("<repository>", textotei(listWit[i].msIdentifier.repository), "</repository>", "\n")
+ if listWit[i].msIdentifier.repository ~= "" then
+ f:write("<repository>", textotei(listWit[i].msIdentifier.repository), "</repository>", "\n")
else end
- if listWit[i].msIdentifier.collection ~= "" then
- f:write("<collection>", textotei(listWit[i].msIdentifier.collection), "</collection>", "\n")
+ if listWit[i].msIdentifier.collection ~= "" then
+ f:write("<collection>", textotei(listWit[i].msIdentifier.collection), "</collection>", "\n")
else end
- if listWit[i].msIdentifier.idno ~= "" then
- f:write("<idno>", textotei(listWit[i].msIdentifier.idno), "</idno>", "\n")
+ if listWit[i].msIdentifier.idno ~= "" then
+ f:write("<idno>", textotei(listWit[i].msIdentifier.idno), "</idno>", "\n")
else end
- if listWit[i].msIdentifier.msName ~= "" then
- f:write("<msName>", textotei(listWit[i].msIdentifier.msName), "</msName>", "\n")
+ if listWit[i].msIdentifier.msName ~= "" then
+ f:write("<msName>", textotei(listWit[i].msIdentifier.msName), "</msName>", "\n")
else end
- f:write("</msIdentifier>", "\n")
+ f:write("</msIdentifier>", "\n")
+ end
+ if listWit[i].handDesc ~= nil then
+ f:write("<physDesc>", "\n")
+ f:write("<handDesc hands=\"", #listWit[i].handDesc, "\">", "\n")
+ local j = 1
+ while listWit[i].handDesc[j]
+ do
+ f:write("<handNote xml:id=\"", listWit[i].handDesc[j].xmlid, "\">", "\n")
+ f:write('<abbr type="siglum">', textotei(listWit[i].handDesc[j].abbr), "</abbr>", "\n")
+ f:write("<p>", textotei(listWit[i].handDesc[j].detailsDesc), "</p>", "\n")
+ f:write("</handNote>", "\n")
+ j = j + 1
+ end
+ f:write("</handDesc>", "\n")
+ f:write("</physDesc>", "\n")
+ else end
+ if listWit[i].history ~= nil then
+ f:write("<history>", "\n")
+ f:write("<origin>", "\n")
+ f:write("<origDate>", textotei(listWit[i].history.origin.origDate), "</origDate>", "\n")
+ f:write("</origin>", "\n")
+ f:write("</history>", "\n")
+ end
+ f:write("</msDesc>", "\n")
+ f:write("</witness>", "\n")
+ end
+ f:write("</listWit>", "\n")
end
- if listWit[i].handDesc ~= nil then
- f:write("<physDesc>", "\n")
- f:write("<handDesc hands=\"", #listWit[i].handDesc, "\">", "\n")
- local j = 1
- while listWit[i].handDesc[j]
- do
- f:write("<handNote xml:id=\"", listWit[i].handDesc[j].xmlid, "\">", "\n")
- f:write('<abbr type="siglum">', textotei(listWit[i].handDesc[j].abbr), "</abbr>", "\n")
- f:write("<p>", textotei(listWit[i].handDesc[j].detailsDesc), "</p>", "\n")
- f:write("</handNote>", "\n")
- j = j + 1
+ 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(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) ~= ""
+ 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 listPerson[i].note ~= ""
+ then
+ f:write("<note>", textotei(listPerson[i].note), "</note>", "\n")
+ end
+ f:write('</persName>', "\n")
+ f:write('</person>', "\n")
end
- f:write("</handDesc>", "\n")
- f:write("</physDesc>", "\n")
- else end
- if listWit[i].history ~= nil then
- f:write("<history>", "\n")
- f:write("<origin>", "\n")
- f:write("<origDate>", textotei(listWit[i].history.origin.origDate), "</origDate>", "\n")
- f:write("</origin>", "\n")
- f:write("</history>", "\n")
+ f:write("</listPerson>", "\n")
end
- f:write("</msDesc>", "\n")
- f:write("</witness>", "\n")
end
- f:write("</listWit>", "\n")
f:write("</sourceDesc>", "\n")
f:write("</fileDesc>", "\n")
f:write("<encodingDesc>", "\n")
@@ -1582,10 +1744,10 @@ function ekdosis.get_bagunits(teitype)
return bagunits[teitype]
end
-local function getapplimit(str)
+local function getapplimit(teitype)
for i = 1,#apparatuses
do
- if apparatuses[i].a == str then
+ if apparatuses[i].a == teitype then
limitfound = apparatuses[i].limit
break
end
@@ -1614,6 +1776,14 @@ function ekdosis.limit_bagunits(teitype)
end
end
+function ekdosis.addto_bagunits(teitype, n)
+ if tonumber(getapplimit(teitype)) ~= 0
+ then
+ n = tonumber(n)
+ bagunits[teitype] = bagunits[teitype] - n
+ end
+end
+
function ekdosis.increment_bagunits(teitype)
bagunits[teitype] = (bagunits[teitype] or 0) + 1
end