diff options
author | Norbert Preining <norbert@preining.info> | 2022-10-23 03:01:07 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-10-23 03:01:07 +0000 |
commit | 588d4f81788b3a24bd9bd480ec40bb55be4d1da1 (patch) | |
tree | a035dd5b60e2cf4afabea9fc6f8a34e5505ba6ac /macros/luatex/generic/lutabulartools | |
parent | 3183c46c6fe93c96cf342a65ba2ac2b74a14dcbd (diff) |
CTAN sync 202210230301
Diffstat (limited to 'macros/luatex/generic/lutabulartools')
-rw-r--r-- | macros/luatex/generic/lutabulartools/lutabulartools.lua | 29 | ||||
-rw-r--r-- | macros/luatex/generic/lutabulartools/lutabulartools.pdf | bin | 105162 -> 110213 bytes | |||
-rw-r--r-- | macros/luatex/generic/lutabulartools/lutabulartools.sty | 23 | ||||
-rw-r--r-- | macros/luatex/generic/lutabulartools/lutabulartools.tex | 28 |
4 files changed, 53 insertions, 27 deletions
diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.lua b/macros/luatex/generic/lutabulartools/lutabulartools.lua index 361530bc97..24c8d5598e 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-10-15 +--% 2022-10-22 --% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,7 +25,8 @@ local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl if (__PL_EXTRAS__ == nil) or (__PENLIGHT__ == nil) then - tex.sprint('\\PackageError{yamlvars}{penlight package with extras (or extrasnoglobals) option must be loaded before this package}{}') + tex.sprint('\\PackageError{yamlvars}{penlight package with extras (or extrasglobals) option must be loaded before this package}{}') + tex.print('\\stop') end local ltt = {} @@ -111,7 +112,7 @@ function ltt.MagicCell(s0,spec,mcspec,pre,content) ltt.debugtalk(pl.List{v, h, r, c, mcspec}:join'; ','v, h, r, c, mcspec') --help_wrt(_CurTabColAbv,'current column') - if s0 == _xTrue or (pl.List(ltt.SI_cols):contains(ltt.col) -- special columns for SI + if s0 == pl.tex._xTrue or (pl.List(ltt.SI_cols):contains(ltt.col) -- special columns for SI and c == '') then -- multicolumn cannot have {} around it STR = STR .. '{' -- multirow and makcell must have {} around it S column is used pl.tex.add_bkt_cnt() @@ -266,8 +267,6 @@ function ltt.make1cmidrule(s, r, c, cmd) -- s=square r=round c=curly end c = ltt.get_midrule_col(t[1])..'-'..ltt.get_midrule_col(t[2]) cmd = cmd..'{'..c..'}' - --help_wrt(cmd) - ltt.debugtalk(cmd,'make1cmidrule') tex.print(cmd) end @@ -303,28 +302,34 @@ function ltt.mrX.set_midruleX(new_sett, def) end new_sett = luakeys.parse(new_sett) ltt.mrX.settings = T.union(curr_sett, new_sett) - ltt.debugtalk{ltt.mrX.settings, 'new settings'} + ltt.debugtalk(ltt.mrX.settings, 'new midruleX 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 + local rule = s.rule 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) + if not rule:startswith('\\') then rule = '\\'..rule end -- todo consider allowing \gmidrule syntax, possible issue with expansion + ltt.debugtalk(rule, 'apply midruleX') + tex.sprint(rule) ltt.mrX.cntr = 0 end end function ltt.mrX.add_label_and_check_page_change() - ltt.mrX.pgcntr = ltt.mrX.pgcntr + 1 + 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 + local rcurr = pl.tex.get_ref_info('ltt@tabular@row@'..ltt.mrX.pgcntr) + local rprev = pl.tex.get_ref_info('ltt@tabular@row@'..ltt.mrX.pgcntr-1) + --local rcurrc, _, _ = pl.tex.get_ref_info_all_cref('ltt@tabular@row@'..ltt.mrX.pgcntr) + ltt.debugtalk('curr: '..rcurr[2]..' prev: '..rprev[2]..' row: '..ltt.mrX.pgcntr, 'check midruleX page change') + ltt.debugtalk(rcurr, 'miduleX current reference info for row: '..ltt.mrX.pgcntr) + --ltt.debugtalk(rcurrc, 'miduleX current cleveref cref info') + if rcurr[2] ~= rprev[2] then -- pg no is second element return true end return false diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.pdf b/macros/luatex/generic/lutabulartools/lutabulartools.pdf Binary files differindex 789cf01125..5d6e7f62d0 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.pdf +++ b/macros/luatex/generic/lutabulartools/lutabulartools.pdf diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.sty b/macros/luatex/generic/lutabulartools/lutabulartools.sty index 5a501a8346..f1dea60c5a 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.sty +++ b/macros/luatex/generic/lutabulartools/lutabulartools.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-10-15 +% 2022-10-22 % 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-15] +\ProvidesPackage{lutabulartools}[2022-10-22] \RequirePackage{booktabs} \RequirePackage{multirow} @@ -53,7 +53,10 @@ \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{\setmidruleX}{s O{N} m}{% + \MakeluastringCommands[N]{#2}% + \luadirect{lutabt.mrX.set_midruleX(\plluastringA{#3}, \luastring{#1})}% +} \NewDocumentCommand{\midruleXreset}{O{0}}{\luadirect{lutabt.mrX.cntr = tonumber(\luastring{#1})}} \NewCommandCopy\resetmidruleX\midruleXreset @@ -141,14 +144,14 @@ \let\oldtabular\tabular -\RenewExpandableDocumentCommand{\tabular}{ O{c} m }{% +\RenewExpandableDocumentCommand{\tabular}{ O{l} m }{% \luadirect{lutabt.set_col_spec(\luastringN{#2})}% \oldtabular[#1]{\ltt@ltrim#2\ltt@rtrim}% } \expandafter\let\expandafter\oldtabulars\csname tabular*\endcsname \expandafter\let\expandafter\endoldtabulars\csname endtabular*\endcsname -\RenewDocumentEnvironment{tabular*}{ m O{c} m }{% +\RenewDocumentEnvironment{tabular*}{ m O{l} m }{% \luadirect{lutabt.set_col_spec(\luastringN{#3})}% \begin{oldtabulars}{#1}[#2]{\ltt@ltrim#3\ltt@rtrim}% }{% @@ -156,6 +159,12 @@ } %%% NOTE tabularx uses tabular*, NO NEED TO CHANGE TABULARX! +\let\oldlongtable\longtable +\RenewExpandableDocumentCommand{\longtable}{ O{l} m }{% + \luadirect{lutabt.set_col_spec(\luastringN{#2})}% + \oldlongtable[#1]{\ltt@ltrim#2\ltt@rtrim}% +} + %s0,spec,mcspec,pre,content % Magic Cell @@ -184,6 +193,10 @@ lutabt.SI_cols[\string##lutabt.SI_cols+1] = '#1' }} +\NewDocumentCommand{\forcecolspec}{ m }{\luadirect{ + lutabt.col_spec = (\luastring{#1}):totable() +}} + \ProcessOptions diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.tex b/macros/luatex/generic/lutabulartools/lutabulartools.tex index ecc35df511..97802fce07 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.tex +++ b/macros/luatex/generic/lutabulartools/lutabulartools.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-10-15 +% 2022-10-22 % Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -62,9 +62,12 @@ \newcommand{\tMC}{\cmd{\\MC}} +\usepackage{caption} + +\usepackage{ltxtable} \usepackage{longtable} -\usepackage[pl,extrasnoglobals]{penlight} +\usepackage[pl,extras]{penlight} \RequirePackage{lutabulartools} @@ -78,6 +81,7 @@ \usepackage{hyperref} + \begin{document} % todo: can improve naming... set col spec to a table instead of a string @@ -85,10 +89,9 @@ \maketitle -lutabulartools is a package that contains a few useful macros to help with tables. -Most functions require LuaLaTeX. +lutabulartools is a package that contains a few useful Lua\LaTeX-based macros to help with tables. This package redefines the {\ttfamily tabular} and {\ttfamily tabular*} environments. -The following packages are loaded: +The following packages are loaded if not already, so if you have specific settings for these packages, load this package after: \texttt{ {booktabs}, {multirow}, @@ -186,7 +189,6 @@ To add a column that should be surrounded by brackets for \cmd{siunitx} purposes S is included by default. -\newpage \subsection{Examples} @@ -350,11 +352,14 @@ Concering \cmd{longtable}s: If \cmd{reset} is set to \cmd{true}, resets the row counter to \cmd{resetnum}, to ensure you have the same X number of rows after the header of each page of a \cmd{longtable}.\\ The starred version of first reverts the settings to default, then loads your inputted settings, which the non-starred version only overwrites the settings specified. \cmd{\setmidruleX*{}} will restore to default. +Use optional parameter \cmd{\setmidruleX*[o|n|f]{}} +to control expansion of the key-val settings (\cmd{[n]} for not expanded is default). Before you want counting to begin, you should apply \cmd{\resetmidruleX} to avoid header rows being counted. Use \cmd{\noalign{\resetmiduleX}} if you need place a rule on the same line the reset takes place, or in a cell before \cmd{\\}. Note that \cmd{\resetmidruleX} resets the row counter to 0, and is in effect, a short-cut for \cmd{\setmidruleX{}} or \cmd{\setmidruleX{cntr=0}} + % %\begin{tabular}{l@{\luadirect{tex.print('\\midrule')}}} % Hello \\ @@ -395,7 +400,7 @@ Num & . & . & . \\ Here's an example with long table. Notice the gray rules reliably appear 3 rows after each header. \begin{verbatim} -\setmidruleX{reset=true,resetnum=0} +\setmidruleX{reset=true,resetnum=0,rule="\gcmidrules{1r,2-}"} \def\tblhead{\toprule No & Name & Place & other\\\midrule} \def\tblcontinued{\MC[+l]{Continued...}\\} \def\tblcontinues\MC[+r]{...Continues}\\} @@ -421,13 +426,13 @@ Here's an example with long table. Notice the gray rules reliably appear 3 rows 14 & & & \\ 15 & & & \\\newpage 16 & & & \\ -17 & & & \\\resetmidruleX -18 & & & \\ +17 & & & \\ +18 & & & \\\resetmidruleX 19 & & & \\ \end{longtable} \end{verbatim} -\setmidruleX{reset=true,resetnum=0} +\setmidruleX{reset=true,resetnum=0,rule="\gcmidrules{1r,2-}"} \def\tblhead{\toprule No & Name & Place & other\\\midrule} \def\tblcontinued{\MC[+l]{Continued...}\\} \def\tblcontinues{\MC[+r]{...Continues}\\} @@ -459,4 +464,7 @@ Here's an example with long table. Notice the gray rules reliably appear 3 rows \end{longtable} +\LTXtable{\linewidth}{ltxexample} + + \end{document} |