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.lua241
1 files changed, 212 insertions, 29 deletions
diff --git a/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua b/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
index 4916d9c586b..f5f9bd22c41 100644
--- a/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
+++ b/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
@@ -51,6 +51,9 @@ local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1)
local app = lpeg.Cs("app")
local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg"))
local note = lpeg.Cs("note")
+local inlem = lpeg.Cs{ "<lem" * ((1 - (lpeg.P"<lem" + lpeg.P"</lem>")) + lpeg.V(1))^0 * "</lem>" }
+local inanchor = lpeg.Cs{ "<anchor" * ((1 - (lpeg.P"<" + lpeg.P">")) + lpeg.V(1))^0 * ">" }
+local inopeningnote = lpeg.Cs{ "<note" * ((1 - (lpeg.P"<" + lpeg.P">")) + lpeg.V(1))^0 * ">" }
local lnbrk = lpeg.Cs("\\\\")
local poemline = lpeg.Cs(lnbrk * spcenc^-1 * lpeg.S("*!")^-1 * bsqbrackets^-1 * spcenc^-1)
local poemlinebreak = lpeg.Cs(lnbrk * spcenc^-1 * lpeg.P("&gt;") * bsqbrackets^-1 * spcenc^-1)
@@ -107,7 +110,7 @@ end
local function checkxmlid(str)
if string.find(str, "^[0-9]")
- or string.find(str, "[:; ]")
+ or string.find(str, "[%{%}%[%]%(%):; ]")
then
return false
else
@@ -174,7 +177,8 @@ function ekdosis.newwitness(id,
Collection,
Idno,
MsName,
- OrigDate)
+ OrigDate,
+ Locus)
if xmlidfound(id)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
@@ -210,6 +214,10 @@ function ekdosis.newwitness(id,
listWit[indexwit].history = {}
listWit[indexwit].history.origin = {origDate = OrigDate}
end
+ if Locus ~= "" then
+ listWit[indexwit].msContents = {}
+ listWit[indexwit].msContents.msItemStruct = {locus = Locus}
+ end
end
return true
end
@@ -354,19 +362,22 @@ function ekdosis.getsiglum(str, opt)
ctrl = str
if opt == "tei" then
for i = 1,#shorthands do
- str = string.gsub(str, shorthands[i].a, shorthands[i].c)
+ local tempa = string.gsub(shorthands[i].a, "([%-%.%_])", "%%%1")
+ str = string.gsub(str, tempa, shorthands[i].c)
end
for i = 1,#idsRend do
- str = string.gsub(str, "(%f[%w])"..idsRend[i].xmlid.."(%,)",
+ local tempb = string.gsub(idsRend[i].xmlid, "([%-%.%_])", "%%%1")
+ str = string.gsub(str, "(%f[%w%-%.%_])"..tempb.."(%,)",
"%1#"..idsRend[i].xmlid.."%2")
- ctrl = string.gsub(ctrl, idsRend[i].xmlid.."%,", "")
+ ctrl = string.gsub(ctrl, tempb.."%,", "")
end
str = string.gsub(str, "%,(%s-)([%#])", " %2")
str = string.gsub(str, "%,$", "")
else
for i = 1,#idsRend do
- str = string.gsub(str, idsRend[i].xmlid.."%,", idsRend[i].abbr)
- ctrl = string.gsub(ctrl, idsRend[i].xmlid.."%,", "")
+ local tempc = string.gsub(idsRend[i].xmlid, "([%-%.%_])", "%%%1")
+ str = string.gsub(str, tempc.."%,", idsRend[i].abbr)
+ ctrl = string.gsub(ctrl, tempc.."%,", "")
end
end
-- if string.find(ctrl, "[A-Za-z0-9]")
@@ -389,14 +400,18 @@ local cmdtotags = {
{a="marginpar", b="note", c=" place=\"margin\""},
{a="footnote", b="note", c=" place=\"bottom\""},
{a="enquote", b="quote", c=""},
+ {a="prname *", b="span",
+ c=" xml:lang=\"ar-Latn\" type=\"transliterated\""},
+ {a="prname", b="span",
+ c=" xml:lang=\"ar-Latn\" type=\"transliterated\" subtype=\"arabtex\""},
{a="txtrans", b="s", c=" xml:lang=\"ar-Latn\" type=\"transliterated\""},
{a="textbf", b="hi", c=" rend=\"bold\""},
{a="textit", b="hi", c=" rend=\"italic\""},
{a="textsc", b="hi", c=" rend=\"smallcaps\""},
{a="textsf", b="hi", c=" rend=\"sf\""},
{a="arbup", b="hi", c=" rend=\"sup\""},
- {a="txarb", b="s", c=" xml:lang=\"arb\""},
- {a="arb", b="foreign",
+ {a="txarb", b="foreign", c=" xml:lang=\"arb\""},
+ {a="arb", b="span",
c=" xml:lang=\"ar-Latn\" type=\"transliterated\" subtype=\"arabtex\""}
}
@@ -408,22 +423,31 @@ local texpatttotags = {
{a="\\resetvlinenumber%s+", b=""},
{a="\\resetlinenumber%s+%[(.-)%]", b=""},
{a="\\resetlinenumber%s+", b=""},
+ {a="\\ekdresethfmarks%s+", b=""},
{a="\\indentpattern%s+{(.-)}", b=""},
+ {a="\\ekdnohfmark%s+", b=""},
{a="\\settowidth%s+{(.-)}{(.-)}", b=""},
{a="\\poemlines%s+{(.-)}", b=""},
{a="\\pagebreak%s+%[[1-4]%]", b=""},
{a="\\pagebreak%s+", b=""},
+ {a="\\teidirect%s+(%b[]){(.-)}(%b{})", b="<%2 ekd@os%1ekd@cs>ekd@ob%3ekd@cb</%2>"},
+ {a="\\teidirect%s+{(.-)}(%b{})", b="<%1>ekd@ob%2ekd@cb</%1>"},
{a="\\altrfont%s+", b=""},
- {a="\\mbox%s+{(.-)}", b="%1"},
- {a="\\LR%s+{(.-)}", b="%1"},
- {a="\\RL%s+{(.-)}", b="%1"},
+ {a="\\endmark%s+", b=""},
+ {a="\\ekdpb%s+%*?%[(.-)%]{(.-)}", b=""},
+ {a="\\ekdpb%s+%*?{(.-)}", b=""},
+ {a="\\ekdpb%s+%*\\?", b=""},
+ {a="\\mbox%s+(%b{})", b="ekd@ob%1ekd@cb"},
+ {a="\\LR%s+(%b{})", b="ekd@ob%1ekd@cb"},
+ {a="\\RL%s+(%b{})", b="ekd@ob%1ekd@cb"},
{a="\\%=%=%=%s?", b="—"},
{a="\\%-%-%-%s?", b="—"},
{a="\\%=%=%s?", b="–"},
{a="\\%-%-%s?", b="–"},
{a="\\%=%/%s?", b="‐"},
{a="\\%-%/%s?", b="‐"},
- {a="\\vin%s+", b=""}
+ {a="\\vin%s+", b=""},
+ {a="\\uc%s+(%b{})", b="ekd@ob%1ekd@cb"}
}
local envtotags = {
@@ -467,8 +491,12 @@ end
function ekdosis.newpatttotag(pat, repl)
pat = string.gsub(pat, "([%[%]])", "%%%1")
+ pat = string.gsub(pat, "%@b[1-9]", "(%%b{})")
+ pat = string.gsub(pat, "%@s[1-9]", "(%%b[])")
pat = string.gsub(pat, "%#[1-9]", "(.-)")
repl = string.gsub(repl, "%#([1-9])", "%%%1")
+ repl = string.gsub(repl, "%@b([1-9])", "ekd@ob%%%1ekd@cb")
+ repl = string.gsub(repl, "%@s([1-9])", "ekd@os%%%1ekd@cs")
if isintable(texpatttotags, pat)
then
local index = get_a_index(pat, texpatttotags)
@@ -561,6 +589,22 @@ local function note_totei(str)
return str
end
+local function remove_extra_anchors(str)
+ str = gsub(str, lpeg.Cs("</note>") * inanchor * inopeningnote, function(enote, anchor, bnote)
+ local id_one = string.gsub(anchor, "(%<anchor )(.-)(/%>)", "%2")
+ id_one = string.sub(get_attr_value(id_one, "xml:id"), 2, -2)
+ local id_two = string.match(bnote, "target%=.-right%((.-)%)")
+ id_two = string.gsub(id_two, ".-right%((.-)%)", "%1")
+ if id_one == id_two
+ then
+ return string.format("%s%s", enote, bnote)
+ else
+ return string.format("%s%s%s", enote, anchor, bnote)
+ end
+ end)
+ return str
+end
+
local function app_totei(str)
str = gsub(str,
dblbkslash *
@@ -647,7 +691,16 @@ local function lem_rdg_totei(str)
end
local function relocate_notes(str)
- str = string.gsub(str, "(%<lem.-%>.-)(%<note.->.-%<%/note%>)(.-%<%/lem%>)", "%1%3%2")
+ str = gsub(str, inlem, function(arg)
+ local notes = {}
+ for i in string.gmatch(arg, "%<note.-%>.-%<%/note%>")
+ do
+ table.insert(notes, i)
+ end
+ allnotes = table.concat(notes)
+ arg = string.gsub(arg, "%<note.->.-%<%/note%>", "")
+ return string.format("%s%s", arg, allnotes)
+ end)
return str
end
@@ -766,6 +819,10 @@ end
local function texpatttotei(str)
for i = 1,#texpatttotags do
str = string.gsub(str, texpatttotags[i].a, texpatttotags[i].b)
+ str = string.gsub(str, "ekd@ob%{", "")
+ str = string.gsub(str, "%}ekd@cb", "")
+ str = string.gsub(str, "ekd@os%[", "")
+ str = string.gsub(str, "%]ekd@cs", "")
end
return str
end
@@ -791,7 +848,8 @@ local function icitetotei(str)
"Please pick another id.}}")
else
end
- return string.format("%s <ref target=\"#%s\">%s</ref>", pre, body, post)
+ return string.format("%s <bibl corresp=\"#%s\"><biblScope>%s</biblScope></bibl>",
+ pre, body, post)
end)
str = gsub(str, lpeg.P("\\")
* citecmds
@@ -811,7 +869,7 @@ local function icitetotei(str)
"Please pick another id.}}")
else
end
- return string.format("<ref target=\"#%s\">%s</ref>", body, post)
+ return string.format("<bibl corresp=\"#%s\"><biblScope>%s</biblScope></bibl>", body, post)
end)
str = gsub(str, lpeg.P("\\")
* citecmds
@@ -967,6 +1025,86 @@ local function self_close_tags(str)
return str
end
+--headers and footers
+local hfmarks = {}
+
+function ekdosis.storehfmark(page, mk, opt)
+ if opt == "endmk"
+ then
+ local emark = hfmarks[#hfmarks].mark
+ table.insert(hfmarks, {a = page, mark = emark})
+ else
+ table.insert(hfmarks, {a = page, mark = mk})
+ end
+ return true
+end
+
+local printhfmarks = {
+ HEL = true,
+ HEC = true,
+ HER = true,
+ HOL = true,
+ HOC = true,
+ HOR = true,
+ FOL = true,
+ FOC = true,
+ FOR = true,
+ FEL = true,
+ FEC = true,
+ FER = true,
+}
+
+function ekdosis.nohfmark()
+ printhfmarks.HEL = false
+ printhfmarks.HEC = false
+ printhfmarks.HER = false
+ printhfmarks.HOL = false
+ printhfmarks.HOC = false
+ printhfmarks.HOR = false
+ printhfmarks.FOL = false
+ printhfmarks.FOC = false
+ printhfmarks.FOR = false
+ printhfmarks.FEL = false
+ printhfmarks.FEC = false
+ printhfmarks.FER = false
+end
+
+function ekdosis.resethfmark()
+ printhfmarks.HEL = true
+ printhfmarks.HEC = true
+ printhfmarks.HER = true
+ printhfmarks.HOL = true
+ printhfmarks.HOC = true
+ printhfmarks.HOR = true
+ printhfmarks.FOL = true
+ printhfmarks.FOC = true
+ printhfmarks.FOR = true
+ printhfmarks.FEL = true
+ printhfmarks.FEC = true
+ printhfmarks.FER = true
+end
+
+function ekdosis.printmark(str, mk)
+ if printhfmarks[mk]
+ then
+ return str
+ else
+ printhfmarks[mk] = true
+ return ""
+ end
+end
+
+function ekdosis.gethfmark(page)
+ local indexpage = get_a_index(page, hfmarks)
+ if hfmarks[indexpage] ~= nil
+ then
+ return hfmarks[indexpage].mark
+ else
+ return hfmarks[#hfmarks-1].mark or ""
+ end
+end
+
+-- divisions of the body text
local divdepth = {
book = 1,
part = 2,
@@ -1175,7 +1313,7 @@ end
local function close_ekddivs_in_between(str)
local maxdepth = 1
- for i in string.gmatch(str, "<div.-depth=\"(%d)\".->", "%1")
+ for i in string.gmatch(str, "<div.-[Dd]epth=\"(%d)\".->", "%1")
do
if tonumber(i) > tonumber(maxdepth)
then
@@ -1200,9 +1338,9 @@ local function close_ekddivs_in_between(str)
do
closedivs = closedivs.."</div>"
firstdivindex = firstdivindex - 1
+ bdivii = string.gsub(bdivii, "depth", "Depth")
end
end
- bdivii = string.gsub(bdivii, "depth", "Depth")
return string.format("%s%s%s%s%s%s%s%s",
bdivi, ndivi, edivi, between,
closedivs, bdivii, ndivii, edivii)
@@ -1235,9 +1373,9 @@ local function close_ndivs_in_between(str)
do
closedivs = closedivs.."</div"..used_ndivs[firstdivindex].a..">"
firstdivindex = firstdivindex - 1
+ bdivii = string.gsub(bdivii, "div", "Div")
end
end
- bdivii = string.gsub(bdivii, "div", "Div")
return string.format("%s%s%s%s%s%s%s%s",
bdivi, ndivi, edivi, between,
closedivs, bdivii, ndivii, edivii)
@@ -1256,6 +1394,7 @@ local function textotei(str)
str = xml_entities(str)
str = texpatttotei(str)
str = note_totei(str)
+ str = remove_extra_anchors(str)
str = app_totei(str)
str = rdgGrp_totei(str)
str = lem_rdg_totei(str)
@@ -1364,7 +1503,14 @@ function ekdosis.openteistream()
end
f:write("</handDesc>", "\n")
f:write("</physDesc>", "\n")
- else end
+ else end
+ if listWit[i].msContents ~= nil then
+ f:write("<msContents>", "\n")
+ f:write("<msItemStruct>", "\n")
+ f:write("<locus>", textotei(listWit[i].msContents.msItemStruct.locus), "</locus>", "\n")
+ f:write("</msItemStruct>", "\n")
+ f:write("</msContents>", "\n")
+ end
if listWit[i].history ~= nil then
f:write("<history>", "\n")
f:write("<origin>", "\n")
@@ -1505,7 +1651,15 @@ function ekdosis.basic_cs(msid)
else
date = ""
end
- return siglum.."&"..name.."&"..date
+ if listWit[indexwit].msContents ~= nil
+ and
+ listWit[indexwit].msContents.msItemStruct ~= nil
+ then
+ locus = listWit[indexwit].msContents.msItemStruct.locus
+ else
+ locus = ""
+ end
+ return siglum.."&"..name.." "..locus.."&"..date
end
-- end basic TeX Conspectus siglorum
@@ -1784,7 +1938,8 @@ function ekdosis.newapparatus(teitype,
appbhook,
appehook,
applimit,
- applang)
+ applang,
+ appnotelang)
if isintable(apparatuses, teitype)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
@@ -1799,7 +1954,8 @@ function ekdosis.newapparatus(teitype,
bhook = appbhook,
ehook = appehook,
limit = applimit,
- lang = applang})
+ lang = applang,
+ notelang = appnotelang})
end
bagunits[teitype] = 1
return true
@@ -1815,6 +1971,16 @@ function ekdosis.getapplang(teitype)
end
end
+function ekdosis.getappnotelang(teitype)
+ i = get_a_index(teitype, apparatuses)
+ if apparatuses[i].notelang ~= ""
+ then
+ return apparatuses[i].notelang
+ else
+ return "\\languagename"
+ end
+end
+
function ekdosis.getappdelim(str)
for i = 1,#apparatuses
do
@@ -1853,7 +2019,7 @@ end
function ekdosis.limit_bagunits(teitype)
local limit = tonumber(getapplimit(teitype))
- if limit >= 10 and bagunits[teitype] > limit
+ if limit >= 10 and bagunits[teitype] >= limit
then
bagunits[teitype] = 2
return "\\pagebreak"
@@ -2109,6 +2275,8 @@ local lnlabs = {}
local lnlab_salt = 0
local current_lnlab = nil
local prev_lnlab = nil
+local prev_prev_lnlab = nil
+local notelabs = {}
local current_notelab = nil
local prev_notelab = nil
local current_lemma = nil
@@ -2122,6 +2290,7 @@ local function mdvisintable(table, value)
end
function ekdosis.dolnlab(str)
+ if prev_lnlab ~= nil then prev_prev_lnlab = prev_lnlab end
prev_lnlab = current_lnlab
current_lemma = str
i = md5.sumhexa(str)
@@ -2144,9 +2313,19 @@ function ekdosis.getprevlnlab()
return prev_lnlab
end
+function ekdosis.getprevprevlnlab()
+ return prev_prev_lnlab
+end
+
function ekdosis.setnotelab(str)
current_notelab = str
- return "\\linelabel{" .. current_notelab .. "}"
+ if isfound(notelabs, current_notelab)
+ then
+ return ""
+ else
+ table.insert(notelabs, current_notelab)
+ return "\\linelabel{" .. current_notelab .. "}"
+ end
end
function ekdosis.getnotelab()
@@ -2162,8 +2341,12 @@ function ekdosis.getprevnotelab()
return prev_notelab
end
-local function remove_note(str)
- str = gsub(str, dblbkslash * lpeg.P("note") * cmdargs, "")
+local cmdstorm = lpeg.P(lpeg.P("note")
+ + lpeg.P("linelabel")
+ + lpeg.P("index"))
+
+local function remove_from_app(str)
+ str = gsub(str, dblbkslash * cmdstorm * cmdargs, "")
return str
end
@@ -2177,7 +2360,7 @@ function ekdosis.mdvappend(str, teitype)
"\\linelabel{" .. current_lnlab .. "-e}"
..
"\\csname append@app\\endcsname{"
- .. remove_note(str) .. "}"
+ .. remove_from_app(str) .. "}"
else
return "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
..
@@ -2186,7 +2369,7 @@ function ekdosis.mdvappend(str, teitype)
"\\linelabel{" .. current_lnlab .. "-e}"
..
"\\csname append@app\\endcsname" .. "[" .. teitype .. "]{"
- .. remove_note(str) .. "}"
+ .. remove_from_app(str) .. "}"
end
end