From 5362413c4d74031afac3641a2d24f6861d526603 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 14 Aug 2020 20:27:05 +0000 Subject: ekdosis (14aug20) git-svn-id: svn://tug.org/texlive/trunk@56112 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.lua | 327 +++++++++++++++++---- Master/texmf-dist/tex/lualatex/ekdosis/ekdosis.sty | 160 ++++++++-- 2 files changed, 410 insertions(+), 77 deletions(-) (limited to 'Master/texmf-dist/tex/lualatex') 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 %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="\\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 %s", 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("%s", 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("", 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("%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) @@ -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+", "

") - str = string.gsub(str, "\\p@rb%s+", "

") - str = string.gsub(str, "\\p@r%s+", "") - str = string.gsub(str, "%s?\\par%s?", "

", 1) - str = string.gsub(str, "(%)(%s-)(%<%/?div%d?)", "%3") - str = string.gsub(str, "%s?\\par%s?", "

") - str = string.gsub(str, "

%s?

", "") - str = string.gsub(str, "(%)%s?(%)$", "%2") - str = string.gsub(str, "(%)%s?$", "") - str = string.gsub(str, "(

)%s?()", "%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+", "

") + str = string.gsub(str, "\\p@rb%s+", "

") + str = string.gsub(str, "\\p@r%s+", "") + str = string.gsub(str, "%s?\\par%s?", "

", 1) + str = string.gsub(str, "(%)(%s-)(%<%/?div%d?)", "%3") + str = string.gsub(str, "%s?\\par%s?", "

") + str = string.gsub(str, "

%s?

