aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2020-03-10 18:30:36 +0100
committerRobert Alessi <alessi@robertalessi.net>2020-03-10 18:30:36 +0100
commitc4310a214c7e5b0a04f823918a7521a02f5f7451 (patch)
treec24a954c41219b0fa28cbd5bb7ba9cb5bfe62775
parente72bdfd80eb72631add8db37845c450d187c23c4 (diff)
downloadekdosis-c4310a214c7e5b0a04f823918a7521a02f5f7451.tar.gz
start programming alignment features
-rw-r--r--ekdosis.dtx101
1 files changed, 100 insertions, 1 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index 66ec86d..83b3ec0 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -143,10 +143,11 @@ Running "make install" installs the files in the local TeX tree.
143\babelfont{tt}{NewComputerModern Mono} 143\babelfont{tt}{NewComputerModern Mono}
144\usepackage{metalogox} 144\usepackage{metalogox}
145\usepackage{hologo} 145\usepackage{hologo}
146\usepackage{latexcolors}
146\usepackage{hyperxmp} 147\usepackage{hyperxmp}
147\usepackage{uri} 148\usepackage{uri}
148\usepackage[numbered]{hypdoc} 149\usepackage[numbered]{hypdoc}
149\hypersetup{unicode=true, colorlinks, allcolors=blue, 150\hypersetup{unicode=true, colorlinks, allcolors=cinnamon,
150 linktocpage=true, pdfauthor={Robert Alessi}, pdftitle={The 151 linktocpage=true, pdfauthor={Robert Alessi}, pdftitle={The
151 ekdosis package}, pdfcontactemail={alessi@robertalessi.net}, 152 ekdosis package}, pdfcontactemail={alessi@robertalessi.net},
152 pdfcontacturl={http://www.robertalessi.net/ekdosis}, 153 pdfcontacturl={http://www.robertalessi.net/ekdosis},
@@ -1065,6 +1066,33 @@ Running "make install" installs the files in the local TeX tree.
1065 \end{linenumbers}% 1066 \end{linenumbers}%
1066 \iftei@export\luadirect{ekdosis.exporttei(\luastringN{#1})}\else\fi} 1067 \iftei@export\luadirect{ekdosis.exporttei(\luastringN{#1})}\else\fi}
1067% \end{macrocode} 1068% \end{macrocode}
1069% Alignment:---
1070% \begin{macrocode}
1071\ekvdefinekeys{align}{
1072 store tcols = \tcols@num,
1073 store lcols = \lcols@num,
1074 store texts = \texts@value,
1075 store apparatus = \apparatus@value,
1076 initial tcols = 2,
1077 initial lcols = 1,
1078 initial texts = edition;translation,
1079 initial apparatus = edition,
1080}
1081\NewDocumentEnvironment{alignment}{O{}}
1082{%
1083 \ekvset{align}{#1}%
1084 \luadirect{ekdosis.mkenvdata(
1085 \luastring{\texts@value},
1086 "texts"
1087 )}
1088 \luadirect{ekdosis.mkenvdata(
1089 \luastring{\apparatus@value}, "apparatus")}
1090 \luadirect{tex.sprint(ekdosis.mkenv())}
1091 \begin{paracol}[\lcols@num]*{\tcols@num}
1092 }
1093 {\luadirect{ekdosis.flushenvdata()}
1094 \end{paracol}}
1095% \end{macrocode}
1068% Very basic implementation of poetry lines:--- 1096% Very basic implementation of poetry lines:---
1069% \begin{macrocode} 1097% \begin{macrocode}
1070\newlength{\ekdverseindentlength} 1098\newlength{\ekdverseindentlength}
@@ -1884,6 +1912,77 @@ ekdosis.getabspg = function(pg) --not used
1884 end 1912 end
1885end 1913end
1886 1914
1915-- Build environments to be aligned
1916--
1917local aligned_texts = {}
1918local texts_w_apparatus = {}
1919
1920function ekdosis.mkenvdata(str, opt)
1921 str = str ..";"
1922 str = string.gsub(str, "%s+", "")
1923 local fieldstart = 1
1924 local col = 0
1925 if opt == "texts" then
1926 repeat
1927 local nexti = string.find(str, "%;", fieldstart)
1928 table.insert(aligned_texts, {text = string.sub(str, fieldstart, nexti-1),
1929 column = col})
1930 col = col + 1
1931 fieldstart = nexti + 1
1932 until fieldstart > string.len(str)
1933 return aligned_texts
1934 elseif opt == "apparatus" then
1935 repeat
1936 local nexti = string.find(str, "%;", fieldstart)
1937 table.insert(texts_w_apparatus, string.sub(str, fieldstart, nexti-1))
1938 fieldstart = nexti +1
1939 until fieldstart > string.len(str)
1940 return texts_w_apparatus
1941 end
1942end
1943
1944-- idea: store this # in a lua variable as in ekdosis.storeabspg()
1945-- above, then use it in the apparatus-page attributes
1946function ekdosis.getcurcol(str)
1947 for i = 1,#aligned_texts
1948 do
1949 if aligned_texts[i].text == str then
1950 colfound = aligned_texts[i].column
1951 break
1952 end
1953 end
1954 return colfound
1955end
1956
1957function ekdosis.flushenvdata()
1958 aligned_texts = {}
1959 texts_w_apparatus = {}
1960 return true
1961end
1962
1963function ekdosis.mkenv()
1964 local environments = {}
1965 for i = 1,#aligned_texts
1966 do
1967 if isfound(texts_w_apparatus, aligned_texts[i].text)
1968 then
1969 table.insert(environments, "\\NewDocumentEnvironment{"
1970 .. aligned_texts[i].text
1971 .. "}{}{\\begin{nthcolumn}{"
1972 .. aligned_texts[i].column
1973 .."}\\begin{ekdosis}}{\\end{ekdosis}\\end{nthcolumn}}")
1974 else
1975 table.insert(environments, "\\NewDocumentEnvironment{"
1976 .. aligned_texts[i].text
1977 .. "}{}{\\begin{nthcolumn}{"
1978 .. aligned_texts[i].column
1979 .."}}{\\end{nthcolumn}}")
1980 end
1981 end
1982 str = table.concat(environments)
1983 return str
1984end
1985
1887-- handle multiple layers in apparatuses 1986-- handle multiple layers in apparatuses
1888-- 1987--
1889local apparatuses = {} 1988local apparatuses = {}