From ac803d5170d7cd82c9658b1b6887a46f6a626239 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Wed, 5 Aug 2020 18:06:53 +0200 Subject: added support for biblatex through icite. improved label/ref to tei --- ekdosis.dtx | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 103 insertions(+), 12 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index 3f50def..c85aec8 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -5400,6 +5400,13 @@ local sections = lpeg.Cs(lpeg.P("book") + lpeg.P("part") + lpeg.P("chapter") 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 labelrefcmds = lpeg.Cs(lpeg.P("label") + + lpeg.P("linelabel") + + lpeg.P("lineref") + + lpeg.P("ref") + + lpeg.P("pageref") + + lpeg.P("vref") + + lpeg.P("vpageref")) -- Bind to local variables local next = next @@ -5494,7 +5501,7 @@ function ekdosis.newwitness(id, then tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" ..id.. - "\" is not a valid xml:id. " + "\" is not a valid xml:id. \\MessageBreak " .. "Please pick another id.}}") else @@ -5534,7 +5541,7 @@ function ekdosis.newhand(id, witid, siglum, description) then tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" ..id.. - "\" is not a valid xml:id. " + "\" is not a valid xml:id. \\MessageBreak " .. "Please pick another id.}}") else @@ -5591,7 +5598,7 @@ function ekdosis.newscholar(id, siglum) then tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" ..id.. - "\" is not a valid xml:id. " + "\" is not a valid xml:id. \\MessageBreak " .. "Please pick another id.}}") else @@ -5656,13 +5663,13 @@ local cmdtotags = { local texpatttotags = { {a="\\altrfont%s+", b=""}, - {a="\\icite%s?%[(.-)%]%[(.-)%]{(.-)}", b="%1 %2"}, - {a="\\icite%s?%[(.-)%]{(.-)}", b="%1"}, - {a="\\icite%s?{(.-)}", b=""}, - {a="\\linelabel%s?{(.-)}", b=""}, - {a="\\label%s?{(.-)}", b=""}, - {a="\\v?pageref%s?{(.-)}", b=""}, - {a="\\v?ref%s?{(.-)}", b=""}, + -- {a="\\icite%s?%[(.-)%]%[(.-)%]{(.-)}", b="%1 %2"}, + -- {a="\\icite%s?%[(.-)%]{(.-)}", b="%1"}, + -- {a="\\icite%s?{(.-)}", b=""}, + -- {a="\\linelabel%s?{(.-)}", b=""}, + -- {a="\\label%s?{(.-)}", b=""}, + -- {a="\\v?pageref%s?{(.-)}", b=""}, + -- {a="\\v?ref%s?{(.-)}", b=""}, {a="\\LR%s+{(.-)}", b="%1"}, {a="\\RL%s+{(.-)}", b="%1"} } @@ -5928,6 +5935,70 @@ local function texpatttotei(str) return str end +local function icitetotei(str) + str = gsub(str, lpeg.P("\\") + * lpeg.Cs("icite") + * 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 %s", pre, body, post) + end) + str = gsub(str, lpeg.P("\\") + * lpeg.Cs("icite") + * 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("%s", body, post) + end) + str = gsub(str, lpeg.P("\\") + * lpeg.Cs("icite") + * 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("", body) + end) + return str +end + local function cmdtotei(str) for i = 1,#cmdtotags do @@ -5963,6 +6034,25 @@ local function cmdtotei(str) return string.format("%s", 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("", body) + else + return string.format("", body) + end + end) str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})", function(cmd, opt, body) body = string.sub(body, 2, -2) @@ -6296,6 +6386,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) @@ -6654,7 +6745,7 @@ function ekdosis.newscholar(id, siglum) then tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" ..id.. - "\" is not a valid xml:id. " + "\" is not a valid xml:id. \\MessageBreak " .. "Please pick another id.}}") else @@ -6687,7 +6778,7 @@ local function build_envdiv(str) then tex.print("\\unexpanded{\\PackageWarning{ekdosis}{\"" ..div.. - "\" is not a valid xml:id. " + "\" is not a valid xml:id. \\MessageBreak " .. "Please pick another id.}}") else -- cgit v1.2.3