From a150a011bb28e5728aa95534403bb43d026a6a41 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Fri, 16 Apr 2021 08:33:02 +0200 Subject: improved \TeXtoTEIPat --- ekdosis.dtx | 39 ++++++++++++++++++++++++++++++++------- ekdosis.el | 4 ++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index c9161cc..5efc419 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -5872,6 +5872,14 @@ many mathematical writings and to the sense of % strings captured are inserted where each of them is expected in % the \texttt{TEI} element. % +% \danger If the entire string to be captured be enclosed in square or +% curly brackets, it is advisable to use |@b|\texttt{\emph{n}} (for +% curly brackets) or |@s|\texttt{\emph{n}} (for square brackets) +% instead of |#|\texttt{\emph{n}}, where \texttt{\emph{n}} is the the +% number that is expected in the sequence. This will prevent any +% brackets that may be found in the captured string from being +% interpreted. +% % \danger Strings must be entered exactly as \pkg{ekdosis} will find % them as the |.tex| source file is compiled. Specifically, % \emph{control sequences}, namely the coded commands immediately @@ -5886,14 +5894,22 @@ many mathematical writings and to the sense of % \iffalse %<*example> % \fi -\begin{minted}[linenos=false]{latex} -\TeXtoTEIPat{\textcolor␣{#1}{#2}}{#2} +\begin{minted}[linenos]{latex} +\TeXtoTEIPat{\textcolor␣{#1}@b2}{@b2} Sample text with a \textcolor{red}{word} in red. \end{minted} % \iffalse % % \fi +% +% \begin{remarks} +% \item[\textsc{Rem.}] As can be seen from l.~1, it is safe to use +% |#1| for the first string for color names are naturally formed of +% letters without braces. However, |@b2| is preferable to capture +% the whole second argument of \cs{textcolor} for it may contain +% words within braces. +% \end{remarks} % % \iffalse %<*example> @@ -9203,7 +9219,7 @@ end local function checkxmlid(str) if string.find(str, "^[0-9]") - or string.find(str, "[:; ]") + or string.find(str, "[%{%}%[%]%(%):; ]") then return false else @@ -9515,16 +9531,17 @@ local texpatttotags = { {a="\\pagebreak%s+%[[1-4]%]", b=""}, {a="\\pagebreak%s+", b=""}, {a="\\altrfont%s+", b=""}, - {a="\\mbox%s+{(.-)}", b="%1"}, - {a="\\LR%s+{(.-)}", b="%1"}, - {a="\\RL%s+{(.-)}", b="%1"}, + {a="\\mbox%s+(%b{})", b="ekd@ob%1ekd@cb"}, + {a="\\LR%s+(%b{})", b="ekd@ob%1ekd@cb"}, + {a="\\RL%s+(%b{})", b="ekd@ob%1ekd@cb"}, {a="\\%=%=%=%s?", b="—"}, {a="\\%-%-%-%s?", b="—"}, {a="\\%=%=%s?", b="–"}, {a="\\%-%-%s?", b="–"}, {a="\\%=%/%s?", b="‐"}, {a="\\%-%/%s?", b="‐"}, - {a="\\vin%s+", b=""} + {a="\\vin%s+", b=""}, + {a="\\uc%s+(%b{})", b="ekd@ob%1ekd@cb"} } local envtotags = { @@ -9568,8 +9585,12 @@ end function ekdosis.newpatttotag(pat, repl) pat = string.gsub(pat, "([%[%]])", "%%%1") + pat = string.gsub(pat, "%@b[1-9]", "(%%b{})") + pat = string.gsub(pat, "%@s[1-9]", "(%%b[])") pat = string.gsub(pat, "%#[1-9]", "(.-)") repl = string.gsub(repl, "%#([1-9])", "%%%1") + repl = string.gsub(repl, "%@b([1-9])", "ekd@ob%%%1ekd@cb") + repl = string.gsub(repl, "%@s([1-9])", "ekd@os%%%1ekd@cs") if isintable(texpatttotags, pat) then local index = get_a_index(pat, texpatttotags) @@ -9892,6 +9913,10 @@ end local function texpatttotei(str) for i = 1,#texpatttotags do str = string.gsub(str, texpatttotags[i].a, texpatttotags[i].b) + str = string.gsub(str, "ekd@ob%{", "") + str = string.gsub(str, "%}ekd@cb", "") + str = string.gsub(str, "ekd@os%[", "") + str = string.gsub(str, "%]ekd@cs", "") end return str end diff --git a/ekdosis.el b/ekdosis.el index 1df3fd3..f1d40b0 100644 --- a/ekdosis.el +++ b/ekdosis.el @@ -56,6 +56,8 @@ (defvar LaTeX-ekdosis-lem-options '(("wit") + ("source") + ("resp") ("alt") ("pre") ("post") @@ -68,6 +70,8 @@ (defvar LaTeX-ekdosis-rdg-options '(("wit") + ("source") + ("resp") ("alt") ("pre") ("post") -- cgit v1.2.3