diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua | 186 |
1 files changed, 144 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua b/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua index 24c8d5598e5..23ef9654825 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-10-22 +--% 2022-11-27 --% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -28,11 +28,61 @@ if (__PL_EXTRAS__ == nil) or (__PENLIGHT__ == nil) then tex.sprint('\\PackageError{yamlvars}{penlight package with extras (or extrasglobals) option must be loaded before this package}{}') tex.print('\\stop') end +local T = pl.tablex local ltt = {} +ltt.tablelevel = 0 ltt.debug = false + +ltt.auto_topbot = false + +ltt.auto_crules = {} -- {{span,trim}, } appearance is like this, 'range|trim', -- auto_rules created by MC +ltt.auto_midrules = {} + +ltt.col_spec1 = {} -- column spec if one column wide (since makcell nests a tabular, preserve col_spec below) +ltt.col_spec = {} -- tab column spec if above 1 +ltt.col = '' -- current column spec, single char, only applies to tabular with more than 1 column +ltt.col_num = 1 -- current column number +ltt.row_num = 0 -- current row number + + +ltt.col_ver_repl = { +m = 'm', +M = 'm', +b = 'b', +} + +ltt.col_hor_repl = { -- horizontal cell alignment that multicolumn should use if () or [hori] not passed to func + l = 'l', + c = 'c', + r = 'r', + p = 'l', + P = 'c', + X = 'l', + Y = 'c', + Z = 'l', + N = 'c', + L = 'l', + R = 'r', + C = 'c', +} + +-- allow user to place their own replacements in for a table, say if they define a column that expands to multiple +ltt.col_replaces = { +--x = 'lll' +} + +ltt.SI_cols = {'S', 'N', 'Q', 'L', 'R'} + + + +----- +----- utility funcs +----- + + function ltt.debugtalk(s, ss) ss = ss or '' if ltt.debug then @@ -40,12 +90,32 @@ function ltt.debugtalk(s, ss) end end -ltt.col_spec1 = {} -- column spec if one column wide (since makcell nests a tabular, preserve col_spec below) -ltt.col_spec = {} -- tab column spec if above 1 -ltt.col = '' -- current column spec, single char, only applies to tabular with more than 1 column -ltt.col_num = 1 -- current column number + +function ltt.set_tabular(sett) + sett = luakeys.parse(sett) + local trim = '' + for k, v in pairs(sett) do + if k == 'tbrule' then + ltt.auto_topbot = v + elseif k == 'nopad' then + if pl.hasval(v) then trim = '@{}' end -- set to trim + tex.print('\\newcolumntype{\\lttltrim}{'..trim..'}') + tex.print('\\newcolumntype{\\lttrtrim}{'..trim..'}') + end + end +end +----- +----- tabular utility funcs +----- + +function ltt.reset_rows() + if ltt.tablelevel == 1 then + ltt.row_num = 0 + end +end + function ltt.set_col_num() -- register current column info (column number and specification) local nest @@ -96,7 +166,12 @@ end -- this case should be considered in this code. -- for example: \multirow{2}{=} -function ltt.MagicCell(s0,spec,mcspec,pre,content) + +----- +----- magic cell and helpers +----- + +function ltt.MagicCell(s0,spec,mcspec,pre,content,trim) -- ltt.set_col_num() -- register current column number and column spec @@ -144,9 +219,14 @@ function ltt.MagicCell(s0,spec,mcspec,pre,content) --help_wrt(STR..' <<< magic cell string') ltt.debugtalk(STR,'MagicCell') tex.sprint(STR)--tex print the STR + + local en + if c == '' then en = ltt.col_num else en = ltt.col_num + c -1 end + ltt.add_auto_crule(ltt.col_num, en, trim) end + function ltt.parse_MagicCell_spec(spec) local mrowsym = '*' -- * = natural width, = will match p{2cm} for example local skipmakecell = false @@ -199,45 +279,76 @@ function ltt.get_HColSpec(h, mcspec, c) -- take horizontal alignment end +----- +----- autorules (with \MC() or auto top bot +----- -ltt.col_ver_repl = { -m = 'm', -M = 'm', -b = 'b', -} +function ltt.add_auto_midrules(rows) + ltt.auto_midrules = rows:split(',') +end + +function ltt.add_auto_crule(st,en,trim) + if trim ~= 'x' then + ltt.auto_crules[#ltt.auto_crules + 1] = {math.floor(st)..'-'..math.floor(en), trim} -- append here + -- {{span 1-2, trim}, ..} + end +end + + +function ltt.process_auto_rules() + if ltt.tablelevel == 1 then + ltt.row_num = ltt.row_num + 1 + end + if ltt.auto_crules ~= {} then + if ltt.tablelevel == 1 then + for _, v in ipairs(ltt.auto_crules) do + --pl.help_wrt(ltt.auto_crules, 'fuck') + ltt.make1cmidrule('', v[2], v[1], 'cmidrule') + end + for i, v in ipairs(ltt.auto_midrules) do + --pl.help_wrt(ltt.auto_midrules, 'fuck') + --pl.help_wrt(v, 'fuck') + pl.help_wrt(ltt.row_num, 'fuck') + if tonumber(v) == ltt.row_num then + _ = table.remove(ltt.auto_midrules,i) + --pl.help_wrt(v, 'removed!') + tex.print('\\midrule ') + end + end + end + end + ltt.auto_crules = {} +end -ltt.col_hor_repl = { -- horizontal cell alignment that multicolumn should use if () or [hori] not passed to func - l = 'l', - c = 'c', - r = 'r', - p = 'l', - P = 'c', - X = 'l', - Y = 'c', - Z = 'l', - N = 'c', - L = 'l', - R = 'r', - C = 'c', -} --- allow user to place their own replacements in for a table, say if they define a column that expands to multiple -ltt.col_replaces = { ---x = 'lll' -} -ltt.SI_cols = {'S', 'N', 'Q', 'L', 'R'} ---ltt.SI_cols = {'S'} ---ltt.SI_cols = {'N'} + +function ltt.process_auto_topbot_rule(rule) + if ltt.tablelevel == 1 then + if ltt.auto_topbot then + tex.print('\\'..rule..'rule ') + end + end +end + ----- ---- midrule stuff +----- midrule and midruleX stuff ----- + +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.get_midrule_col(s) if string.find(s, '+') then s = s:gsub('+', '') @@ -282,15 +393,6 @@ 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 '' |