aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2020-04-28 21:05:20 +0200
committerRobert Alessi <alessi@robertalessi.net>2020-04-28 21:05:20 +0200
commit216a8a300531d01c1fc8d206a750b249c527e8bb (patch)
tree453eae1c600bad2761dc6c37437e644ecf25bd3a
parent2dffe397f9a027ae551037e6f1c0b27e2350bf08 (diff)
downloadekdosis-216a8a300531d01c1fc8d206a750b249c527e8bb.tar.gz
new function \MkBodyDivs
-rw-r--r--ekdosis.dtx62
1 files 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.
1137 \luadirect{ekdosis.flushcolnums()} 1137 \luadirect{ekdosis.flushcolnums()}
1138 } 1138 }
1139% \end{macrocode} 1139% \end{macrocode}
1140% Divisions of the Body
1141% \begin{macrocode}
1142\NewDocumentCommand{\MkBodyDivs}{mmmmmm}{
1143 \luadirect{ekdosis.mkdivdepths(
1144 \luastringN{#1},
1145 \luastringN{#2},
1146 \luastringN{#3},
1147 \luastringN{#4},
1148 \luastringN{#5},
1149 \luastringN{#6}
1150 )
1151 }
1152}
1153% \end{macrocode}
1140% Very basic implementation of poetry lines:--- 1154% Very basic implementation of poetry lines:---
1141% \begin{macrocode} 1155% \begin{macrocode}
1142\newlength{\ekdverseindentlength} 1156\newlength{\ekdverseindentlength}
@@ -1195,8 +1209,7 @@ local poemline = lpeg.Cs(lnbrk * bsqbrackets^-1)
1195local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1) 1209local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1)
1196local sections = lpeg.Cs(lpeg.P("book") + lpeg.P("part") + lpeg.P("chapter") 1210local sections = lpeg.Cs(lpeg.P("book") + lpeg.P("part") + lpeg.P("chapter")
1197 + lpeg.P("section") + lpeg.P("subsection") 1211 + lpeg.P("section") + lpeg.P("subsection")
1198 + lpeg.P("subsubsection") + lpeg.P("paragraph") 1212 + lpeg.P("subsubsection"))
1199 + lpeg.P("subparagraph"))
1200 1213
1201-- Bind to local variables 1214-- Bind to local variables
1202local next = next 1215local next = next
@@ -1819,16 +1832,29 @@ local function self_close_tags(str)
1819end 1832end
1820 1833
1821local divdepth = { 1834local divdepth = {
1822 book = 0, 1835 book = 1,
1823 part = 1, 1836 part = 2,
1824 chapter = 2, 1837 chapter = 3,
1825 section = 3, 1838 section = 4,
1826 subsection = 4, 1839 subsection = 5,
1827 subsubsection = 5, 1840 subsubsection = 6
1828 paragraph = 6,
1829 subparagraph = 7
1830} 1841}
1831 1842
1843function ekdosis.mkdivdepths(...)
1844 divdepth = {}
1845 local num = 1
1846 for _, y in ipairs{...}
1847 do
1848 if y == "book" or "part" or "chapter" or "section" or "subsection" or "subsubsection"
1849 then
1850 divdepth[y] = num
1851 num = num + 1
1852 else
1853 end
1854 end
1855 return true
1856end
1857
1832local function section_totei(str) 1858local function section_totei(str)
1833 str = gsub(str, dblbkslash * sections * spce^-1 * bcbraces, "%1%2%3[]%4") 1859 str = gsub(str, dblbkslash * sections * spce^-1 * bcbraces, "%1%2%3[]%4")
1834 str = gsub(str, dblbkslash * sections * spce^-1 * bsqbrackets * bcbraces, 1860 str = gsub(str, dblbkslash * sections * spce^-1 * bsqbrackets * bcbraces,
@@ -1854,9 +1880,9 @@ local function close_ndivs_at_end(str)
1854 else 1880 else
1855 end 1881 end
1856 -- collect used div numbers 1882 -- collect used div numbers
1857 for i in string.gmatch(str, "<div%d") 1883 for i in string.gmatch(str, "<div[1-6]")
1858 do 1884 do
1859 i = string.match(i, "%d") 1885 i = string.match(i, "[1-6]")
1860 if isintable(used_ndivs, i) 1886 if isintable(used_ndivs, i)
1861 then 1887 then
1862 else 1888 else
@@ -1868,10 +1894,10 @@ local function close_ndivs_at_end(str)
1868 table.sort(used_ndivs, function(a ,b) return(#a.a > #b.a) end) 1894 table.sort(used_ndivs, function(a ,b) return(#a.a > #b.a) end)
1869 else 1895 else
1870 end 1896 end
1871 local firstdiv = string.match(str, "<div%d") or "" 1897 local firstdiv = string.match(str, "<div[1-6]") or ""
1872 firstdiv = string.match(firstdiv, "%d") or "" 1898 firstdiv = string.match(firstdiv, "[1-6]") or ""
1873 local lastdiv = string.match(string.reverse(str), "%dvid<") or "" 1899 local lastdiv = string.match(string.reverse(str), "[1-6]vid<") or ""
1874 lastdiv = string.match(lastdiv, "%d") or "" 1900 lastdiv = string.match(lastdiv, "[1-6]") or ""
1875 local firstdivindex = get_a_index(firstdiv, used_ndivs) 1901 local firstdivindex = get_a_index(firstdiv, used_ndivs)
1876 local lastdivindex = get_a_index(lastdiv, used_ndivs) 1902 local lastdivindex = get_a_index(lastdiv, used_ndivs)
1877 firstdivindex = tonumber(firstdivindex) 1903 firstdivindex = tonumber(firstdivindex)
@@ -1885,7 +1911,7 @@ local function close_ndivs_at_end(str)
1885 lastdivindex = lastdivindex - 1 1911 lastdivindex = lastdivindex - 1
1886 end 1912 end
1887 end 1913 end
1888-- str = string.gsub(str, "(<div)(%d)(.->)", "%1%3") 1914-- str = string.gsub(str, "(<div)([1-6])(.->)", "%1%3")
1889 if isdiv 1915 if isdiv
1890 then 1916 then
1891 return str..closedivs.."</div>" 1917 return str..closedivs.."</div>"
@@ -1897,7 +1923,7 @@ end
1897local function close_ndivs_in_between(str) 1923local function close_ndivs_in_between(str)
1898 for ndivi = 0, 9 1924 for ndivi = 0, 9
1899 do 1925 do
1900 str = string.gsub(str, "(<div)("..ndivi..")(.->)(.-)(<div)(%d)(.->)", 1926 str = string.gsub(str, "(<div)("..ndivi..")(.->)(.-)(<div)([1-6])(.->)",
1901 function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii) 1927 function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii)
1902 local firstdiv = ndivi 1928 local firstdiv = ndivi
1903 local lastdiv = ndivii 1929 local lastdiv = ndivii