diff options
Diffstat (limited to 'macros/luatex/generic/lutabulartools/lutabulartools.lua')
-rw-r--r-- | macros/luatex/generic/lutabulartools/lutabulartools.lua | 76 |
1 files changed, 68 insertions, 8 deletions
diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.lua b/macros/luatex/generic/lutabulartools/lutabulartools.lua index fd783332a9..361530bc97 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.lua +++ b/macros/luatex/generic/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) |