From 216a8a300531d01c1fc8d206a750b249c527e8bb Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Tue, 28 Apr 2020 21:05:20 +0200 Subject: new function \MkBodyDivs --- ekdosis.dtx | 62 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index e46a6d5..2b47132 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -1137,6 +1137,20 @@ Running "make install" installs the files in the local TeX tree. \luadirect{ekdosis.flushcolnums()} } % \end{macrocode} +% Divisions of the Body +% \begin{macrocode} +\NewDocumentCommand{\MkBodyDivs}{mmmmmm}{ + \luadirect{ekdosis.mkdivdepths( + \luastringN{#1}, + \luastringN{#2}, + \luastringN{#3}, + \luastringN{#4}, + \luastringN{#5}, + \luastringN{#6} + ) + } +} +% \end{macrocode} % Very basic implementation of poetry lines:--- % \begin{macrocode} \newlength{\ekdverseindentlength} @@ -1195,8 +1209,7 @@ local poemline = lpeg.Cs(lnbrk * bsqbrackets^-1) local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1) local sections = lpeg.Cs(lpeg.P("book") + lpeg.P("part") + lpeg.P("chapter") + lpeg.P("section") + lpeg.P("subsection") - + lpeg.P("subsubsection") + lpeg.P("paragraph") - + lpeg.P("subparagraph")) + + lpeg.P("subsubsection")) -- Bind to local variables local next = next @@ -1819,16 +1832,29 @@ local function self_close_tags(str) end local divdepth = { - book = 0, - part = 1, - chapter = 2, - section = 3, - subsection = 4, - subsubsection = 5, - paragraph = 6, - subparagraph = 7 + book = 1, + part = 2, + chapter = 3, + section = 4, + subsection = 5, + subsubsection = 6 } +function ekdosis.mkdivdepths(...) + divdepth = {} + local num = 1 + for _, y in ipairs{...} + do + if y == "book" or "part" or "chapter" or "section" or "subsection" or "subsubsection" + then + divdepth[y] = num + num = num + 1 + else + end + end + return true +end + local function section_totei(str) str = gsub(str, dblbkslash * sections * spce^-1 * bcbraces, "%1%2%3[]%4") str = gsub(str, dblbkslash * sections * spce^-1 * bsqbrackets * bcbraces, @@ -1854,9 +1880,9 @@ local function close_ndivs_at_end(str) else end -- collect used div numbers - for i in string.gmatch(str, " #b.a) end) else end - local firstdiv = string.match(str, ")", "%1%3") +-- str = string.gsub(str, "()", "%1%3") if isdiv then return str..closedivs.."" @@ -1897,7 +1923,7 @@ end local function close_ndivs_in_between(str) for ndivi = 0, 9 do - str = string.gsub(str, "()(.-)()", + str = string.gsub(str, "()(.-)()", function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii) local firstdiv = ndivi local lastdiv = ndivii -- cgit v1.2.3