aboutsummaryrefslogtreecommitdiff
path: root/ekdosis.dtx
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2019-03-24 17:59:52 +0100
committerRobert Alessi <alessi@robertalessi.net>2019-03-24 17:59:52 +0100
commit5842e21604d612a03721aa6b866283806c72c6fb (patch)
tree3cca802fe6e3e353765533749cfd45ae046e1e0c /ekdosis.dtx
parentbb57f2a6f33788bd7b4c735467ec65714cbc3ee5 (diff)
downloadekdosis-5842e21604d612a03721aa6b866283806c72c6fb.tar.gz
export to tei: first implementation
Diffstat (limited to 'ekdosis.dtx')
-rw-r--r--ekdosis.dtx118
1 files changed, 114 insertions, 4 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index a8426eb..796482f 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -321,6 +321,9 @@ Running "make install" installs the files in the local TeX tree.
321 \@pkg@parnotestrue\@parnotesromantrue 321 \@pkg@parnotestrue\@parnotesromantrue
322 \fi\fi\fi 322 \fi\fi\fi
323}{\PackageWarning{ekdosis}{parnotes: erroneous input (ignored)}} 323}{\PackageWarning{ekdosis}{parnotes: erroneous input (ignored)}}
324\newif\iftei@export
325\define@boolkey{ekdosis.sty}[@pkg@]{teiexport}[true]{%
326 \if@pkg@teiexport\tei@exporttrue\else\fi}
324\ExecuteOptionsX{} 327\ExecuteOptionsX{}
325\ProcessOptionsX\relax 328\ProcessOptionsX\relax
326\RequirePackage{luacode} 329\RequirePackage{luacode}
@@ -343,7 +346,21 @@ Running "make install" installs the files in the local TeX tree.
343\luadirect{dofile(kpse.find_file("ekdosis.lua"))} 346\luadirect{dofile(kpse.find_file("ekdosis.lua"))}
344% \end{macrocode} 347% \end{macrocode}
345% \begin{macrocode} 348% \begin{macrocode}
346\AtEndDocument{\luadirect{ekdosis.closestream()}} 349\AtEndDocument{
350 \luadirect{ekdosis.closestream()}
351 \luadirect{ekdosis.closeteistream()}
352}
353% \end{macrocode}
354% Build an process the list of witnesses
355% \begin{macrocode}
356\NewDocumentCommand{\NewWitness}{m m +m}{
357 \luadirect{ekdosis.newwitness(\luastringN{#1},
358 \luastringN{#2},
359 \luastringN{#3})}
360}
361\NewDocumentCommand{\getsiglum}{m}{%
362 \luadirect{tex.sprint(ekdosis.getsiglum(\luastring{#1}))}
363}
347% \end{macrocode} 364% \end{macrocode}
348% \begin{macrocode} 365% \begin{macrocode}
349\newbool{ekd@started} 366\newbool{ekd@started}
@@ -488,12 +505,13 @@ choice nolem={false,,true}][1]{%
488\NewDocumentCommand{\EkdosisOff}{}{% 505\NewDocumentCommand{\EkdosisOff}{}{%
489 \setbool{ekd@state}{false}% 506 \setbool{ekd@state}{false}%
490} 507}
491\newenvironment{ekdosis}{% 508\NewDocumentEnvironment{ekdosis}{+b}{%
492 \begin{linenumbers} 509 \begin{linenumbers}
493 \EkdosisStart% 510 \EkdosisStart%
494 \EkdosisOn}{% 511 \EkdosisOn#1}{%
495 \EkdosisOff 512 \EkdosisOff
496 \end{linenumbers}} 513 \end{linenumbers}%
514 \iftei@export\luadirect{ekdosis.exporttei(\luastringN{#1})}\else\fi}
497% \end{macrocode} 515% \end{macrocode}
498% \iffalse 516% \iffalse
499%</package> 517%</package>
@@ -507,6 +525,98 @@ choice nolem={false,,true}][1]{%
507 525
508ekdosis = {} 526ekdosis = {}
509 527
528listWit = {}
529
530function ekdosis.newwitness(id, siglum, description)
531 table.insert(listWit, {a = id, b = siglum, c = description})
532 table.sort(listWit, function(a ,b) return(#a.a > #b.a) end)
533 return true
534end
535
536function ekdosis.isintable(table, element)
537 for i = 1,#table do
538 if table[i].a == element then
539 return true
540 end
541 end
542 return false
543end
544
545function ekdosis.getsiglum(str)
546-- if not ekdosis.isintable(listWit, str) then
547-- str = "<??>"
548-- else
549 for i = 1,#listWit do
550 str = string.gsub(str, listWit[i].a, listWit[i].b)
551 end
552-- end
553 return str
554end
555
556-- begin totei functions
557local tags = {
558 {a="footnote", b="note", c=" pos=\"foot\""},
559 {a="textbf", b="hi", c=" rend=\"bold\""},
560 {a="emph", b="hi", c=" rend=\"italic\""},
561 {a="textsf", b="hi", c=" rend=\"sans\""},
562 {a="txarb", b="foreign", c=" xml:lang=\"arb\""},
563 {a="arb", b="foreign", c=" xml:lang=\"arb\""},
564 {a="sg", b="foreign", c=" xml:lang=\"grc\""},
565 {a="app", b="app", c=""},
566 {a="lem", b="lem", c=""},
567 {a="rdg", b="rdg", c=""}
568}
569
570function ekdosis.textotei(str)
571 str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>")
572 for i = 1,#tags
573 do
574 str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b{})", "%1[]%2")
575 str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b[])(%b{})",
576 function(tag, arg, body)
577 body = string.sub(body, 2, -2)
578 arg = string.sub(arg, 2, -2)
579 arg = string.gsub(arg, "(%b{})", function(braces)
580 braces = string.sub(braces, 2, -2)
581 return string.format("\"%s\"", braces)
582 end)
583 body = ekdosis.textotei(body)
584 return string.format("<"..tags[i].b..tags[i].c.." %s>%s</"..tags[i].b..">", arg, body)
585 end)
586 end
587 str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})",
588 function(tag, opt, body)
589 body = string.sub(body, 2, -2)
590 body = ekdosis.textotei(body)
591 return string.format("<%s>%s</%s>", tag, body, tag)
592 end)
593 str = string.gsub(str, "\\(%a+)%s?%*?(%b{})",
594 function(tag, body)
595 body = string.sub(body, 2, -2)
596 body = ekdosis.textotei(body)
597 return string.format("<%s>%s</%s>", tag, body, tag)
598 end)
599 str = string.gsub(str, "(%s)(%>)", "%2")
600 return str
601end
602
603function ekdosis.closeteistream()
604 os.remove(tex.jobname.."-tei.xml")
605 os.rename(tex.jobname.."_tmp-tei.xml", tex.jobname.."-tei.xml")
606 return true
607end
608
609function ekdosis.exporttei(str)
610 local f = io.open(tex.jobname.."_tmp-tei.xml", "a+")
611 str = ekdosis.textotei(str)
612 f:write("\n<p>")
613 f:write(str)
614 f:write("</p>")
615 f:close()
616 return true
617end
618-- end totei functions
619
510function ekdosis.closestream() 620function ekdosis.closestream()
511 os.remove(tex.jobname..".ekd") 621 os.remove(tex.jobname..".ekd")
512 os.rename(tex.jobname.."_tmp.ekd", tex.jobname..".ekd") 622 os.rename(tex.jobname.."_tmp.ekd", tex.jobname..".ekd")