aboutsummaryrefslogtreecommitdiff
path: root/ekdosis.dtx
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2019-03-26 00:23:36 +0100
committerRobert Alessi <alessi@robertalessi.net>2019-03-26 00:23:36 +0100
commite760359b4dd2765f148b865ecf9f755fee72e87b (patch)
tree14c3f9b7e3c6d51fcf40b55966bbbba14a6ec8b9 /ekdosis.dtx
parent5842e21604d612a03721aa6b866283806c72c6fb (diff)
downloadekdosis-e760359b4dd2765f148b865ecf9f755fee72e87b.tar.gz
export 'wit' attribute to tei. added basic \DeclareNewWitness
Diffstat (limited to 'ekdosis.dtx')
-rw-r--r--ekdosis.dtx88
1 files changed, 71 insertions, 17 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index 796482f..ff530af 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -353,13 +353,13 @@ Running "make install" installs the files in the local TeX tree.
353% \end{macrocode} 353% \end{macrocode}
354% Build an process the list of witnesses 354% Build an process the list of witnesses
355% \begin{macrocode} 355% \begin{macrocode}
356\NewDocumentCommand{\NewWitness}{m m +m}{ 356\NewDocumentCommand{\DeclareNewWitness}{m m +m}{
357 \luadirect{ekdosis.newwitness(\luastringN{#1}, 357 \luadirect{ekdosis.newwitness(\luastringN{#1},
358 \luastringN{#2}, 358 \luastringN{#2},
359 \luastringN{#3})} 359 \luastringN{#3})}
360} 360}
361\NewDocumentCommand{\getsiglum}{m}{% 361\NewDocumentCommand{\getsiglum}{m}{%
362 \luadirect{tex.sprint(ekdosis.getsiglum(\luastring{#1}))} 362 \luadirect{tex.sprint(ekdosis.getsiglum(\luastringN{#1}))}
363} 363}
364% \end{macrocode} 364% \end{macrocode}
365% \begin{macrocode} 365% \begin{macrocode}
@@ -434,7 +434,7 @@ choice nolem={false,,true}][1]{%
434 }% 434 }%
435 \egroup{}% 435 \egroup{}%
436 \ifcommandkey{prewit}{ \commandkey{prewit} }{}% 436 \ifcommandkey{prewit}{ \commandkey{prewit} }{}%
437 \ifcommandkey{wit}{ \commandkey{wit}}{}% 437 \ifcommandkey{wit}{ \getsiglum{\commandkey{wit}}}{}%
438 \ifcommandkey{postwit}{ \commandkey{postwit}}{}:% 438 \ifcommandkey{postwit}{ \commandkey{postwit}}{}:%
439 }}% 439 }}%
440 {|\append@ln@app|{% 440 {|\append@ln@app|{%
@@ -448,7 +448,7 @@ choice nolem={false,,true}][1]{%
448 \ifcommandkey{post}{ \commandkey{post} }{}% 448 \ifcommandkey{post}{ \commandkey{post} }{}%
449 }% 449 }%
450 \ifcommandkey{prewit}{ \commandkey{prewit} }{}% 450 \ifcommandkey{prewit}{ \commandkey{prewit} }{}%
451 \ifcommandkey{wit}{ \commandkey{wit}}{}% 451 \ifcommandkey{wit}{ \getsiglum{\commandkey{wit}}}{}%
452 \ifcommandkey{postwit}{ \commandkey{postwit}}{}:% 452 \ifcommandkey{postwit}{ \commandkey{postwit}}{}:%
453 }}% 453 }}%
454|\fi|} 454|\fi|}
@@ -468,7 +468,7 @@ choice nolem={false,,true}][1]{%
468 }% 468 }%
469 \egroup{}% 469 \egroup{}%
470 \ifcommandkey{prewit}{ \commandkey{prewit} }{}% 470 \ifcommandkey{prewit}{ \commandkey{prewit} }{}%
471 \ifcommandkey{wit}{ \commandkey{wit}}{}% 471 \ifcommandkey{wit}{ \getsiglum{\commandkey{wit}}}{}%
472 \ifcommandkey{postwit}{ \commandkey{postwit}}{}% 472 \ifcommandkey{postwit}{ \commandkey{postwit}}{}%
473 }}% 473 }}%
474 {|\append@app|{% 474 {|\append@app|{%
@@ -482,7 +482,7 @@ choice nolem={false,,true}][1]{%
482 \ifcommandkey{post}{ \commandkey{post} }{}% 482 \ifcommandkey{post}{ \commandkey{post} }{}%
483 }% 483 }%
484 \ifcommandkey{prewit}{ \commandkey{prewit} }{}% 484 \ifcommandkey{prewit}{ \commandkey{prewit} }{}%
485 \ifcommandkey{wit}{ \commandkey{wit}}{}% 485 \ifcommandkey{wit}{ \getsiglum{\commandkey{wit}}}{}%
486 \ifcommandkey{postwit}{ \commandkey{postwit}}{}% 486 \ifcommandkey{postwit}{ \commandkey{postwit}}{}%
487 }}% 487 }}%
488} 488}
@@ -525,9 +525,33 @@ choice nolem={false,,true}][1]{%
525 525
526ekdosis = {} 526ekdosis = {}
527 527
528-- lpeg equivalent for string.gsub()
529local function gsub(s, patt, repl)
530 patt = lpeg.P(patt)
531 patt = lpeg.Cs((patt / repl + 1)^0)
532 return lpeg.match(patt, s)
533end
534
535-- some basic patterns:
536local ascii = lpeg.R("az", "AZ", "@@")
537local dblbkslash = lpeg.Cs("\\")
538local bsqbrackets = lpeg.Cs{ "[" * ((1 - lpeg.S"[]") + lpeg.V(1))^0 * "]" }
539local bcbraces = lpeg.Cs{ "{" * ((1 - lpeg.S"{}") + lpeg.V(1))^0 * "}" }
540local spce = lpeg.Cs(" ")
541local spcenc = lpeg.P(" ")
542local cmdstar = lpeg.Cs(spce * lpeg.P("*"))
543local bsqbracketsii = lpeg.Cs(bsqbrackets^-2)
544local bcbracesii = lpeg.Cs(bcbraces^-2)
545local cmd = lpeg.Cs(dblbkslash * ascii^1 * cmdstar^-1)
546local rawcmd = lpeg.Cs(dblbkslash * ascii^1)
547local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash)
548local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1)
549local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg"))
550
528listWit = {} 551listWit = {}
529 552
530function ekdosis.newwitness(id, siglum, description) 553function ekdosis.newwitness(id, siglum, description)
554 id = id..","
531 table.insert(listWit, {a = id, b = siglum, c = description}) 555 table.insert(listWit, {a = id, b = siglum, c = description})
532 table.sort(listWit, function(a ,b) return(#a.a > #b.a) end) 556 table.sort(listWit, function(a ,b) return(#a.a > #b.a) end)
533 return true 557 return true
@@ -542,15 +566,29 @@ function ekdosis.isintable(table, element)
542 return false 566 return false
543end 567end
544 568
545function ekdosis.getsiglum(str) 569function ekdosis.getsiglum(str, opt)
546-- if not ekdosis.isintable(listWit, str) then 570 str = str..","
547-- str = "<??>" 571 str = string.gsub(str, "%s-(%,)", "%1")
548-- else 572 ctrl = str
573 if opt == "tei" then
574 for i = 1,#listWit do
575 str = string.gsub(str, listWit[i].a, "#"..listWit[i].a)
576 ctrl = string.gsub(ctrl, listWit[i].a, "")
577 end
578 str = string.gsub(str, "%,(%s-)([%#])", " %2")
579 str = string.gsub(str, "%,$", "")
580 else
549 for i = 1,#listWit do 581 for i = 1,#listWit do
550 str = string.gsub(str, listWit[i].a, listWit[i].b) 582 str = string.gsub(str, listWit[i].a, listWit[i].b)
583 ctrl = string.gsub(ctrl, listWit[i].a, "")
551 end 584 end
552-- end 585 end
553 return str 586 if string.find(ctrl, "[A-Za-z0-9]")
587 then
588 return "<??>"
589 else
590 return str
591 end
554end 592end
555 593
556-- begin totei functions 594-- begin totei functions
@@ -567,13 +605,29 @@ local tags = {
567 {a="rdg", b="rdg", c=""} 605 {a="rdg", b="rdg", c=""}
568} 606}
569 607
608local function lem_rdg_totei(str)
609 str = gsub(str, dblbkslash * lemrdg * spcenc^-1 * bsqbrackets * bcbraces,
610 function(bkslash, cmd, opt, arg)
611 opt = string.sub(opt, 2, -2)
612 arg = string.sub(arg, 2, -2)
613 opt = string.gsub(opt, "wit%s?%=%s?(%b{})", function(bbraces)
614 bbraces = string.sub(bbraces, 2, -2)
615 bbraces = ekdosis.getsiglum(bbraces, "tei")
616 return string.format("%s", bbraces)
617 end)
618 return string.format("<%s wit=\"%s\">%s</%s>", cmd, opt, arg, cmd)
619 end)
620 return str
621end
622
570function ekdosis.textotei(str) 623function ekdosis.textotei(str)
571 str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>") 624 str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>")
625 str = lem_rdg_totei(str)
572 for i = 1,#tags 626 for i = 1,#tags
573 do 627 do
574 str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b{})", "%1[]%2") 628 str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b{})", "%1[]%2")
575 str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b[])(%b{})", 629 str = string.gsub(str, "(\\"..tags[i].a..")%s?(%b[])(%b{})",
576 function(tag, arg, body) 630 function(cmd, arg, body)
577 body = string.sub(body, 2, -2) 631 body = string.sub(body, 2, -2)
578 arg = string.sub(arg, 2, -2) 632 arg = string.sub(arg, 2, -2)
579 arg = string.gsub(arg, "(%b{})", function(braces) 633 arg = string.gsub(arg, "(%b{})", function(braces)
@@ -585,16 +639,16 @@ function ekdosis.textotei(str)
585 end) 639 end)
586 end 640 end
587 str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})", 641 str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})",
588 function(tag, opt, body) 642 function(cmd, opt, body)
589 body = string.sub(body, 2, -2) 643 body = string.sub(body, 2, -2)
590 body = ekdosis.textotei(body) 644 body = ekdosis.textotei(body)
591 return string.format("<%s>%s</%s>", tag, body, tag) 645 return string.format("<%s>%s</%s>", cmd, body, cmd)
592 end) 646 end)
593 str = string.gsub(str, "\\(%a+)%s?%*?(%b{})", 647 str = string.gsub(str, "\\(%a+)%s?%*?(%b{})",
594 function(tag, body) 648 function(cmd, body)
595 body = string.sub(body, 2, -2) 649 body = string.sub(body, 2, -2)
596 body = ekdosis.textotei(body) 650 body = ekdosis.textotei(body)
597 return string.format("<%s>%s</%s>", tag, body, tag) 651 return string.format("<%s>%s</%s>", cmd, body, cmd)
598 end) 652 end)
599 str = string.gsub(str, "(%s)(%>)", "%2") 653 str = string.gsub(str, "(%s)(%>)", "%2")
600 return str 654 return str