summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-11-28 21:00:21 +0000
committerKarl Berry <karl@freefriends.org>2022-11-28 21:00:21 +0000
commit13c21a7d28314ccd114931580b7e6e2364377856 (patch)
tree427e6d7948f97806a67118d09d76fe7fedf69f1f /Master/texmf-dist/tex/luatex
parent20229ac1b0cf251211d2acde80293548ec753ce3 (diff)
lutabulartools (28nov22)
git-svn-id: svn://tug.org/texlive/trunk@65133 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua186
-rw-r--r--Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty62
2 files changed, 186 insertions, 62 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 ''
diff --git a/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty b/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty
index f1dea60c5a7..1d2522b099d 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-10-22
+% 2022-11-27
% 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-10-22]
+\ProvidesPackage{lutabulartools}[2022-11-27]
\RequirePackage{booktabs}
\RequirePackage{multirow}
@@ -40,13 +40,8 @@
\newcommand{\lttdebugON}{\luadirect{lutabt.debug = true}}
\newcommand{\lttdebugOFF}{\luadirect{lutabt.debug = true}}
-\newcolumntype{\ltt@ltrim}{@{}}
-\newcolumntype{\ltt@rtrim}{@{}}
-\DeclareOption{notrim}{
- \newcolumntype{\ltt@ltrim}{}
- \newcolumntype{\ltt@rtrim}{}
-}
-
+\newcolumntype{\lttltrim}{}
+\newcolumntype{\lttrtrim}{}
%%% midrule every X rows
@@ -143,40 +138,67 @@
+\NewDocumentCommand{\midrulesat}{m}{\luadirect{lutabt.add_auto_midrules(\luastring{#1})}}
+
+
+
+
+\NewDocumentCommand{\settabular}{s m}{\luadirect{lutabt.set_tabular(\luastring{#2})}} % make kv interface for auto
+
+\def\ltt@resetrownum{\luadirect{lutabt.reset_rows()}}
+\def\ltt@autotoprule{\luadirect{lutabt.process_auto_topbot_rule('top')}}
+\def\ltt@autobotrule{\luadirect{lutabt.process_auto_topbot_rule('bottom')}}
+
\let\oldtabular\tabular
+\let\oldendtabular\endtabular
\RenewExpandableDocumentCommand{\tabular}{ O{l} m }{%
\luadirect{lutabt.set_col_spec(\luastringN{#2})}%
- \oldtabular[#1]{\ltt@ltrim#2\ltt@rtrim}%
+ \oldtabular[#1]{\lttltrim#2\lttrtrim}\ltt@inctablelevel\ltt@resetrownum\ltt@autotoprule%
}
+\def\endtabular{\ltt@autobotrule\ltt@dectablelevel\oldendtabular}
+
+
+
\expandafter\let\expandafter\oldtabulars\csname tabular*\endcsname
\expandafter\let\expandafter\endoldtabulars\csname endtabular*\endcsname
\RenewDocumentEnvironment{tabular*}{ m O{l} m }{%
\luadirect{lutabt.set_col_spec(\luastringN{#3})}%
- \begin{oldtabulars}{#1}[#2]{\ltt@ltrim#3\ltt@rtrim}%
+ \begin{oldtabulars}{#1}[#2]{\lttltrim#3\lttrtrim}\ltt@inctablelevel\ltt@resetrownum\ltt@autotoprule%
}{%
- \end{oldtabulars}%
+ \ltt@autobotrule\ltt@dectablelevel\end{oldtabulars}%
}
%%% NOTE tabularx uses tabular*, NO NEED TO CHANGE TABULARX!
\let\oldlongtable\longtable
\RenewExpandableDocumentCommand{\longtable}{ O{l} m }{%
+ \luadirect{lutabt.auto_topbot_old = lutabt.auto_topbot
+ lutabt.auto_topbot = false}%
\luadirect{lutabt.set_col_spec(\luastringN{#2})}%
- \oldlongtable[#1]{\ltt@ltrim#2\ltt@rtrim}%
+ \oldlongtable[#1]{\lttltrim#2\lttrtrim}\ltt@inctablelevel\ltt@resetrownum%
}
+\let\oldendlongtable\endlongtable
+\def\endlongtable{\luadirect{lutabt.auto_topbot = lutabt.auto_topbot_old}
+ \ltt@dectablelevel\oldendlongtable}% restore status of auto topbot rule
+
+\apptocmd{\@arraycr}{\luadirect{lutabt.process_auto_rules()}}{}{}
+
+\def\ltt@inctablelevel{\luadirect{lutabt.tablelevel = lutabt.tablelevel + 1}}
+\def\ltt@dectablelevel{\luadirect{lutabt.tablelevel = lutabt.tablelevel - 1}}
%s0,spec,mcspec,pre,content
% Magic Cell
-\NewExpandableDocumentCommand{\MC}{ s O{} D(){} D<>{} m }{%
+\NewExpandableDocumentCommand{\MC}{ s O{} O{} D<>{} D(){x} m }{%
% Magic cell *wraps with {} but automatically checks for SI column,
- % [column spec] (mult-column spec override) <pre-cell stuff> {cell content}
+ % [column spec] [mult-column spec override] <pre-cell stuff> (add rule) {cell content}
\luadirect{lutabt.MagicCell(
\luastring{#1},
\luastring{#2},
\luastringN{#3},
\luastringN{#4},
- \luastringN{#5}
+ \luastringN{#6},
+ \luastring{#5}
)}}
@@ -219,12 +241,12 @@
% \setcounter{RowNumCnt}{1}%
% \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason
%\DeclareOption{notrimx}{
-% \global\newcolumntype{\ltt@ltrim}{!{\stepcounter{RowNumCnt}}}
-%% \global\newcolumntype{\ltt@rtrim}{!{\luadirect{lutabt.get_TabColNum()}}}
+% \global\newcolumntype{\lttltrim}{!{\stepcounter{RowNumCnt}}}
+%% \global\newcolumntype{\lttrtrim}{!{\luadirect{lutabt.get_TabColNum()}}}
%}
%\DeclareOption{trimx}{
-% \newcolumntype{\ltt@ltrim}{@{\stepcounter{RowNumCnt}}}
-%% \newcolumntype{\ltt@rtrim}{@{\luadirect{lutabt.get_TabColNum()}}}
+% \newcolumntype{\lttltrim}{@{\stepcounter{RowNumCnt}}}
+%% \newcolumntype{\lttrtrim}{@{\luadirect{lutabt.get_TabColNum()}}}
%}