From 5b78bc5e83cb76a2e5b9e8bb989b92ded63027d4 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Thu, 19 Mar 2020 19:18:14 +0100 Subject: new functions: any column can have any number of distinct apparatuses --- ekdosis.dtx | 115 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 37 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index 8555005..dcc4d24 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -507,6 +507,7 @@ Running "make install" installs the files in the local TeX tree. \def\setLR{\boolfalse{al@rlmode}\pardir TLT \textdir TLT} } \newcounter{ekd@lab} +\globalcounter{ekd@lab} % \def\unconditional@appin#1{% % \luadirect{ekdosis.appin(\luastringN{#1})}% % } @@ -1079,6 +1080,9 @@ Running "make install" installs the files in the local TeX tree. initial texts = edition;translation, initial apparatus = edition, } +\NewDocumentCommand{\ekd@storecol}{m}{% + \luadirect{ekdosis.storecurcol(\luastring{\thecolumn})}% +} \NewDocumentEnvironment{alignment}{O{}} {% \ekvset{align}{#1}% @@ -1087,7 +1091,8 @@ Running "make install" installs the files in the local TeX tree. "texts" )} \luadirect{ekdosis.mkenvdata( - \luastring{\apparatus@value}, "apparatus")} + \luastring{\apparatus@value}, "apparatus" + )} \luadirect{tex.sprint(ekdosis.mkenv())} \ifekd@paired \begin{paracol}[\lcols@num]{\tcols@num} @@ -1095,8 +1100,10 @@ Running "make install" installs the files in the local TeX tree. \begin{paracol}[\lcols@num]*{\tcols@num} \fi } - {\luadirect{ekdosis.flushenvdata()} - \end{paracol}} + {\end{paracol} + \luadirect{ekdosis.flushenvdata()} + \luadirect{ekdosis.flushcolnums()} + } % \end{macrocode} % Very basic implementation of poetry lines:--- % \begin{macrocode} @@ -1946,17 +1953,18 @@ function ekdosis.mkenvdata(str, opt) end end --- idea: store this # in a lua variable as in ekdosis.storeabspg() --- above, then use it in the apparatus-page attributes -function ekdosis.getcurcol(str) - for i = 1,#aligned_texts - do - if aligned_texts[i].text == str then - colfound = aligned_texts[i].column - break - end - end - return colfound +local prevcol = nil +local curcol = "x" + +function ekdosis.storecurcol(n) + curcol = n + return true +end + +function ekdosis.flushcolnums() + prevcol = nil + curcol = "x" + return true end function ekdosis.flushenvdata() @@ -1975,12 +1983,14 @@ function ekdosis.mkenv() .. aligned_texts[i].text .. "}{}{\\begin{nthcolumn}{" .. aligned_texts[i].column - .."}\\begin{ekdosis}}{\\end{ekdosis}\\end{nthcolumn}}") + .."}\\begin{ekdosis}" + .."\\csname ekd@storecol\\endcsname{\\thecolumn}}{\\end{ekdosis}\\end{nthcolumn}}") table.insert(environments, "\\NewDocumentEnvironment{" .. aligned_texts[i].text .. "*}{O{}}{\\begin{nthcolumn*}{" .. aligned_texts[i].column - .."}\\begin{ekdosis}}{\\end{ekdosis}\\end{nthcolumn*}}") + .."}\\begin{ekdosis}" + .."\\csname ekd@storecol\\endcsname{\\thecolumn}}{\\end{ekdosis}\\end{nthcolumn*}}") else table.insert(environments, "\\NewDocumentEnvironment{" .. aligned_texts[i].text @@ -2058,7 +2068,7 @@ function ekdosis.appin(str, teitype) local f = io.open(tex.jobname.."_tmp.ekd", "a+") if next(apparatuses) == nil then - f:write("<", cur_abs_pg, "-0>", str, "\n") + f:write("<", cur_abs_pg, "-", curcol, "-0>", str, "\n") else for i = 1,#apparatuses do @@ -2067,7 +2077,7 @@ function ekdosis.appin(str, teitype) break end end - f:write("<", cur_abs_pg, "-", appno, ">", str, "\n") + f:write("<", cur_abs_pg, "-", curcol, "-", appno, ">", str, "\n") end f:close() return true @@ -2084,7 +2094,7 @@ function ekdosis.appout() table.insert(output, "\\noindent\\csname ekd@default@rule\\endcsname\\NLS{}") -- table.insert(output, "\\noindent ") for i in string.gmatch(t, - "<"..cur_abs_pg.."%-0>.-") + "<"..cur_abs_pg.."%-"..curcol.."%-0>.-") do table.insert(output, i) end @@ -2093,7 +2103,7 @@ function ekdosis.appout() local n = 1 while apparatuses[n] do - if string.match(t, "<"..cur_abs_pg.."%-"..n..">.-") + if string.match(t, "<"..cur_abs_pg.."%-"..curcol.."%-"..n..">.-") then -- table.insert(output, "BEGIN") table.insert(output, "\\bgroup{}") @@ -2142,7 +2152,7 @@ function ekdosis.appout() table.insert(output, "\\relax") end for i in string.gmatch(t, - "<"..cur_abs_pg.."%-"..n..">.-") + "<"..cur_abs_pg.."%-"..curcol.."%-"..n..">.-") do table.insert(output, i) end @@ -2159,10 +2169,11 @@ function ekdosis.appout() end f:close() str = table.concat(output) - str = string.gsub(str, "", "") - str = string.gsub(str, "<"..cur_abs_pg.."%-[0-9]>", " ") + str = string.gsub(str, "", "") + str = string.gsub(str, "<"..cur_abs_pg.."%-"..curcol.."%-[0-9]>", " ") return str - else end + else + end end function ekdosis.appin_out(str, nl) @@ -2177,21 +2188,51 @@ function ekdosis.appin_out(str, nl) end function ekdosis.testapparatus() - if tonumber(pg_ii) < tonumber(pg_i) - or tonumber(pg_ii) < tonumber(cur_abs_pg) then - pg_i = cur_abs_pg - if next(apparatuses) ~= nil then - reset_bagunits() + if curcol ~= "x" + then + if prevcol == nil or curcol ~= prevcol + then + prevcol = curcol + if next(apparatuses) ~= nil then + reset_bagunits() + end + return "\\booltrue{do@app}" + else + -- return "\\boolfalse{do@app}" + if tonumber(pg_ii) < tonumber(pg_i) + or tonumber(pg_ii) < tonumber(cur_abs_pg) then + pg_i = cur_abs_pg + if next(apparatuses) ~= nil then + reset_bagunits() + end + return "\\booltrue{do@app}" + elseif tonumber(pg_ii) == tonumber(pg_i) then + return "\\boolfalse{do@app}" + elseif tonumber(pg_ii) > tonumber(pg_i) then + pg_i = cur_abs_pg + if next(apparatuses) ~= nil then + reset_bagunits() + end + return "\\booltrue{do@app}" + end end - return "\\booltrue{do@app}" - elseif tonumber(pg_ii) == tonumber(pg_i) then - return "\\boolfalse{do@app}" - elseif tonumber(pg_ii) > tonumber(pg_i) then - pg_i = cur_abs_pg - if next(apparatuses) ~= nil then - reset_bagunits() + else + if tonumber(pg_ii) < tonumber(pg_i) + or tonumber(pg_ii) < tonumber(cur_abs_pg) then + pg_i = cur_abs_pg + if next(apparatuses) ~= nil then + reset_bagunits() + end + return "\\booltrue{do@app}" + elseif tonumber(pg_ii) == tonumber(pg_i) then + return "\\boolfalse{do@app}" + elseif tonumber(pg_ii) > tonumber(pg_i) then + pg_i = cur_abs_pg + if next(apparatuses) ~= nil then + reset_bagunits() + end + return "\\booltrue{do@app}" end - return "\\booltrue{do@app}" end end -- cgit v1.2.3