aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2020-05-02 20:05:56 +0200
committerRobert Alessi <alessi@robertalessi.net>2020-05-02 20:05:56 +0200
commita9765ab2db29434f92475d2cc6675b7b651ce9b1 (patch)
tree0ee1d5aa1b0d7dff7ee64f92cfd177adb9d73f69
parent216a8a300531d01c1fc8d206a750b249c527e8bb (diff)
downloadekdosis-a9765ab2db29434f92475d2cc6675b7b651ce9b1.tar.gz
started programming \ekddiv
-rw-r--r--ekdosis.dtx188
1 files changed, 177 insertions, 11 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index 2b47132..8354459 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -316,6 +316,17 @@ Running "make install" installs the files in the local TeX tree.
316 \ifx\@tempa\layout@float\@pkg@floattrue\fi 316 \ifx\@tempa\layout@float\@pkg@floattrue\fi
317 \ifx\@tempa\layout@footins\@pkg@floatfalse\@pkg@footinstrue\fi 317 \ifx\@tempa\layout@footins\@pkg@floatfalse\@pkg@footinstrue\fi
318} 318}
319\newif\if@pkg@ekddivs
320\define@choicekey+{ekdosis.sty}{divs}{ekdosis, latex}[ekdosis]{
321 \edef\divs@ekdosis{ekdosis}
322 \edef\divs@latex{latex}
323 \edef\@tempa{#1}
324 \ifx\@tempa\divs@ekdosis\@pkg@ekddivstrue\fi
325 \ifx\@tempa\divs@latex
326 \@pkg@ekddivsfalse
327 \AtBeginDocument{\luadirect{ekdosis.setekddivsfalse()}}
328 \fi
329}{\PackageError{ekdosis}{divs option must be either 'ekdosis' or 'latex'}}
319\newif\if@parnotesroman 330\newif\if@parnotesroman
320\newif\if@pkg@parnotes 331\newif\if@pkg@parnotes
321\define@choicekey+{ekdosis.sty}{parnotes}{true, false, roman}[true]{% 332\define@choicekey+{ekdosis.sty}{parnotes}{true, false, roman}[true]{%
@@ -345,7 +356,7 @@ Running "make install" installs the files in the local TeX tree.
345 \AtBeginDocument{\luadirect{ekdosis.openteistream()}}% 356 \AtBeginDocument{\luadirect{ekdosis.openteistream()}}%
346 \AtEndDocument{\luadirect{ekdosis.closeteistream("tidy")}} 357 \AtEndDocument{\luadirect{ekdosis.closeteistream("tidy")}}
347 \else\fi\fi\fi} 358 \else\fi\fi\fi}
348\ExecuteOptionsX{layout} 359\ExecuteOptionsX{layout,divs}
349\ProcessOptionsX\relax 360\ProcessOptionsX\relax
350\RequirePackage{luacode} 361\RequirePackage{luacode}
351\RequirePackage{paracol} 362\RequirePackage{paracol}
@@ -1083,7 +1094,7 @@ Running "make install" installs the files in the local TeX tree.
1083 initial tcols = 2, 1094 initial tcols = 2,
1084 initial lcols = 1, 1095 initial lcols = 1,
1085 initial texts = edition;translation, 1096 initial texts = edition;translation,
1086 initial apparatus = edition, 1097 initial apparatus = edition
1087} 1098}
1088\NewDocumentCommand{\SetEkdosisAlignment}{m}{ 1099\NewDocumentCommand{\SetEkdosisAlignment}{m}{
1089 \ekvset{ekd@align}{#1} 1100 \ekvset{ekd@align}{#1}
@@ -1151,6 +1162,52 @@ Running "make install" installs the files in the local TeX tree.
1151 } 1162 }
1152} 1163}
1153% \end{macrocode} 1164% \end{macrocode}
1165% Divisions specific to ekdosis:---
1166% \begin{macrocode}
1167\ekvdefinekeys{ekd@div}{
1168 code type = \def\type@value{#1},
1169 code n = \def\n@value{#1},
1170 code head = \def\head@value{#1},
1171 code barehead = \def\barehead@value{#1},
1172 store depth = \depth@value,
1173 choice toc = {book = \def\toc@value{book},
1174 part = \def\toc@value{part},
1175 chapter = \def\toc@value{chapter},
1176 section = \def\toc@value{section},
1177 subsection = \def\toc@value{subsection},
1178 subsubsection = \def\toc@value{subsubsection},
1179 paragraph = \def\toc@value{paragraph},
1180 subparagraph = \def\toc@value{subparagraph}},
1181 initial depth = 1
1182}
1183
1184\NewDocumentCommand{\ekdfmtdiv}{m m m}{
1185 \luadirect{ekdosis.fmtdiv(\luastring{#1}, \luastringN{#2}, \luastringN{#3})}
1186}
1187\NewDocumentCommand{\ekd@getfmtdiv}{m m}{%
1188 \luadirect{tex.sprint(ekdosis.getfmtdiv(\luastringO{#1}, \luastringN{#2}))}%
1189}
1190\NewDocumentCommand{\ekddiv}{m}{
1191 \begingroup
1192 \ekvset{ekd@div}{#1}%
1193 \ifdefined\head@value
1194 \bgroup
1195 \ekd@getfmtdiv{\depth@value}{b}%
1196 \head@value
1197 \ekd@getfmtdiv{\depth@value}{e}%
1198 \egroup
1199 \ifdefined\toc@value
1200 \ltx@ifpackageloaded{hyperref}{\phantomsection}{}%
1201 \ifdefined\barehead@value
1202 \addcontentsline{toc}{\toc@value}{\barehead@value}%
1203 \else
1204 \addcontentsline{toc}{\toc@value}{\head@value}%
1205 \fi
1206 \fi
1207 \fi
1208 \endgroup
1209}
1210% \end{macrocode}
1154% Very basic implementation of poetry lines:--- 1211% Very basic implementation of poetry lines:---
1155% \begin{macrocode} 1212% \begin{macrocode}
1156\newlength{\ekdverseindentlength} 1213\newlength{\ekdverseindentlength}
@@ -1845,7 +1902,8 @@ function ekdosis.mkdivdepths(...)
1845 local num = 1 1902 local num = 1
1846 for _, y in ipairs{...} 1903 for _, y in ipairs{...}
1847 do 1904 do
1848 if y == "book" or "part" or "chapter" or "section" or "subsection" or "subsubsection" 1905 if y == "book" or "part" or "chapter"
1906 or "section" or "subsection" or "subsubsection"
1849 then 1907 then
1850 divdepth[y] = num 1908 divdepth[y] = num
1851 num = num + 1 1909 num = num + 1
@@ -1855,16 +1913,119 @@ function ekdosis.mkdivdepths(...)
1855 return true 1913 return true
1856end 1914end
1857 1915
1916-- LaTeX side: format the divisions
1917local fmtdiv = {}
1918
1919function ekdosis.fmtdiv(n, fmtb, fmte)
1920 if isintable(fmtdiv, n)
1921 then
1922 local index = get_a_index(n, fmtdiv)
1923 table.remove(fmtdiv, index)
1924 else
1925 end
1926 table.insert(fmtdiv, { a = n, formatb = fmtb, formate = fmte} )
1927 return true
1928end
1929
1930function ekdosis.getfmtdiv(n, pos)
1931 local index = get_a_index(n, fmtdiv)
1932 if index ~= nil
1933 then
1934 if pos == "b"
1935 then
1936 return fmtdiv[index].formatb
1937 elseif pos == "e"
1938 then
1939 return fmtdiv[index].formate
1940 end
1941 else
1942 return ""
1943 end
1944end
1945
1946local ekddivs = true
1947
1948function ekdosis.setekddivsfalse()
1949 ekddivs = false
1950end
1951
1952--[[
1953 teitype = string.match(opt, "%f[%w]type%s?%=%s?%b{}")
1954 or string.match(opt, "%f[%w]type%s?%=%s?%w+%f[%W]")
1955 or ""
1956 teitype = string.gsub(teitype, "type%s?%=%s?(%b{})", function(bbraces)
1957 bbraces = string.sub(bbraces, 2, -2)
1958 return string.format("%s", bbraces)
1959 end)
1960 teitype = string.gsub(teitype, "(type%s?%=%s?)(%w+%f[%W])", "%2")
1961--]]
1962
1963local function ekddivs_totei(str)
1964 str = gsub(str, dblbkslash * lpeg.Cs("ekddiv") * spce^-1 * bcbraces,
1965 function(bkslash, cmd, space, arg)
1966 if ekddivs
1967 then
1968 arg = string.sub(arg, 2, -2)
1969 arg = arg..","
1970 --
1971 teitype = string.match(arg, "%f[%w]type%s?%=%s?%b{}")
1972 or string.match(arg, "%f[%w]type%s?%=%s?[%w%s]+%,")
1973 or ""
1974 teitype = string.gsub(teitype, "type%s?%=%s?(%b{})", function(bbraces)
1975 bbraces = string.sub(bbraces, 2, -2)
1976 return string.format("%s", bbraces)
1977 end)
1978 teitype = string.gsub(teitype, "(type%s?%=%s?)([%w%s]+)(%,)", "%2")
1979 --
1980 tein = string.match(arg, "%f[%w]n%s?%=%s?%b{}")
1981 or string.match(arg, "%f[%w]n%s?%=%s?[%w%s]+%,")
1982 or ""
1983 tein = string.gsub(tein, "n%s?%=%s?(%b{})", function(bbraces)
1984 bbraces = string.sub(bbraces, 2, -2)
1985 return string.format("%s", bbraces)
1986 end)
1987 tein = string.gsub(tein, "(n%s?%=%s?)([%w%s]+)(%,)", "%2")
1988 --
1989 teihead = string.match(arg, "%f[%w]head%s?%=%s?%b{}")
1990 or string.match(arg, "%f[%w]head%s?%=%s?[%w%s]+%,")
1991 or ""
1992 teihead = string.gsub(teihead, "head%s?%=%s?(%b{})", function(bbraces)
1993 bbraces = string.sub(bbraces, 2, -2)
1994 return string.format("%s", bbraces)
1995 end)
1996 teihead = string.gsub(teihead, "(head%s?%=%s?)([%w%s]+)(%,)", "%2")
1997 --
1998 teidepth = string.match(arg, "%f[%w]depth%s?%=%s?%b{}")
1999 or string.match(arg, "%f[%w]depth%s?%=%s?[%w%s]+%,")
2000 or ""
2001 teidepth = string.gsub(teidepth, "depth%s?%=%s?(%b{})", function(bbraces)
2002 bbraces = string.sub(bbraces, 2, -2)
2003 return string.format("%s", bbraces)
2004 end)
2005 teidepth = string.gsub(teidepth, "(depth%s?%=%s?)([%w%s]+)(%,)", "%2")
2006 --
2007 return string.format("\\par <div type=\"%s\" n=\"%s\" depth=\"%s\"/><head>%s</head>",
2008 teitype, tein, teidepth, teihead)
2009 else
2010 return ""
2011 end
2012 end)
2013 return str
2014end
2015
1858local function section_totei(str) 2016local function section_totei(str)
1859 str = gsub(str, dblbkslash * sections * spce^-1 * bcbraces, "%1%2%3[]%4") 2017 str = gsub(str, dblbkslash * sections * spce^-1 * bcbraces, "%1%2%3[]%4")
1860 str = gsub(str, dblbkslash * sections * spce^-1 * bsqbrackets * bcbraces, 2018 str = gsub(str, dblbkslash * sections * spce^-1 * bsqbrackets * bcbraces,
1861 function(bkslash, secname, space, opt, arg) 2019 function(bkslash, secname, space, opt, arg)
1862 ctr = divdepth[secname] 2020 if ekddivs
1863 arg = string.sub(arg, 2, -2) 2021 then
1864 -- return string.format("\\par <div%s type=\"%s\" depth=\"%s\"><head>%s</head>", 2022 return ""
1865 -- ctr, secname, ctr, arg) 2023 else
1866 return string.format("\\par <div%s type=\"%s\"><head>%s</head>", 2024 ctr = divdepth[secname]
1867 ctr, secname, arg) 2025 arg = string.sub(arg, 2, -2)
2026 return string.format("\\par <div%s type=\"%s\"><head>%s</head>",
2027 ctr, secname, arg)
2028 end
1868 end) 2029 end)
1869 return str 2030 return str
1870end 2031end
@@ -1958,13 +2119,18 @@ local function textotei(str)
1958 str = relocate_notes(str) 2119 str = relocate_notes(str)
1959 str = versetotei(str) 2120 str = versetotei(str)
1960 str = envtotei(str) 2121 str = envtotei(str)
2122 str = ekddivs_totei(str)
1961 str = section_totei(str) 2123 str = section_totei(str)
1962 str = cmdtotei(str) 2124 str = cmdtotei(str)
1963 str = self_close_tags(str) 2125 str = self_close_tags(str)
1964 str = partotei(str) 2126 str = partotei(str)
1965 str = checkpars(str) 2127 str = checkpars(str)
1966 str = close_ndivs_at_end(str) 2128 if ekddivs
1967 str = close_ndivs_in_between(str) 2129 then
2130 else
2131 str = close_ndivs_at_end(str)
2132 str = close_ndivs_in_between(str)
2133 end
1968 return str 2134 return str
1969end 2135end
1970 2136