summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-10-16 20:15:33 +0000
committerKarl Berry <karl@freefriends.org>2022-10-16 20:15:33 +0000
commit22416e24d6a3b4143ed58e8758c4fd4d01c97aed (patch)
tree7534210064c590af3b5daf2859c300090f427911 /Master/texmf-dist/tex/luatex
parent24d00f8763db787c7926225ef1cea8874959ae26 (diff)
lutabulartools (16oct22)
git-svn-id: svn://tug.org/texlive/trunk@64724 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua76
-rw-r--r--Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty80
2 files changed, 118 insertions, 38 deletions
diff --git a/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua b/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua
index fd783332a91..361530bc978 100644
--- a/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua
+++ b/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje@gmail.com)
---% 2022-04-16
+--% 2022-10-15
--% Copyright (C) 2021-2022 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -45,24 +45,19 @@ ltt.col = '' -- current column spec, single char, only applies to tabular with m
ltt.col_num = 1 -- current column number
-local glue_t, unset_t, tabskip_st = node.id'glue', node.id'unset'
-local tabskip_st = table.swapped(node.subtypes'glue').tabskip
-assert(tabskip_st)
-
-
function ltt.set_col_num()
-- register current column info (column number and specification)
local nest
for i = tex.nest.ptr, 1, -1 do
local tail = tex.nest[i].tail
- if tail.id == glue_t and tail.subtype == tabskip_st then
+ if tail.id == node.id'glue' and tail.subtype == table.swapped(node.subtypes'glue').tabskip then
nest = tex.nest[i]
break
end
end
if nest then
local col = 1
- for _, sub in node.traverse_id(unset_t, nest.head) do
+ for _, sub in node.traverse_id(node.id'unset', nest.head) do
col = col + sub + 1
end
ltt.col_num = col
@@ -288,6 +283,71 @@ function ltt.makecmidrules(s, r, c, cmd)
end
+local T = pl.tablex
+
+ltt.mrX = {}
+ltt.mrX.defaults = {step=5, rule='midrule', reset=false, resetnum=0, cntr=0}
+ltt.mrX.settings = T.copy(ltt.mrX.defaults)
+ltt.mrX.cntr = 0
+ltt.mrX.pgcntr = 0
+
+
+
+function ltt.mrX.set_midruleX(new_sett, def)
+ def = def or ''
+ local curr_sett = {}
+ if def == pl.tex._xTrue then -- default flag, if true, reset all non-used keys to default
+ curr_sett = ltt.mrX.defaults
+ else
+ curr_sett = ltt.mrX.settings
+ end
+ new_sett = luakeys.parse(new_sett)
+ ltt.mrX.settings = T.union(curr_sett, new_sett)
+ ltt.debugtalk{ltt.mrX.settings, 'new settings'}
+ ltt.mrX.cntr = curr_sett.cntr
+end
+
+function ltt.mrX.midruleX(n)
+ n = n or '' -- todo placeholder for noalign ?
+ local s = ltt.mrX.settings
+ if pl.hasval(s.reset) and ltt.mrX.add_label_and_check_page_change() then ltt.mrX.cntr = s.resetnum end
+ ltt.mrX.cntr = ltt.mrX.cntr + 1
+ if ltt.mrX.cntr == s.step then
+ ltt.debugtalk{s.rule, 'apply midruleX'}
+ tex.sprint('\\'..s.rule)
+ ltt.mrX.cntr = 0
+ end
+end
+
+function ltt.mrX.add_label_and_check_page_change()
+ ltt.mrX.pgcntr = ltt.mrX.pgcntr + 1
+ tex.print('\\noalign{\\label{ltt@tabular@row@'..ltt.mrX.pgcntr..'}}')
+ local _, pgcurr = pl.tex.get_ref_info('ltt@tabular@row@'..ltt.mrX.pgcntr)
+ local _, pgprev = pl.tex.get_ref_info('ltt@tabular@row@'..ltt.mrX.pgcntr-1)
+ if pgcurr ~= pgprev then
+ return true
+ end
+ return false
+end
+
+
+
+
+
+
+--
+--ltt.tabular_row_pages_cntr = 0
+--function ltt.reset_midruleX_on_newpage(n)
+-- local n = n or 0
+-- ltt.tabular_row_pages_cntr = ltt.tabular_row_pages_cntr + 1
+-- tex.print('\\noalign{\\label{tabular@row@'..ltt.tabular_row_pages_cntr..'}}')
+-- if ltt.get_ref_page('tabular@row@'..ltt.tabular_row_pages_cntr) -
+-- ltt.get_ref_page('tabular@row@'..(ltt.tabular_row_pages_cntr-1)) == 1 then
+-- tex.print('\\setcounter{midruleX}{'..n..'}')
+-- end
+--end
+
+
--help_wrt('TEST COL ')
--for _, s in ipairs{ 'll', '*{6}{s}', 'l*{6}{l}', 'lll', 'll[]', 'll[]*{6}{l}', '*{6}{l}', 'y*{6}{sq}x', } do
-- ltt. set_col_spec(s)
diff --git a/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty b/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty
index abeb1afdefb..5a501a8346c 100644
--- a/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty
+++ b/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2022-04-16
+% 2022-10-15
% Copyright (C) 2021-2022 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -23,7 +23,7 @@
% OR OTHER DEALINGS IN THE SOFTWARE.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{lutabulartools}[2022-04-16]
+\ProvidesPackage{lutabulartools}[2022-10-15]
\RequirePackage{booktabs}
\RequirePackage{multirow}
@@ -49,35 +49,13 @@
-%% adapted from
-% https://tex.stackexchange.com/questions/182953/add-midrule-every-5-lines-automatically
-%% https://tex.stackexchange.com/questions/145084/what-is-the-function-of-noalign
-
-\def\midruleXstep{5}
-\def\midruleXrule{\gmidrule}
-
-\newcounter{midruleX}
-\newcommand*{\midruleX}{%
- \aftergroup\aftergroup\aftergroup\midruleXaux
-}
-\newif\ifmidruleX
-
-\newcommand*{\midruleXaux}{%
- \noalign{%
- \stepcounter{midruleX}%
- \ifnum\value{midruleX}=\midruleXstep %
- \global\midruleXtrue
- \resetmidruleX%
- \else
- \global\midruleXfalse
- \fi
- }
- \ifmidruleX\midruleXrule\fi
-}
-\newcommand*{\resetmidruleX}{\setcounter{midruleX}{0}} %%% todo maybe put noalign in here
-
-\resetmidruleX
+%%% midrule every X rows
+\def\midruleX{\aftergroup\aftergroup\aftergroup\midruleX@aux}
+\def\midruleX@aux{\luadirect{lutabt.mrX.midruleX('')}} % todo argument for vadjust or noalign??
+\NewDocumentCommand{\setmidruleX}{s m}{\luadirect{lutabt.mrX.set_midruleX(\luastring{#2}, \luastring{#1})}}
+\NewDocumentCommand{\midruleXreset}{O{0}}{\luadirect{lutabt.mrX.cntr = tonumber(\luastring{#1})}}
+\NewCommandCopy\resetmidruleX\midruleXreset
@@ -235,3 +213,45 @@
% \newcolumntype{\ltt@ltrim}{@{\stepcounter{RowNumCnt}}}
%% \newcolumntype{\ltt@rtrim}{@{\luadirect{lutabt.get_TabColNum()}}}
%}
+
+
+%% adapted from
+% https://tex.stackexchange.com/questions/182953/add-midrule-every-5-lines-automatically
+%% https://tex.stackexchange.com/questions/145084/what-is-the-function-of-noalign
+%
+%\def\midruleXstep{5}
+%\def\midruleXrule{\gmidrule}
+%
+%\newcounter{midruleX}
+%\newcommand*{\midruleXa}{%
+% \aftergroup\aftergroup\aftergroup\midruleXaux
+%}
+%
+%\newif\ifmidruleX
+%
+%\newcommand*{\midruleXaux}{%
+% \noalign{%
+% \stepcounter{midruleX}%
+% \ifnum\value{midruleX}=\midruleXstep %
+% \global\midruleXtrue
+% \resetmidruleX%
+% \else
+% \global\midruleXfalse
+% \fi
+% }
+% \ifmidruleX\midruleXrule\fi
+%}
+
+%\newcommand*{\resetmidruleX}{\setcounter{midruleX}{0}} %
+%\resetmidruleX
+
+%\NewDocumentCommand{\resetmidruleXonNP}{O{0}}{\luadirect{lutabt.reset_midruleX_on_newpage(\luastring{#1})}}
+
+%
+%\NewDocumentCommand{\IfmidruleX}{m m}{% if a midruleX was placed, do #1, if not, do #2
+% \ifnum\the\value{midruleX}=0
+% #1
+% \else
+% #2
+% \fi%
+%} \ No newline at end of file