aboutsummaryrefslogtreecommitdiff
path: root/ekdosis.dtx
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2019-04-26 14:18:12 +0200
committerRobert Alessi <alessi@robertalessi.net>2019-04-26 14:18:12 +0200
commita7ed6e42996771616d6810bb8e350c1f55d294a3 (patch)
tree2fe70b5c934bd55fdd63dc7f3b19afb7a7c84858 /ekdosis.dtx
parent37388e14beef9f4426f59235fa9d4dcef0056f98 (diff)
downloadekdosis-a7ed6e42996771616d6810bb8e350c1f55d294a3.tar.gz
new command \EnvtoTEI. check if <p> is open or not before inserting any other <p>
Diffstat (limited to 'ekdosis.dtx')
-rw-r--r--ekdosis.dtx97
1 files changed, 78 insertions, 19 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index 93679ea..2d4579c 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -281,8 +281,8 @@ Running "make install" installs the files in the local TeX tree.
281% \rule{3cm}{0.01cm}\par\footnotesize% 281% \rule{3cm}{0.01cm}\par\footnotesize%
282% \textbf{1}~Peter A: John B \textbf{2}~Peter A: John B 282% \textbf{1}~Peter A: John B \textbf{2}~Peter A: John B
283% \textbf{3}~Peter A: John B \textbf{4}~Peter A: John B}; \node at 283% \textbf{3}~Peter A: John B \textbf{4}~Peter A: John B}; \node at
284% (0,3) {\scriptsize $\approx$ \unit[25]{pt}}; \draw [->] (0,2.9) -- 284% (0,3) {\scriptsize $\approx$ \unit[25]{pt}}; \draw [->] (0,2.9)
285% (0,2); 285% -- (0,2);
286% \end{tikzpicture} 286% \end{tikzpicture}
287% \end{keyfigure} 287% \end{keyfigure}
288% 288%
@@ -425,6 +425,11 @@ idno={}, msName={}, origDate={}][3]{%
425 \luastringN{#2}, 425 \luastringN{#2},
426 \luastringN{#3})} 426 \luastringN{#3})}
427} 427}
428\NewDocumentCommand{\EnvtoTEI}{m m m}{%
429 \luadirect{ekdosis.newenvtotag(\luastringN{#1},
430 \luastringN{#2},
431 \luastringN{#3})}
432}
428% \end{macrocode} 433% \end{macrocode}
429% Set |TEI| file name 434% Set |TEI| file name
430% \begin{macrocode} 435% \begin{macrocode}
@@ -610,7 +615,8 @@ choice nordg={false,,true}][1]{%
610 \IfBooleanTF{#1}{\ekd@note@star[#2]{#3}} 615 \IfBooleanTF{#1}{\ekd@note@star[#2]{#3}}
611 {\ekd@note[#2]{#3}}% 616 {\ekd@note[#2]{#3}}%
612} 617}
613\NewDocumentCommand{\apparatus}{}{\luadirect{tex.sprint(ekdosis.appout())}} 618\NewDocumentCommand{\apparatus}{}{%
619 \luadirect{tex.sprint(ekdosis.appout())}}
614\NewDocumentCommand{\test@apparatus}{}{% 620\NewDocumentCommand{\test@apparatus}{}{%
615 \luadirect{tex.sprint(ekdosis.testapparatus())}} 621 \luadirect{tex.sprint(ekdosis.testapparatus())}}
616\NewDocumentCommand{\EkdosisStart}{}{% 622\NewDocumentCommand{\EkdosisStart}{}{%
@@ -668,6 +674,9 @@ local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash)
668local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) 674local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1)
669local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) 675local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg"))
670 676
677-- Booleans
678local tei_p_open = false
679
671-- General 680-- General
672xmlids = {} 681xmlids = {}
673 682
@@ -764,7 +773,8 @@ function ekdosis.newhand(id, witid, siglum, description)
764 listWit[indexwit].handDesc = {} 773 listWit[indexwit].handDesc = {}
765 else 774 else
766 end 775 end
767 table.insert(listWit[indexwit].handDesc, {xmlid = id, abbr = siglum, handNote = description}) 776 table.insert(listWit[indexwit].handDesc,
777 {xmlid = id, abbr = siglum, handNote = description})
768 end 778 end
769 return true 779 return true
770end 780end
@@ -819,7 +829,8 @@ function ekdosis.getsiglum(str, opt)
819 str = string.gsub(str, shorthands[i].a, shorthands[i].c) 829 str = string.gsub(str, shorthands[i].a, shorthands[i].c)
820 end 830 end
821 for i = 1,#idsRend do 831 for i = 1,#idsRend do
822 str = string.gsub(str, "(%f[%w])"..idsRend[i].xmlid.."(%,)", "%1#"..idsRend[i].xmlid.."%2") 832 str = string.gsub(str, "(%f[%w])"..idsRend[i].xmlid.."(%,)",
833 "%1#"..idsRend[i].xmlid.."%2")
823 ctrl = string.gsub(ctrl, idsRend[i].xmlid.."%,", "") 834 ctrl = string.gsub(ctrl, idsRend[i].xmlid.."%,", "")
824 end 835 end
825 str = string.gsub(str, "%,(%s-)([%#])", " %2") 836 str = string.gsub(str, "%,(%s-)([%#])", " %2")
@@ -851,12 +862,14 @@ local cmdtotags = {
851 {a="textsf", b="hi", c=" rend=\"sf\""}, 862 {a="textsf", b="hi", c=" rend=\"sf\""},
852 {a="arbup", b="hi", c=" rend=\"sup\""}, 863 {a="arbup", b="hi", c=" rend=\"sup\""},
853 {a="txarb", b="s", c=" xml:lang=\"arb\""}, 864 {a="txarb", b="s", c=" xml:lang=\"arb\""},
854 {a="arb", b="s", c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""} 865 {a="arb", b="s",
866 c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""}
855} 867}
856 868
857local envtotags = { 869local envtotags = {
858 {a="center", b="p", c=" rend=\"centered\""}, 870 {a="center", b="p", c=" rend=\"centered\""},
859 {a="arab", b="p", c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""} 871 {a="arab", b="p",
872 c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""}
860} 873}
861 874
862function ekdosis.newcmdtotag(cmd, tag, attr) 875function ekdosis.newcmdtotag(cmd, tag, attr)
@@ -874,6 +887,21 @@ function ekdosis.newcmdtotag(cmd, tag, attr)
874 return true 887 return true
875end 888end
876 889
890function ekdosis.newenvtotag(env, tag, attr)
891 if isintable(envtotags, env)
892 then
893 tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]]
894 ..cmd..
895 [[" already exists as a known environment to be processed to TEI. ]]
896 ..
897 [[Please pick another environment name.}}]])
898 else
899 table.insert(envtotags, {a = env, b = tag, c = " "..attr})
900 table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end)
901 end
902 return true
903end
904
877local function xml_entities(str) 905local function xml_entities(str)
878 str = string.gsub(str, "%<", "&lt;") 906 str = string.gsub(str, "%<", "&lt;")
879 str = string.gsub(str, "%>", "&gt;") 907 str = string.gsub(str, "%>", "&gt;")
@@ -881,7 +909,13 @@ local function xml_entities(str)
881end 909end
882 910
883local function lem_rdg_totei(str) 911local function lem_rdg_totei(str)
884 str = gsub(str, dblbkslash * lemrdg * spcenc^-1 * bsqbrackets * bcbraces * spcenc^-1, 912 str = gsub(str,
913 dblbkslash *
914 lemrdg *
915 spcenc^-1 *
916 bsqbrackets *
917 bcbraces *
918 spcenc^-1,
885 function(bkslash, cmd, opt, arg) 919 function(bkslash, cmd, opt, arg)
886 opt = string.sub(opt, 2, -2) 920 opt = string.sub(opt, 2, -2)
887 arg = string.sub(arg, 2, -2) 921 arg = string.sub(arg, 2, -2)
@@ -891,7 +925,8 @@ local function lem_rdg_totei(str)
891 bbraces = ekdosis.getsiglum(bbraces, "tei") 925 bbraces = ekdosis.getsiglum(bbraces, "tei")
892 return string.format("%s", bbraces) 926 return string.format("%s", bbraces)
893 end) 927 end)
894 return string.format("<%s wit=\"%s\">%s</%s>", cmd, opt, arg, cmd) 928 return string.format("<%s wit=\"%s\">%s</%s>",
929 cmd, opt, arg, cmd)
895 end) 930 end)
896 return str 931 return str
897end 932end
@@ -899,13 +934,24 @@ end
899local function envtotei(str) 934local function envtotei(str)
900 for i = 1,#envtotags 935 for i = 1,#envtotags
901 do 936 do
902 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") 937 if tei_p_open and envtotags[i].b == "p"
903 * lpeg.Cs(envtotags[i].a) * lpeg.P("}") 938 then
904 * bsqbracketsii * bcbracesii * spcenc^-1, 939 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
905 "<"..envtotags[i].b..envtotags[i].c..">") 940 * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
906 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{") 941 * bsqbracketsii * bcbracesii * spcenc^-1,
907 * lpeg.Cs(envtotags[i].a) * lpeg.P("}"), 942 "</p>\n<"..envtotags[i].b..envtotags[i].c..">")
908 "</"..envtotags[i].b..">") 943 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
944 * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
945 "</"..envtotags[i].b..">\n<p>")
946 else
947 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
948 * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
949 * bsqbracketsii * bcbracesii * spcenc^-1,
950 "<"..envtotags[i].b..envtotags[i].c..">")
951 str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{")
952 * lpeg.Cs(envtotags[i].a) * lpeg.P("}"),
953 "</"..envtotags[i].b..">")
954 end
909 end 955 end
910 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") 956 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
911 * lpeg.Cs(ascii^1) * lpeg.P("}") * bsqbracketsii 957 * lpeg.Cs(ascii^1) * lpeg.P("}") * bsqbracketsii
@@ -932,7 +978,8 @@ local function cmdtotei(str)
932 end) 978 end)
933 body = cmdtotei(body) 979 body = cmdtotei(body)
934 -- return string.format("<"..cmdtotags[i].b..cmdtotags[i].c.." %s>%s</"..cmdtotags[i].b..">", arg, body) 980 -- return string.format("<"..cmdtotags[i].b..cmdtotags[i].c.." %s>%s</"..cmdtotags[i].b..">", arg, body)
935 return string.format("<"..cmdtotags[i].b..cmdtotags[i].c..">%s</"..cmdtotags[i].b..">", body) 981 return string.format("<"..cmdtotags[i].b..cmdtotags[i].c..">%s</" ..
982 cmdtotags[i].b..">", body)
936 end) 983 end)
937 end 984 end
938 str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})", 985 str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})",
@@ -953,7 +1000,13 @@ end
953 1000
954function ekdosis.textotei(str) 1001function ekdosis.textotei(str)
955 str = xml_entities(str) 1002 str = xml_entities(str)
956 str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>") 1003 if tei_p_open
1004 then
1005 str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>")
1006 else
1007 str = string.gsub(str, "%s?\\par%s?", "\n<p>")
1008 tei_p_open = true
1009 end
957 str = lem_rdg_totei(str) 1010 str = lem_rdg_totei(str)
958 str = envtotei(str) 1011 str = envtotei(str)
959 str = cmdtotei(str) 1012 str = cmdtotei(str)
@@ -1096,8 +1149,14 @@ function ekdosis.exporttei(str)
1096 local f = io.open(teifilename.."_tmp.xml", "a+") 1149 local f = io.open(teifilename.."_tmp.xml", "a+")
1097 str = ekdosis.textotei(str) 1150 str = ekdosis.textotei(str)
1098 f:write("\n<p>") 1151 f:write("\n<p>")
1152 tei_p_open = true
1099 f:write(str) 1153 f:write(str)
1100 f:write("</p>") 1154 if tei_p_open
1155 then
1156 f:write("</p>")
1157 tei_p_open = false
1158 else
1159 end
1101 f:close() 1160 f:close()
1102 return true 1161 return true
1103end 1162end