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.lua327
1 files changed, 277 insertions, 50 deletions
diff --git a/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua b/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
index cab5b029694..64e444d5912 100644
--- a/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
+++ b/Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua
@@ -57,10 +57,35 @@ local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1)
local sections = lpeg.Cs(lpeg.P("book") + lpeg.P("part") + lpeg.P("chapter")
+ lpeg.P("section") + lpeg.P("subsection")
+ lpeg.P("subsubsection"))
-local par = lpeg.P(lpeg.P("\\par") * spce^1)
-local parb = lpeg.P(lpeg.Cs("\\p@rb") * spce^1)
-local para = lpeg.P(lpeg.Cs("\\p@ra") * spce^1)
-
+local par = lpeg.P(lpeg.P("\\par") * spce^0)
+local parb = lpeg.P(lpeg.Cs("\\p@rb") * spce^0)
+local para = lpeg.P(lpeg.Cs("\\p@ra") * spce^0)
+local labelrefcmds = lpeg.Cs(lpeg.P("label")
+ + lpeg.P("linelabel")
+ + lpeg.P("lineref")
+ + lpeg.P("ref")
+ + lpeg.P("pageref")
+ + lpeg.P("vref")
+ + lpeg.P("vpageref"))
+local citecmds = lpeg.Cs(lpeg.P("icite")
+ + lpeg.P("cite")
+ + lpeg.P("Cite")
+ + lpeg.P("cite *")
+ + lpeg.P("parencite")
+ + lpeg.P("Parencite")
+ + lpeg.P("parencite *")
+ + lpeg.P("footcite")
+ + lpeg.P("footcitetext")
+ + lpeg.P("textcite")
+ + lpeg.P("Textcite")
+ + lpeg.P("smartcite")
+ + lpeg.P("Smartcite")
+ + lpeg.P("autocite")
+ + lpeg.P("Autocite")
+ + lpeg.P("autocite *")
+ + lpeg.P("Autocite *")
+)
+--
-- Bind to local variables
local next = next
@@ -76,6 +101,16 @@ local function xmlidfound(element)
return false
end
+local function checkxmlid(str)
+ if string.find(str, "^[0-9]")
+ or string.find(str, "[:; ]")
+ then
+ return false
+ else
+ return true
+ end
+end
+
-- Witnesses
listWit = {}
idsRend = {}
@@ -137,7 +172,14 @@ function ekdosis.newwitness(id,
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
..id..
- "\" already exists as a xml: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
@@ -170,7 +212,14 @@ function ekdosis.newhand(id, witid, siglum, description)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
..id..
- "\" already exists as a xml: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
@@ -220,9 +269,16 @@ function ekdosis.newscholar(id, siglum)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
..id..
- "\" already exists as a xml: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)
@@ -279,18 +335,17 @@ 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="\\icite%s?%[(.-)%]%[(.-)%]{(.-)}", b="%1 <ref target=\"#%3\">%2</ref>"},
- {a="\\icite%s?%[(.-)%]{(.-)}", b="<ref target=\"#%2\">%1</ref>"},
- {a="\\icite%s?{(.-)}", b="<ptr target=\"#%1\"/>"},
- {a="\\linelabel%s?{(.-)}", b="<anchor xml:id=\"%1\"/>"},
- {a="\\label%s?{(.-)}", b="<anchor xml:id=\"%1\"/>"},
- {a="\\v?pageref%s?{(.-)}", b="<ptr target=\"#%1\"/>"},
- {a="\\v?ref%s?{(.-)}", b="<ptr target=\"#%1\"/>"}
+ {a="\\pagebreak%s+%[[1-4]%]", b=""},
+ {a="\\pagebreak%s+", b=""},
+ {a="\\altrfont%s+", b=""},
+ {a="\\LR%s+{(.-)}", b="%1"},
+ {a="\\RL%s+{(.-)}", b="%1"}
}
local envtotags = {
@@ -299,6 +354,8 @@ local envtotags = {
{a="quotation", b="quote", c=""},
{a="ekdverse", b="lg", c=""},
{a="txarabtr", b="p", c=" xml:lang=\"ar-Latn\" type=\"transliterated\""},
+ {a="quoting", b="quote", c=""},
+ {a="ekdpar", b="p", c=""},
{a="txarab", b="p", c=" xml:lang=\"arb\""},
{a="center", b="p", c=" rend=\"align(center)\""},
{a="verse", b="lg", c=""},
@@ -553,6 +610,70 @@ local function texpatttotei(str)
return str
end
+local function icitetotei(str)
+ str = gsub(str, lpeg.P("\\")
+ * citecmds
+ * spcenc^-1
+ * bsqbrackets
+ * bsqbrackets
+ * bcbraces
+ * bsqbrackets^-1,
+ function(cmd, pre, post, body, opt)
+ pre = string.sub(pre, 2, -2)
+ post = string.sub(post, 2, -2)
+ body = string.sub(body, 2, -2)
+ if not checkxmlid(body)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..body..
+ "\" is not a valid xml:id. \\MessageBreak "
+ ..
+ "Please pick another id.}}")
+ else
+ end
+ return string.format("%s <ref target=\"#%s\">%s</ref>", pre, body, post)
+ end)
+ str = gsub(str, lpeg.P("\\")
+ * citecmds
+ * spcenc^-1
+ * bsqbrackets
+ * bcbraces
+ * bsqbrackets^-1,
+ function(cmd, post, body, opt)
+ post = string.sub(post, 2, -2)
+ body = string.sub(body, 2, -2)
+ if not checkxmlid(body)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..body..
+ "\" is not a valid xml:id. \\MessageBreak "
+ ..
+ "Please pick another id.}}")
+ else
+ end
+ return string.format("<ref target=\"#%s\">%s</ref>", body, post)
+ end)
+ str = gsub(str, lpeg.P("\\")
+ * citecmds
+ * spcenc^-1
+ * bcbraces
+ * bsqbrackets^-1,
+ function(cmd, body, opt)
+ body = string.sub(body, 2, -2)
+ if not checkxmlid(body)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..body..
+ "\" is not a valid xml:id. \\MessageBreak "
+ ..
+ "Please pick another id.}}")
+ else
+ end
+ return string.format("<ptr target=\"#%s\"/>", body)
+ end)
+ return str
+end
+
local function cmdtotei(str)
for i = 1,#cmdtotags
do
@@ -588,6 +709,25 @@ local function cmdtotei(str)
return string.format("<ref target=\"%s\">%s</ref>",
teisiglum, printsiglum)
end)
+ str = gsub(str, lpeg.P("\\") * labelrefcmds * spcenc^-1 * bcbraces,
+ function(cmd, body)
+ body = string.sub(body, 2, -2)
+ if not checkxmlid(body)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..body..
+ "\" is not a valid xml:id. \\MessageBreak "
+ ..
+ "Please pick another id.}}")
+ else
+ end
+ if string.find(cmd, "label")
+ then
+ return string.format("<anchor xml:id=\"%s\"/>", body)
+ else
+ return string.format("<ptr target=\"#%s\"/>", body)
+ end
+ end)
str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})",
function(cmd, opt, body)
body = string.sub(body, 2, -2)
@@ -604,19 +744,36 @@ local function cmdtotei(str)
return str
end
+local teiautopar = true
+
+function ekdosis.setteiautopar(choice)
+ if choice == "yes"
+ then
+ teiautopar = true
+ else
+ teiautopar = false
+ end
+ return true
+end
+
local function partotei(str)
- str = gsub(str, lpeg.P(lpeg.P("\\par") * spcenc^1)^1, "\\par ")
- str = gsub(str, ((para + parb) * par^-1)^2, "\\p@r ")
- str = string.gsub(str, "\\p@ra%s+", "<p>")
- str = string.gsub(str, "\\p@rb%s+", "</p>")
- str = string.gsub(str, "\\p@r%s+", "")
- str = string.gsub(str, "%s?\\par%s?", "<p>", 1)
- str = string.gsub(str, "(%<p%>)(%s-)(%<%/?div%d?)", "%3")
- str = string.gsub(str, "%s?\\par%s?", "</p><p>")
- str = string.gsub(str, "<p>%s?</p>", "")
- str = string.gsub(str, "(%<p%>)%s?(%</div%>)$", "%2")
- str = string.gsub(str, "(%<p%>)%s?$", "")
- str = string.gsub(str, "(<p>)%s?(<div.->)", "%2%1")
+ if teiautopar
+ then
+ str = gsub(str, lpeg.P(lpeg.P("\\par") * spcenc^1)^1, "\\par ")
+ str = gsub(str, ((para + parb) * par^-1)^2, "\\p@r ")
+ str = string.gsub(str, "\\p@ra%s+", "<p>")
+ str = string.gsub(str, "\\p@rb%s+", "</p>")
+ str = string.gsub(str, "\\p@r%s+", "")
+ str = string.gsub(str, "%s?\\par%s?", "<p>", 1)
+ str = string.gsub(str, "(%<p%>)(%s-)(%<%/?div%d?)", "%3")
+ str = string.gsub(str, "%s?\\par%s?", "</p><p>")
+ str = string.gsub(str, "<p>%s?</p>", "")
+ str = string.gsub(str, "(%<p%>)%s?(%</div%>)$", "%2")
+ str = string.gsub(str, "(%<p%>)%s?$", "")
+ str = string.gsub(str, "(<p>)%s?(<div.->)", "%2%1")
+ else
+ str = gsub(str, par + para + parb, "")
+ end
return str
end
@@ -921,6 +1078,7 @@ local function textotei(str)
str = envtotei(str)
str = ekddivs_totei(str)
str = section_totei(str)
+ str = icitetotei(str)
str = cmdtotei(str)
str = self_close_tags(str)
str = partotei(str)
@@ -1179,7 +1337,7 @@ function ekdosis.newalignment(str)
then
newalignment = false
cur_alignment = "-"
- cur_alignment_patt = "-"
+ cur_alignment_patt = "%-"
end
return true
end
@@ -1267,23 +1425,6 @@ 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
@@ -1296,10 +1437,17 @@ local function build_envdiv(str)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
..div..
- "\" already exists as a xml:id. "
+ "\" already exists as an xml:id. "
..
"ekdosis has generated some random id.}}")
return "div-"..math.random(1000,9999)
+ elseif not checkxmlid(div)
+ then
+ tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
+ ..div..
+ "\" is not a valid xml:id. \\MessageBreak "
+ ..
+ "Please pick another id.}}")
else
table.insert(xmlids, {xmlid = div})
table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end)
@@ -1398,7 +1546,8 @@ function ekdosis.newapparatus(teitype,
appdelim,
appsep,
appbhook,
- appehook)
+ appehook,
+ applimit)
if isintable(apparatuses, teitype)
then
tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\""
@@ -1411,7 +1560,8 @@ function ekdosis.newapparatus(teitype,
delim = appdelim,
sep = appsep,
bhook = appbhook,
- ehook = appehook})
+ ehook = appehook,
+ limit = applimit})
end
bagunits[teitype] = 1
return true
@@ -1432,6 +1582,38 @@ function ekdosis.get_bagunits(teitype)
return bagunits[teitype]
end
+local function getapplimit(str)
+ for i = 1,#apparatuses
+ do
+ if apparatuses[i].a == str then
+ limitfound = apparatuses[i].limit
+ break
+ end
+ end
+ if tonumber(limitfound) ~= nil
+ then
+ if tonumber(limitfound) < 10
+ then
+ return 0
+ else
+ return limitfound
+ end
+ else
+ return 0
+ end
+end
+
+function ekdosis.limit_bagunits(teitype)
+ local limit = tonumber(getapplimit(teitype))
+ if limit >= 10 and bagunits[teitype] > limit
+ then
+ bagunits[teitype] = 2
+ return "\\pagebreak"
+ else
+ return ""
+ end
+end
+
function ekdosis.increment_bagunits(teitype)
bagunits[teitype] = (bagunits[teitype] or 0) + 1
end
@@ -1472,7 +1654,8 @@ function ekdosis.appout()
local output = {}
if next(apparatuses) == nil then
-- table.insert(output, "BEGIN")
- table.insert(output, "\\noindent\\csname ekd@default@rule\\endcsname\\NLS{}")
+ table.insert(output, "\\noindent\\csname ekd@default@rule\\endcsname\\NLS")
+ table.insert(output, "\\csname ekd@begin@apparatus\\endcsname\\ignorespaces")
-- table.insert(output, "\\noindent ")
for i in string.gmatch(t,
"<"..cur_abs_pg
@@ -1489,8 +1672,8 @@ function ekdosis.appout()
local n = 1
while apparatuses[n]
do
- if string.match(t, "<"..cur_abs_pg..
- cur_alignment_patt
+ if string.match(t, "<"..cur_abs_pg
+ ..cur_alignment_patt
..curcol.."%-"..n..">.-</"
..cur_abs_pg
..cur_alignment_patt
@@ -1603,10 +1786,54 @@ function ekdosis.testapparatus()
if next(apparatuses) ~= nil then
reset_bagunits()
end
+ newalignment = false
return "\\booltrue{do@app}"
end
end
+local function get_ln_prefix(x, y)
+ for index = 1, string.len(x)
+ do
+ if string.sub(x, index, index) ~= string.sub(y, index, index)
+ then
+ return string.sub(x, 1, index - 1)
+ end
+ end
+end
+
+function ekdosis.numrange(x, y)
+ xstr = tostring(x)
+ ystr = tostring(y)
+ if x == y -- which will never apply
+ then
+ return "\\LRnum{" .. xstr .. "}"
+ elseif string.len(xstr) ~= string.len(ystr)
+ then
+ return "\\LRnum{" .. xstr .. "}--\\LRnum{" .. ystr .. "}"
+ else
+ common = get_ln_prefix(xstr, ystr)
+ if string.len(common) == 0
+ then
+ return "\\LRnum{" .. xstr .. "}--\\LRnum{" .. ystr .. "}"
+ elseif string.sub(xstr, -2, -2) == "1"
+ then
+ return "\\LRnum{"
+ .. string.sub(common, 1, -2)
+ .. string.sub(xstr, string.len(common), -1)
+ .. "}--\\LRnum{"
+ .. string.sub(ystr, string.len(common), -1)
+ .. "}"
+ else
+ return "\\LRnum{"
+ .. string.sub(common, 1, -1)
+ .. string.sub(xstr, string.len(common) + 1, -1)
+ .. "}--\\LRnum{"
+ .. string.sub(ystr, string.len(common) + 1, -1)
+ .. "}"
+ end
+ end
+end
+
local lnlabs = {}
local lnlab_salt = 0
local current_lnlab = nil