From 959b7789787a6848434f2c4fe61ca932571b569d Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Sun, 27 Oct 2019 18:21:50 +0100 Subject: added flexible \TeXtoTEIPatt command --- ekdosis.dtx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ekdosis.dtx') diff --git a/ekdosis.dtx b/ekdosis.dtx index a7a6dac..5e9dedd 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -441,6 +441,9 @@ idno={}, msName={}, origDate={}][3]{% \luastringN{#4})} } } +\NewDocumentCommand{\TeXtoTEIPatt}{m m}{% + \luadirect{ekdosis.newpatttotag(\luastringN{#1}, \luastringN{#2})} +} % \end{macrocode} % Set |TEI| file name % \begin{macrocode} @@ -1289,6 +1292,8 @@ local cmdtotags = { c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""} } +local texpatttotags = {} + local envtotags = { {a="ekdverse", b="lg", c=""}, {a="txarabtr", b="p", c=" xml:lang=\"arb-Latn\" type=\"transliterated\""}, @@ -1319,6 +1324,13 @@ function ekdosis.newcmdtotag(cmd, tag, attr) return true end +function ekdosis.newpatttotag(pat, repl) + pat = string.gsub(pat, "%#[1-9]", "(.-)") + repl = string.gsub(repl, "%#", "%%") + table.insert(texpatttotags, { a = pat, b = repl }) + return true +end + function ekdosis.newenvtotag(env, tag, attr, closep) if isintable(envtotags, env) then @@ -1538,6 +1550,13 @@ local function envtotei(str) return str end +local function texpatttotei(str) + for i = 1,#texpatttotags do + str = string.gsub(str, texpatttotags[i].a, texpatttotags[i].b) + end + return str +end + local function cmdtotei(str) for i = 1,#cmdtotags do @@ -1588,6 +1607,7 @@ end local function textotei(str) str = xml_entities(str) + str = texpatttotei(str) if tei_p_open then str = string.gsub(str, "%s?\\par%s?", "

\n

") -- cgit v1.2.3