", "") + str = string.gsub(str, "(%)%s?(%)$", "%2") + str = string.gsub(str, "(%)%s?$", "") + str = string.gsub(str, "(

)%s?()", "%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..">.- { \TrimSpaces } +m}{% \begingroup @@ -394,8 +479,13 @@ \fi % \else + \ifekd@elidednumbers + \luadirect{tex.sprint(ekdosis.numrange(\luastring{\getrefnumber{#1}}, + \luastring{\getrefnumber{#2}}))}% + \else \LRnum{\getrefnumber{#1}}--% \LRnum{\getrefnumber{#2}}% issue the nos + \fi \fi% \else \LRnum{\getrefnumber{#1}}--% @@ -442,8 +532,14 @@ \fi % \else + \ifekd@elidednumbers + \luadirect{tex.sprint(ekdosis.numrange( + \luastring{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}, + \luastring{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}))}% issue the nos + \else \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}--% \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-e}}% issue the nos + \fi \fi% \else \LRnum{\getrefnumber{\luadirect{tex.sprint(ekdosis.getlnlab())}-b}}--% @@ -478,6 +574,7 @@ \NewDocumentCommand{\lem}{O{} m}{% \ekd@isinlemtrue% \luadirect{ekdosis.dolnlab(\luastringN{#2})}% + \null \bgroup% \ekvset{lem}{#1}% \ifekd@mapps% @@ -489,6 +586,7 @@ \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}% \def\ekd@munit@delim{% \luadirect{tex.sprint(ekdosis.getappdelim(\luastringO{\ekdan@type}))}}% + \luadirect{tex.sprint(ekdosis.limit_bagunits(\luastringO{\ekdan@type}))}% \fi% \ifekdl@nolem\edef\lem@app{% % \hskip .75em @@ -554,8 +652,8 @@ \ifdefined\ekdlr@pre% \space\unexpanded\expandafter{\ekdlr@pre}\space\else\fi \ltx@ifpackageloaded{babel}% - {\noexpand\selectlanguage{\languagename}\unexpanded{#2}}{% - \unexpanded{#2}}% + {{\noexpand\selectlanguage{\languagename}\unexpanded{#2}}}{% + {\unexpanded{#2}}}% \ifdefined\ekdlr@post% \space\unexpanded\expandafter{\ekdlr@post}\space\else\fi \fi @@ -627,8 +725,8 @@ \ifdefined\ekdlr@pre% \space\unexpanded\expandafter{\ekdlr@pre}\space\else\fi \ltx@ifpackageloaded{babel}% - {\noexpand\selectlanguage{\languagename}\unexpanded{#2}}{% - \unexpanded{#2}}% + {{\noexpand\selectlanguage{\languagename}\unexpanded{#2}}}{% + {\unexpanded{#2}}}% \ifdefined\ekdlr@post% \space\unexpanded\expandafter{\ekdlr@post}\space\else\fi \fi @@ -653,10 +751,12 @@ code labelb = \def\ekdn@labelb{#1}, code labele = \def\ekdn@labele{#1}, store sep = \ekdn@sep, + bool nosep = \ifekdn@nosep, initial type = default, initial sep = \ekdsep } \NewDocumentCommand{\note@noapp}{O{} +m}{% + \null \bgroup% \ekvset{note}{#1}% \stepcounter{ekd@lab}% @@ -673,6 +773,7 @@ \luadirect{ekdosis.increment_bagunits(\luastringO{\ekdan@type})}% \def\ekd@munit@delim{% \luadirect{tex.sprint(ekdosis.getappdelim(\luastringO{\ekdan@type}))}}% + \luadirect{tex.sprint(ekdosis.limit_bagunits(\luastringO{\ekdan@type}))}% \fi% \ifdefined\ekdn@labelb% \luadirect{tex.sprint(ekdosis.setnotelab(\luastringO{\ekdn@labelb}))}% @@ -691,7 +792,9 @@ \current@ref@arg{\ekdn@labelb}{\ekdn@labele}%\hskip .25em \ifdefined\ekdn@lem% {\textdir TRT\unexpanded\expandafter{\ekdn@lem}}% - \unexpanded\expandafter{\ekdn@sep}\else\fi% + \unless\ifekdn@nosep + \unexpanded\expandafter{\ekdn@sep}\fi + \else\fi% {\textdir TRT\unexpanded{#2}}}}% {\edef\note@contents{% % \hskip .75em @@ -707,18 +810,21 @@ {\noexpand\selectlanguage{\languagename}% \unexpanded\expandafter{\ekdn@lem}}% {\unexpanded\expandafter{\ekdn@lem}}% - \unexpanded\expandafter{\ekdn@sep}\else\fi% + \unless\ifekdn@nosep + \unexpanded\expandafter{\ekdn@sep}\fi + \else\fi% \ltx@ifpackageloaded{babel}% - {\noexpand\selectlanguage{\languagename}\unexpanded{#2}}{% - \unexpanded{#2}}}}% + {{\noexpand\selectlanguage{\languagename}\unexpanded{#2}}}{% + {\unexpanded{#2}}}}}% \ifekd@mapps% \unconditional@appin[\ekdan@type]{\note@contents}% \else% \unconditional@appin{\note@contents}% \fi% \luadirect{ekdosis.setprevnotelab(\luastringO{\ekdn@labelb})}% - \egroup% - \subsq@unittrue% + \egroup + \subsq@unittrue + \ignorespaces } \ekvdefinekeys{ekd@note}{ store pre = \pre@value, @@ -730,7 +836,7 @@ \edef\note@contents{% \ekvifdefinedNoVal{note}{pre}{}{% \unexpanded\expandafter{\pre@value}}% - \unexpanded{#2}% + {\unexpanded{#2}}% \ekvifdefinedNoVal{note}{post}{}{% \unexpanded\expandafter{\post@value}}% }% @@ -744,7 +850,7 @@ \edef\note@contents{% \ekvifdefinedNoVal{note}{pre}{}{% \unexpanded\expandafter{\pre@value}}% - \unskip\noexpand\parnote{#2}% + \unskip\noexpand\parnote{\unexpanded{#2}}% \ekvifdefinedNoVal{note}{post}{}{% \unexpanded\expandafter{\post@value}}% }% @@ -804,7 +910,6 @@ \endrunninglinenumbers% \iftei@export \luadirect{ekdosis.exporttei(\luastringN{\par #1\par })}\fi} -\newif\ifekd@pagelineation \ekvdefinekeys{ekd@align}{ store tcols = \tcols@num, store lcols = \lcols@num, @@ -827,7 +932,7 @@ initial apparatus = edition, default segmentation = auto } -\NewDocumentCommand{\SetEkdosisAlignment}{m}{ +\NewDocumentCommand{\SetAlignment}{m}{ \ekvset{ekd@align}{#1} } \patchcmd{\pcol@nextpage}{% @@ -914,7 +1019,7 @@ \MessageBreak `subsubsection', `paragraph' or `subparagraph'.}, initial depth = 1 } -\NewDocumentCommand{\ekdfmtdiv}{m m m}{ +\NewDocumentCommand{\FormatDiv}{m m m}{ \luadirect{ekdosis.fmtdiv(\luastring{#1}, \luastringN{#2}, \luastringN{#3})} @@ -954,6 +1059,7 @@ } \item[] }{\end{list}} +\NewDocumentEnvironment{ekdpar}{}{\par}{\par} \endinput %% %% End of file `ekdosis.sty'. -- cgit v1.2.3