From db70ffae9b765557aa5c14e59e6515efde371794 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Tue, 26 Mar 2019 19:56:22 +0100 Subject: added \TeXtoTEI --- ekdosis.dtx | 78 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 21 deletions(-) (limited to 'ekdosis.dtx') diff --git a/ekdosis.dtx b/ekdosis.dtx index ad26fc9..c4a706f 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -134,6 +134,7 @@ Running "make install" installs the files in the local TeX tree. \documentclass{ltxdoc} \usepackage[letterpaper,margin=25mm,left=50mm,nohead]{geometry} \usepackage{metalogox} +\usepackage{hologo} \usepackage{hyperxmp} \usepackage{uri} \usepackage[numbered]{hypdoc} @@ -162,7 +163,7 @@ Running "make install" installs the files in the local TeX tree. \usepackage{units} \usepackage[newfloat=true]{minted} \newminted[ekdlua]{lua}{linenos, fontsize=\relsize{-0.5}, - xleftmargin=12pt, + xleftmargin=12pt, breaklines, numberblanklines=false, numbersep=3pt, firstnumber=last} \renewcommand{\theFancyVerbLine}{\rmfamily\smaller\arabic{FancyVerbLine}} \usepackage[contents]{colordoc} @@ -362,6 +363,14 @@ Running "make install" installs the files in the local TeX tree. \luadirect{tex.sprint(ekdosis.getsiglum(\luastringN{#1}))} } % \end{macrocode} +% Add a \hologo{(La)TeX} command to be processed as a |TEI xml| tag: +% \begin{macrocode} +\NewDocumentCommand{\TeXtoTEI}{m m m}{% + \luadirect{ekdosis.newcmdtotag(\luastringN{#1}, + \luastringN{#2}, + \luastringN{#3})} +} +% \end{macrocode} % \begin{macrocode} \newbool{ekd@started} \newbool{do@app} @@ -548,16 +557,10 @@ local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) +-- Witnesses listWit = {} -function ekdosis.newwitness(id, siglum, description) - id = id.."," - table.insert(listWit, {a = id, b = siglum, c = description}) - table.sort(listWit, function(a ,b) return(#a.a > #b.a) end) - return true -end - -function ekdosis.isintable(table, element) +local function isintable(table, element) for i = 1,#table do if table[i].a == element then return true @@ -566,13 +569,32 @@ function ekdosis.isintable(table, element) return false end +local sorted_no = 0 + +function ekdosis.newwitness(id, siglum, description) + if isintable(listWit, id..",") + then + tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]] + ..id.. + [[" already exists as a witness id. ]] + .. + [[Please pick another id.}}]]) + else + sorted_no = sorted_no + 1 + id = id.."," + table.insert(listWit, {a = id, b = siglum, c = description, d = sorted_no}) + table.sort(listWit, function(a ,b) return(#a.a > #b.a) end) + end + return true +end + function ekdosis.getsiglum(str, opt) str = str.."," str = string.gsub(str, "%s-(%,)", "%1") ctrl = str if opt == "tei" then for i = 1,#listWit do - str = string.gsub(str, listWit[i].a, "#"..listWit[i].a) + str = string.gsub(str, "(%f[%w])"..listWit[i].a, "%1#"..listWit[i].a) ctrl = string.gsub(ctrl, listWit[i].a, "") end str = string.gsub(str, "%,(%s-)([%#])", " %2") @@ -592,19 +614,33 @@ function ekdosis.getsiglum(str, opt) end -- begin totei functions -local tags = { - {a="footnote", b="note", c=" pos=\"foot\""}, +local cmdtotags = { + {a="footnote", b="note", c=" place=\"bottom\""}, {a="textbf", b="hi", c=" rend=\"bold\""}, - {a="emph", b="hi", c=" rend=\"italic\""}, - {a="textsf", b="hi", c=" rend=\"sans\""}, {a="txarb", b="foreign", c=" xml:lang=\"arb\""}, + {a="emph", b="hi", c=" rend=\"italic\""}, {a="arb", b="foreign", c=" xml:lang=\"arb\""}, - {a="sg", b="foreign", c=" xml:lang=\"grc\""}, {a="app", b="app", c=""}, {a="lem", b="lem", c=""}, {a="rdg", b="rdg", c=""} } +function ekdosis.newcmdtotag(cmd, tag, attr) + if isintable(cmdtotags, cmd) + then + tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]] + ..cmd.. + [[" already exists as a known command to be processed to TEI. ]] + .. + [[Please pick another command.}}]]) + else + table.insert(cmdtotags, {a = cmd, b = tag, c = " "..attr}) + table.sort(cmdtotags, function(a ,b) return(#a.a > #b.a) end) + end + return true +end + + local function lem_rdg_totei(str) str = gsub(str, dblbkslash * lemrdg * spcenc^-1 * bsqbrackets * bcbraces, function(bkslash, cmd, opt, arg) @@ -623,10 +659,10 @@ end function ekdosis.textotei(str) str = string.gsub(str, "%s?\\par%s?", "

\n

") str = lem_rdg_totei(str) - for i = 1,#tags + for i = 1,#cmdtotags do - str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b{})", "%1[]%2") - str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b[])(%b{})", + str = string.gsub(str, "(\\"..cmdtotags[i].a..")%s?(%b{})", "%1[]%2") + str = string.gsub(str, "(\\"..cmdtotags[i].a..")%s?(%b[])(%b{})", function(cmd, arg, body) body = string.sub(body, 2, -2) arg = string.sub(arg, 2, -2) @@ -635,7 +671,7 @@ function ekdosis.textotei(str) return string.format("\"%s\"", braces) end) body = ekdosis.textotei(body) - return string.format("<"..tags[i].b..tags[i].c.." %s>%s", arg, body) + return string.format("<"..cmdtotags[i].b..cmdtotags[i].c.." %s>%s", arg, body) end) end str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})", @@ -708,7 +744,7 @@ ekdosis.getabspg = function(pg) --not used end end -local function isintable(table, value) +local function mdvisintable(table, value) for _, v in pairs(table) do if v == value then return true end end @@ -761,7 +797,7 @@ local salt = 0 function ekdosis.mdvappend(str) i = md5.sumhexa(str) - if not isintable(md5items, i) then + if not mdvisintable(md5items, i) then table.insert(md5items, i) else i = i..salt -- cgit v1.2.3