aboutsummaryrefslogtreecommitdiff
path: root/ekdosis.dtx
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2019-09-23 22:22:31 +0200
committerRobert Alessi <alessi@robertalessi.net>2019-09-23 22:22:31 +0200
commit29f699359d2040eb090a88ba45fb9876cd169538 (patch)
tree09265e5125fb08180c405e056fbe97641bbe823d /ekdosis.dtx
parent08138be2648ce925ec46e2f60bebbd0f88d385c3 (diff)
downloadekdosis-29f699359d2040eb090a88ba45fb9876cd169538.tar.gz
started implementing multi-layer apparatuses. improved tei exporting of <lem/> and <rdg/>
Diffstat (limited to 'ekdosis.dtx')
-rw-r--r--ekdosis.dtx156
1 files changed, 119 insertions, 37 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index 39cc3a7..c81489d 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -440,9 +440,18 @@ idno={}, msName={}, origDate={}][3]{%
440} 440}
441\@onlypreamble\SetxmlBibResource 441\@onlypreamble\SetxmlBibResource
442% \end{macrocode} 442% \end{macrocode}
443% Multi-layer apparatuses
444% \begin{macrocode}
445\newif\ifekd@mapps
446\NewDocumentCommand{\DeclareApparatus}{m}{
447 \unless\ifekd@mapps\global\ekd@mappstrue\fi
448 \luadirect{ekdosis.newapparatus(\luastringN{#1})}
449}
450\@onlypreamble\DeclareApparatus
451% \end{macrocode}
443% \begin{macrocode} 452% \begin{macrocode}
444\newbool{do@app} 453\newbool{do@app}
445\newbool{ekd@state} 454\newif\ifekd@state
446\newif\ifekd@isinapp 455\newif\ifekd@isinapp
447\providebool{al@rlmode} 456\providebool{al@rlmode}
448\@ifpackageloaded{arabluatex}{}{% 457\@ifpackageloaded{arabluatex}{}{%
@@ -476,30 +485,39 @@ idno={}, msName={}, origDate={}][3]{%
476 \footnotesize\apparatus\ekd@end@apparatus% 485 \footnotesize\apparatus\ekd@end@apparatus%
477 \if@pkg@parnotes\parnotes\parnotereset\else\fi% 486 \if@pkg@parnotes\parnotes\parnotereset\else\fi%
478 }% 487 }%
479 \unconditional@appin{\rule{5cm}{0.5pt}\newline} 488 % \unconditional@appin{\rule{5cm}{0.5pt}\newline}
480} 489}
481\def\add@apparatus{% 490\def\add@apparatus{%
482 \test@apparatus% 491 \test@apparatus%
483 \ifbool{do@app}{\subsq@unitfalse\add@@apparatus}{}% 492 \ifbool{do@app}{\subsq@unitfalse\add@@apparatus}{}%
484} 493}
485\NewDocumentCommand{\append@app}{+m}{% 494\NewDocumentCommand{\append@app}{o +m}{%
486 \ifekd@isinapp% 495 \ifekd@isinapp%
487 \ifbool{ekd@state}{% 496 \ifekd@state%
488 \luadirect{ekdosis.appin(\luastringO{#1})}% 497 \IfNoValueTF{#1}%
489 }{}\else\fi} 498 {\luadirect{ekdosis.appin(\luastringO{#2})}}%
490\NewDocumentCommand{\append@ln@app}{+m}% 499 {\luadirect{ekdosis.appin(\luastringO{#2}, \luastringO{#1})}}%
491 {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#1}))}} 500 \fi%
492\NewDocumentCommand{\app}{ > { \TrimSpaces } +m}{% 501 \fi}
502\NewDocumentCommand{\append@ln@app}{o +m}{%
503 \IfNoValueTF{#1}
504 {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#2}))}}
505 {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#2},
506 \luastringO{#1}))}}}
507\define@cmdkey[ekd]{appnote}[ekdan@]{type}{}
508\NewDocumentCommand{\app}{O{} > { \TrimSpaces } +m}{%
509 \presetkeys[ekd]{appnote}{type=default}{}%
510 \setkeys[ekd]{appnote}{#1}%
493 \ekd@isinapptrue% 511 \ekd@isinapptrue%
494 \stepcounter{ekd@lab}% 512 \stepcounter{ekd@lab}%
495 \zlabel{ekd:\theekd@lab}% 513 \zlabel{ekd:\theekd@lab}%
496 \luadirect{ekdosis.storeabspg( 514 \luadirect{ekdosis.storeabspg(
497 \luastring{\zref@extract{ekd:\theekd@lab}{abspage}})}% 515 \luastring{\zref@extract{ekd:\theekd@lab}{abspage}})}%
498 \ifbool{ekd@state}{\add@apparatus}{}% 516 \ifekd@state\add@apparatus\fi%
499 \luadirect{% 517 \luadirect{%
500 ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}}, 518 ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}},
501 "pg_ii")}% 519 "pg_ii")}%
502 \luadirect{tex.sprint(ekdosis.removesp(\luastringN{#1}))}% 520 \luadirect{tex.sprint(ekdosis.removesp(\luastringN{#2}))}%
503 \ekd@isinappfalse} 521 \ekd@isinappfalse}
504\def\current@ref{{\textdir TLT\noexpand\bfseries% 522\def\current@ref{{\textdir TLT\noexpand\bfseries%
505 \ifnum% 523 \ifnum%
@@ -547,9 +565,10 @@ idno={}, msName={}, origDate={}][3]{%
547 \bgroup% 565 \bgroup%
548 \setkeys[ekd]{lemrdg,lem}{#1}% 566 \setkeys[ekd]{lemrdg,lem}{#1}%
549 \ifekdl@nolem\edef\lem@app{% 567 \ifekdl@nolem\edef\lem@app{%
550 \hskip .75em\ifsubsq@unit% 568 \hskip .75em\ifsubsq@unit%
551 \unexpanded\expandafter{\ekd@unit@delim}\else\fi% 569 \unexpanded\expandafter{\ekd@unit@delim}\else\fi%
552 \current@ref\hskip .25em}\else% 570 \current@ref\hskip .25em}%
571 \else%
553 \ifbool{al@rlmode}{% 572 \ifbool{al@rlmode}{%
554 \edef\lem@app{% 573 \edef\lem@app{%
555 \hskip .75em\ifsubsq@unit% 574 \hskip .75em\ifsubsq@unit%
@@ -608,14 +627,19 @@ idno={}, msName={}, origDate={}][3]{%
608 }% 627 }%
609 }% 628 }%
610 \fi% 629 \fi%
630 \ifekd@mapps%
631 \append@ln@app[\ekdan@type]{\lem@app}%
632 \else%
611 \append@ln@app{\lem@app}% 633 \append@ln@app{\lem@app}%
634 \fi%
612 \egroup% 635 \egroup%
613 \subsq@unittrue% 636 \subsq@unittrue%
614} 637}
615\NewDocumentCommand{\rdg}{O{} m}{% 638\NewDocumentCommand{\rdg}{O{} m}{%
616 \bgroup% 639 \bgroup%
617 \setkeys[ekd]{lemrdg,rdg}{#1}% 640 \setkeys[ekd]{lemrdg,rdg}{#1}%
618 \ifekdr@nordg\append@app{}\else% 641 \ifekdr@nordg\append@app{}\else% do we need \append@app{} here? If
642 % so, keep in mind \ifekd@mapps
619 \ifbool{al@rlmode}{% 643 \ifbool{al@rlmode}{%
620 \edef\rdg@app{% 644 \edef\rdg@app{%
621 \ifdefined\ekdlr@alt 645 \ifdefined\ekdlr@alt
@@ -665,8 +689,12 @@ idno={}, msName={}, origDate={}][3]{%
665 \space\unexpanded\expandafter{\ekdlr@postwit}\else\fi 689 \space\unexpanded\expandafter{\ekdlr@postwit}\else\fi
666 }% 690 }%
667 }% 691 }%
692 \ifekd@mapps%
693 \append@app[\ekdan@type]{\rdg@app}%
694 \else%
668 \append@app{\rdg@app}% 695 \append@app{\rdg@app}%
669 \fi% 696 \fi%
697 \fi%
670 \egroup% 698 \egroup%
671} 699}
672\newkeycommand+[\|]{\ekd@note}[pre, post][1]{% 700\newkeycommand+[\|]{\ekd@note}[pre, post][1]{%
@@ -707,9 +735,9 @@ idno={}, msName={}, origDate={}][3]{%
707 ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}}, 735 ekdosis.storeabspg(\luastring{\zref@extract{ekd:\theekd@lab}{abspage}},
708 "pg_i")}% 736 "pg_i")}%
709} 737}
710\NewDocumentCommand{\EkdosisOn}{}{\setbool{ekd@state}{true}} 738\NewDocumentCommand{\EkdosisOn}{}{\ekd@statetrue}
711\NewDocumentCommand{\EkdosisOff}{}{% 739\NewDocumentCommand{\EkdosisOff}{}{%
712 \setbool{ekd@state}{false}% 740 \ekd@statefalse%
713} 741}
714\NewDocumentEnvironment{ekdosis}{+b}{% 742\NewDocumentEnvironment{ekdosis}{+b}{%
715 \begin{linenumbers} 743 \begin{linenumbers}
@@ -752,6 +780,7 @@ local cmd = lpeg.Cs(dblbkslash * ascii^1 * cmdstar^-1)
752local rawcmd = lpeg.Cs(dblbkslash * ascii^1) 780local rawcmd = lpeg.Cs(dblbkslash * ascii^1)
753local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) 781local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash)
754local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) 782local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1)
783local app = lpeg.Cs("app")
755local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) 784local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg"))
756local lnbrk = lpeg.Cs("\\\\") 785local lnbrk = lpeg.Cs("\\\\")
757local poemline = lpeg.Cs(lnbrk * bsqbrackets^-1) 786local poemline = lpeg.Cs(lnbrk * bsqbrackets^-1)
@@ -1017,9 +1046,35 @@ local function xml_entities(str)
1017 return str 1046 return str
1018end 1047end
1019 1048
1020local function lem_rdg_totei(str) 1049local function app_totei(str)
1021 str = gsub(str, 1050 str = gsub(str,
1022 dblbkslash * 1051 dblbkslash *
1052 app *
1053 spcenc^-1 *
1054 bsqbrackets *
1055 bcbraces *
1056 spcenc^-1,
1057 function(bkslash, cmd, opt, arg)
1058 opt = string.sub(opt, 2, -2)
1059 arg = string.sub(arg, 2, -2)
1060 opt = string.match(opt, "%f[%w]type%s?%=%s?%b{}")
1061 or string.match(opt, "%f[%w]type%s?%=%s?%w+%f[%W]")
1062 or ""
1063 opt = string.gsub(opt, "type%s?%=%s?(%b{})", function(bbraces)
1064 bbraces = string.sub(bbraces, 2, -2)
1065 return string.format("%s", bbraces)
1066 end)
1067 opt = string.gsub(opt, "(type%s?%=%s?)(%w+%f[%W])", "%2")
1068 return app_totei(string.format("<%s type=\"%s\">%s</%s>",
1069 cmd, opt, arg, cmd))
1070 end)
1071 return str
1072end
1073
1074local function lem_rdg_totei(str)
1075 str = gsub(str,
1076 spcenc^-1 *
1077 dblbkslash *
1023 lemrdg * 1078 lemrdg *
1024 spcenc^-1 * 1079 spcenc^-1 *
1025 bsqbrackets * 1080 bsqbrackets *
@@ -1028,15 +1083,26 @@ local function lem_rdg_totei(str)
1028 function(bkslash, cmd, opt, arg) 1083 function(bkslash, cmd, opt, arg)
1029 opt = string.sub(opt, 2, -2) 1084 opt = string.sub(opt, 2, -2)
1030 arg = string.sub(arg, 2, -2) 1085 arg = string.sub(arg, 2, -2)
1031 opt = string.match(opt, "%f[%w]wit%s?%=%s?%b{}") or "" 1086 opt = string.match(opt, "%f[%w]wit%s?%=%s?%b{}")
1087 or string.match(opt, "%f[%w]wit%s?%=%s?%w+%f[%W]")
1088 or ""
1032 opt = string.gsub(opt, "wit%s?%=%s?(%b{})", function(bbraces) 1089 opt = string.gsub(opt, "wit%s?%=%s?(%b{})", function(bbraces)
1033 bbraces = string.sub(bbraces, 2, -2) 1090 bbraces = string.sub(bbraces, 2, -2)
1034 bbraces = ekdosis.getsiglum(bbraces, "tei") 1091 bbraces = ekdosis.getsiglum(bbraces, "tei")
1035 return string.format("%s", bbraces) 1092 return string.format("%s", bbraces)
1036 end) 1093 end)
1094 opt = string.gsub(opt, "(wit%s?%=%s?)(%w+%f[%W])", function(attr, value)
1095 value = ekdosis.getsiglum(value, "tei")
1096 return string.format("%s", value)
1097 end)
1037 return lem_rdg_totei(string.format("<%s wit=\"%s\">%s</%s>", 1098 return lem_rdg_totei(string.format("<%s wit=\"%s\">%s</%s>",
1038 cmd, opt, arg, cmd)) 1099 cmd, opt, arg, cmd))
1039 end) 1100 end)
1101 str = gsub(str, spcenc^-0 * dblbkslash * lemrdg * spcenc^-1 * bcbraces * spcenc^-1,
1102 function(bkslash, cmd, arg)
1103 arg = string.sub(arg, 2, -2)
1104 return lem_rdg_totei(string.format("<%s>%s</%s>", cmd, arg, cmd))
1105 end)
1040 return str 1106 return str
1041end 1107end
1042 1108
@@ -1138,6 +1204,7 @@ local function textotei(str)
1138 str = string.gsub(str, "%s?\\par%s?", "\n<p>") 1204 str = string.gsub(str, "%s?\\par%s?", "\n<p>")
1139 tei_p_open = true 1205 tei_p_open = true
1140 end 1206 end
1207 str = app_totei(str)
1141 str = lem_rdg_totei(str) 1208 str = lem_rdg_totei(str)
1142 str = versetotei(str) 1209 str = versetotei(str)
1143 str = envtotei(str) 1210 str = envtotei(str)
@@ -1367,6 +1434,7 @@ end
1367-- handle multiple layers in apparatuses 1434-- handle multiple layers in apparatuses
1368-- 1435--
1369local apparatuses = {} 1436local apparatuses = {}
1437local bagtype = {}
1370function ekdosis.newapparatus(teitype) 1438function ekdosis.newapparatus(teitype)
1371 if isintable(apparatuses, teitype) 1439 if isintable(apparatuses, teitype)
1372 then 1440 then
@@ -1376,6 +1444,7 @@ function ekdosis.newapparatus(teitype)
1376 else 1444 else
1377 table.insert(apparatuses, { a = teitype }) 1445 table.insert(apparatuses, { a = teitype })
1378 end 1446 end
1447 bagtype[type] = 1
1379 return true 1448 return true
1380end 1449end
1381 1450
@@ -1388,7 +1457,7 @@ function ekdosis.appin(str, teitype)
1388 for i = 1,#apparatuses 1457 for i = 1,#apparatuses
1389 do 1458 do
1390 if apparatuses[i].a == teitype then 1459 if apparatuses[i].a == teitype then
1391 local appno = i 1460 appno = i
1392 break 1461 break
1393 end 1462 end
1394 end 1463 end
@@ -1398,18 +1467,6 @@ function ekdosis.appin(str, teitype)
1398 return true 1467 return true
1399end 1468end
1400 1469
1401function ekdosis.appin_out(str, nl)
1402 local f = io.open(tex.jobname.."_tmp.ekd", "a+")
1403 if nl == "yes" then
1404 f:write(str, "\n")
1405 else
1406 f:write(str)
1407 end
1408 f:close()
1409 return true
1410end
1411
1412
1413function ekdosis.appout() 1470function ekdosis.appout()
1414 local file = io.open(tex.jobname..".ekd", "r") 1471 local file = io.open(tex.jobname..".ekd", "r")
1415 if file ~= nil then io.close(file) 1472 if file ~= nil then io.close(file)
@@ -1418,6 +1475,7 @@ function ekdosis.appout()
1418 local output = {} 1475 local output = {}
1419 if next(apparatuses) == nil then 1476 if next(apparatuses) == nil then
1420 -- table.insert(output, "BEGIN") 1477 -- table.insert(output, "BEGIN")
1478 table.insert(output, "\\par")
1421 for i in string.gmatch(t, 1479 for i in string.gmatch(t,
1422 "<"..cur_abs_pg.."%-0>.-</"..cur_abs_pg.."%-0>") 1480 "<"..cur_abs_pg.."%-0>.-</"..cur_abs_pg.."%-0>")
1423 do 1481 do
@@ -1429,6 +1487,7 @@ function ekdosis.appout()
1429 while apparatuses[n] 1487 while apparatuses[n]
1430 do 1488 do
1431 -- table.insert(output, "BEGIN") 1489 -- table.insert(output, "BEGIN")
1490 table.insert(output, "\\par")
1432 for i in string.gmatch(t, 1491 for i in string.gmatch(t,
1433 "<"..cur_abs_pg.."%-"..n..">.-</"..cur_abs_pg.."%-"..n..">") 1492 "<"..cur_abs_pg.."%-"..n..">.-</"..cur_abs_pg.."%-"..n..">")
1434 do 1493 do
@@ -1446,6 +1505,17 @@ function ekdosis.appout()
1446 else end 1505 else end
1447end 1506end
1448 1507
1508function ekdosis.appin_out(str, nl)
1509 local f = io.open(tex.jobname.."_tmp.ekd", "a+")
1510 if nl == "yes" then
1511 f:write(str, "\n")
1512 else
1513 f:write(str)
1514 end
1515 f:close()
1516 return true
1517end
1518
1449function ekdosis.testapparatus() 1519function ekdosis.testapparatus()
1450 if tonumber(pg_ii) < tonumber(pg_i) 1520 if tonumber(pg_ii) < tonumber(pg_i)
1451 or tonumber(pg_ii) < tonumber(cur_abs_pg) then 1521 or tonumber(pg_ii) < tonumber(cur_abs_pg) then
@@ -1496,15 +1566,27 @@ function ekdosis.getprevlnlab()
1496 return prev_lnlab 1566 return prev_lnlab
1497end 1567end
1498 1568
1499function ekdosis.mdvappend(str) 1569function ekdosis.mdvappend(str, teitype)
1500 return [[\linelabel{]] .. current_lnlab .. [[-b}\wordboundary{}]] 1570 if teitype == nil
1571 then
1572 return "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
1501 .. 1573 ..
1502 current_lemma 1574 current_lemma
1503 .. 1575 ..
1504 [[\linelabel{]] .. current_lnlab .. [[-e}]] 1576 "\\linelabel{" .. current_lnlab .. "-e}"
1577 ..
1578 "\\csname append@app\\endcsname{"
1579 .. str .. "}"
1580 else
1581 return "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
1505 .. 1582 ..
1506 [[\csname append@app\endcsname{]] 1583 current_lemma
1507 .. str .. [[}]] 1584 ..
1585 "\\linelabel{" .. current_lnlab .. "-e}"
1586 ..
1587 "\\csname append@app\\endcsname" .. "[" .. teitype .. "]{"
1588 .. str .. "}"
1589 end
1508end 1590end
1509 1591
1510% \end{ekdlua} 1592% \end{ekdlua}