texlive[62253] branches/branch2021.final/Master/texmf-dist:

commits+karl at tug.org commits+karl at tug.org
Sun Feb 27 22:33:55 CET 2022


Revision: 62253
          http://tug.org/svn/texlive?view=revision&revision=62253
Author:   karl
Date:     2022-02-27 22:33:55 +0100 (Sun, 27 Feb 2022)
Log Message:
-----------
lutabulartools (27feb22) (branch)

Modified Paths:
--------------
    branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/README.md
    branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.pdf
    branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex
    branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua
    branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty

Modified: branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/README.md
===================================================================
--- branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/README.md	2022-02-27 21:33:46 UTC (rev 62252)
+++ branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/README.md	2022-02-27 21:33:55 UTC (rev 62253)
@@ -1,12 +1,13 @@
 # lutabulartools
 
-This LuaLaTeX package offers some useful macros for tabular matter. The `\MC` command it provides allows one to specify a multi-row and or multi-column cell with minimal syntax. The package loads `booktabs` and adds a gray midrule, and allows a user to specify multiple `\cmidrules` with one command.
+This LuaLaTeX package offers some useful macros for tabular matter. The `\MC` command it provides allows one to specify a multi-row and or multi-column cell with minimal syntax. The package loads `booktabs` and adds a gray midrule, and allows a user to specify multiple `\cmidrules` with one command. The [github repo](https://github.com/kalekje/lutabulartools) has an MS Excel
+macro-enabled spreadsheet named "LaTeX-Tabular-Generator.xlsm" to help make tables in LaTeX.
 
 
 
 # License (MIT)
 
-Copyright (C) 2021 Kale Ewasiuk
+Copyright (C) 2021-2022 Kale Ewasiuk
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

Modified: branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.pdf
===================================================================
(Binary files differ)

Modified: branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex
===================================================================
--- branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex	2022-02-27 21:33:46 UTC (rev 62252)
+++ branches/branch2021.final/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex	2022-02-27 21:33:55 UTC (rev 62253)
@@ -1,6 +1,6 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2021-11-07
-% Copyright (C) 2021 Kale Ewasiuk
+% 2022-02-27
+% Copyright (C) 2021-2022 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
 % of this software and associated documentation files (the "Software"), to deal
@@ -61,11 +61,20 @@
 \title{lutabulartools}
 \subtitle{some useful tabular tools (LuaLaTeX-based)}
 
+\usepackage{tabularx}
+\usepackage{siunitx}
+
 \begin{document}
+
+%  todo: can improve naming... set col spec to a table instead of a string
+
+
 \maketitle
 
 lutabulartools is a package that contains a few useful macros to help with tables.
-Most functions require LuaLaTeX. The following packages are loaded:
+Most functions require LuaLaTeX.
+This package redefines the {\ttfamily tabular} and {\ttfamily tabular*} environments.
+The following packages are loaded:
 \texttt{
 {booktabs},
 {multirow},
@@ -78,31 +87,46 @@
 {penlight},
 }
 
+\section{Options}
+The author likes tables with left and right-most columns flush to the end.
+Since the \cmd{tabular} env is redefined in this, the author took the liberty to
+automatically pad the \cmd{tabular} cell spec with \cmd{@{}} on each end.
+If you don't want this, you can pass \cmd{notrim} to the package. Or,
+you can manually fix it in a \cmd{tabular} with \cmd{!{}} like so:
+
+\begin{LTXexample}
+\begin{tabular}{!{}c!{}}\toprule
+Xyz\\\bottomrule    \end{tabular}
+\end{LTXexample}
+
+
 \section{\texttt{\textbackslash MC} -- Magic Cell}
 \texttt{\textbackslash MC} (magic cell) combines the facilities of
 \cmd{\multirow} and \cmd{\multicolumn} from the \texttt{multirow} package, and \cmd{\makcell} from the titular package.
 With the help of LuaLaTeX, it takes an easy-to-use cell specification and employs said commands as required.
+\cmd{\MC} will not work properly if your table is only 1 column wide (you probably don't need \cmd{MC} in that case anyway...).
 Here is the usage:
 
 \texttt{\textbackslash MC * [cell spec] <cell format> (override multicolumn col) \{contents\} }
 
 \llcmd{*}This will wrap the entire command in \{\}. This is necessary for \texttt{siunitx} single-column width columns.
-However, the \tMC\  command attempts to detect this automatically.
+However, the \cmd{\MC} command attempts to detect this automatically.
 
 \llcmd{[cell spec]}%
 Any letters placed in this argument are used for cell alignment.
 You can use one of three: \qcmd{t}, \qcmd{m}, \qcmd{b} for top, middle, bottom (vertical alignment),
 or \qcmd{l}, \qcmd{c}, \qcmd{r} for horizontal alignment.
-By default, \tMC\   will try to autodetect the horizontal alignment based on the current column.
+By default, \cmd{\MC}   will try to autodetect the horizontal alignment based on the current column.
 If it can't, it will be left-aligned.
-The default vertical alginment is top.
+The default vertical alginment is top. More on this in section \ref{s.def}.
 
 This argument can also contain two integers, separated by a comma (if two are used).
 \qcmd{C,R}, \qcmd{C}, or \qcmd{,R} are a valid inputs,
-where R=rows (int), and C=columns, (int).
+where \cmd{R}=rows (int), and \cmd{C}=columns, (int).
 If you want a 1 column wide, multirow cell,
-you can pass \qcmd{,R}. These numbers can be negative.
-If no spec is passed, (argument empty), \tMC\
+you can pass \qcmd{,R}. These numbers can be negative (positive numbers occupy columns to the right
+and rows below, and negative numbers occupy columns to the left and rows above).
+If no spec is passed, (argument empty), \cmd{\MC}
 acts like a \texttt{makecell}.
 Additionally, you can pass \qcmd{+} in place of C (number of columns wide),
 and it will make the cell width fill until the end of the current row.
@@ -109,22 +133,104 @@
 
 Examples:\\
 \qcmd{\MC[2,2]} means two columns wide, two rows tall.\\
-\qcmd{\MC[2,1]} or \qcmd{\MC[2]} or  means two columns wide, one row tall.\\
+\qcmd{\MC[2,1]} or \qcmd{\MC[2]}  means two columns wide, one row tall.\\
 \qcmd{\MC[1,2]} or \qcmd{\MC[,2]} means one column wide, two rows tall.\\
+\qcmd{\MC[+,2]}, if placed in the first column, occupies the entire row and is two rows tall.\\
+\qcmd{\MC[+,2]}, if placed in the second column, occupies the second column to the end of the table and is two rows tall.\\
 In any of these examples, you can place the alignment letters anywhere.
+So, \qcmd{\MC[l1,2b]} and \qcmd{\MC[1,2 lb]} are both left-bottom aligned (spaces are ignored).
 
 
 \llcmd{(override}%
 You may want to adjust the column specification of a multicolumn  cell,\\
 \llcmd{multicolumn)}for example, using
-\texttt{@\{\}c@\{\}} to remove padding between the cell.
+\texttt{(@\{\}c@\{\})} to remove padding between the cell.
 
+
 \llcmd{<cell format>}%
 You can place formatting like \cmd{\bfseries} here.
 
-Here's an example.
 
+\subsection{Defaults}\label{s.def}
+The \cmd{tabular[*]} environment is re-defined to use Lua pattern matching
+to parse the column specification of the table. This is done to determine how many columns there are,
+and what the current column type is, even if specifications like \cmd{r@{.}l*{3}{r}} are used.
+If you have defined a column that expands many, you should register it with
+\cmd{\setMCrepl{?}{??}} where \cmd{?} is your column and \cmd{??} is what it expands to.
+You can also specify default horizontal and vertical alignments (ie if alignment not passed to \cmd{\MC})
+for an arbitrary column by \cmd{\setMChordef{?}{l|r|c}} and\\
+\cmd{\setMChordef{?}{t|m|b}}, where \cmd{?} is the column.
+To add a column that should be surrounded by brackets for \cmd{siunitx} purposes, do so with \cmd{\addMCsicol{?}}.
+S is included by default.
+
+
+\newpage
+
+\subsection{Examples}
+
+\let\nl\\
+
+
+\subsubsection{A good use for headers}
 \begin{LTXexample}
+\begin{tabular}{ l l l }\toprule
+\MC[+m]<\itshape>{A Decent
+                Example}\\\midrule
+    & \MC[2m]{Heading} \\\cmidrule{2-}
+\MC[b,-2]{Multi\\Line}  & A & B   \\\midrule
+\end{tabular}
+\end{LTXexample}
+
+\subsubsection{A small example}
+
+
+\begin{LTXexample}
+\begin{tabular}{ l l l }\midrule
+ A & \MC[mc2,2]{Lttrs}    \\
+ B &                       \\
+ 1 & A & B   \\
+\end{tabular}
+\end{LTXexample}
+
+
+\subsubsection{A small bad example}
+Notice that the top-aligned p-column
+doesn't play particularly well with the middle aligned \cmd{\MC}
+\begin{LTXexample}
+\begin{tabular}{ p{1cm} l }\toprule
+   hello\newline world
+        & \MC[mr]{11\\2} \\
+\end{tabular}
+\end{LTXexample}
+
+
+\subsubsection{If you insist on vertical lines}
+\begin{LTXexample}
+\begin{tabular}{|c|c|c|} \hline
+1 & 2 & 3\\\hline
+4 & \MC[2,2cm](@{}c@{}|)%
+    <\ttfamily>{5}\\\cline{1-1}
+  & \MC[2](r|){} \\\hline%hacky fix
+6 & 7 & 8\\\hline
+\end{tabular}
+\end{LTXexample}
+
+
+\subsubsection{A perhaps useful example}
+
+\begin{LTXexample}
+\begin{tabularx}{\linewidth}{S[table-format=2.1,table-alignment=left]X}
+% err & ... \\% ERROR, not wrap
+  \MC{Error,\%} & Comment \\% MC helps
+ 3.1 & \MC[,2]{multi-line\\comment}\\
+ 10.1& \\
+ \MC[2c]{... ...} \\
+\end{tabularx}
+\end{LTXexample}
+
+\subsubsection{A messy example}
+
+\begin{LTXexample}
 \begin{tabular}{| c | c | c | c | c | c |}\toprule
  \MC[2,2cm]<\ttfamily>{2,2cm}   & \MC[2r]<\ttfamily>{2r} & 5 & \MC[,2b]<\ttfamily>{,2b}\\
    &   & 3 & 4 & 5 & \\\midrule
@@ -136,23 +242,39 @@
 \end{LTXexample}
 
 
+
+
+
 %%% https://tex.stackexchange.com/questions/287346/width-of-column-after-multicolumn-header
 
 %\textbackslash MC[<spec>]{<contents}
 
-\subsection{Notes}
-This package redefines the {\ttfamily tabular} and {\ttfamily tabular*} environments.
-It uses Lua pattern matching to parse the column specification of the table to know how many columns there are,
-and what the current column type is. If you have defined a column that creates many, it will not work.
-This will be worked out in later package revisions.
-%But, to know how many columns there are you, you will have
-%either have to manually set todo the lua variable before the table, or,
-%in the last column of the first row, \texttt{get\_tab\_colnum ()}.
-%The above Lua function can be used to get the current column number.
-%You will also remove the ability for this package to know what the current column spec is
 
+%\subsubsection{And another one}
+%
+%\begin{LTXexample}
+%\setMChordef{l}{r}
+%\setMCverdef{l}{b}
+%% change deflt alignment ^
+%\newcolumntype{e}{ll}
+%\setMCrepl{e}{ll}
+%% e -> l l  ^
+%\begin{tabular}{l l l e}\toprule
+%aaaaa & bbb & ccc & eee & fff\\
+%\MC{aaaaa}\\
+%\MC{a}\\\midrule
+%\MC{a\\bbbbb}  & x\\\midrule
+%\makecell[br]{a\\b} & x\\\midrule
+%\MC[+]{--- ---}\\
+%\end{tabular}
+%\end{LTXexample}
+%% WHY ISNT THIS RIGHT?
 
 
+
+\newpage
+
+
 \section{Some additional rules}
 This package also redefines the \texttt{booktabs} midrules.\\
 \llcmd{\gmidrule}is a full gray midrule.\\
@@ -171,11 +293,23 @@
 Here's an example:
 
 \begin{LTXexample}
-\begin{tabular}{c c c c c c}\toprule
- 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrule{+1}  % rule on last column
- 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrules{1,3-+3,+} % rule on first col, third to third last col, and last col
- 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrules{1,3-+3rl,+} % same as above, but trim middle
- 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrules(l){1,r3-+3,+1}% trim left for all, but only trim right for middle rule
+\begin{tabular}{c c c c c c}
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \cmidrule{+1}  % rule on last column
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \cmidrules{1,3-+3,+} % rule on first col, third to third last col, and last col
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \cmidrules{1,3-+3rl,+} % same as above, but trim middle
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \cmidrules(l){1,r3-+3,+1}% trim left for all, but only trim right for middle rule
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \gcmidrule{+1}  % rule on last column
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \gcmidrules{1,3-+3,+} % rule on first col, third to third last col, and last col
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \gcmidrules{1,3-+3rl,+} % same as above, but trim middle
+ 1 & 2 & 3 & 4 & 5 & 6\\
+    \gcmidrules(l){1,r3-+3,+1}% trim left for all, but only trim right for middle rule
 \end{tabular}
 \end{LTXexample}
 
@@ -192,13 +326,15 @@
 \end{verbatim}
 
 
-Usage: Insert midrulex at the end of each row using  the column spec.
+To use, insert \cmd{@{\midrulex}} at the end of each row using the tabular column spec.
 Before you want counting to begin, you should
-apply resetmidruleX (also to avoid header rows).
+apply \cmd{\resetmidruleX}  to avoid header rows being counted.
+Use \cmd{\noalign{\resetmiduleX}} if you need place a rule on the same line or in a cell.
 
+
 \begin{LTXexample}
-\def\midruleXstep{4}
-\def\midruleXrule{\cmidrules{1,3-4}}
+\def\midruleXstep{3}
+\def\midruleXrule{\cmidrules{1,3-4r}}
 \begin{tabular}{rclc@{\midruleX}}
                 % ^^^ inject midrule
 \toprule

Modified: branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua
===================================================================
--- branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua	2022-02-27 21:33:46 UTC (rev 62252)
+++ branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua	2022-02-27 21:33:55 UTC (rev 62253)
@@ -1,6 +1,6 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2021-11-07
---% Copyright (C) 2021 Kale Ewasiuk
+--% 2022-02-27
+--% Copyright (C) 2021-2022 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
 --% of this software and associated documentation files (the "Software"), to deal
@@ -24,31 +24,19 @@
 
 local ltt = {}
 
---todo clean up the code, make some stuff local
---todo maybe add the penlight lua table to latex tabular?
+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
 
---integrate current cell
---todo check if S[] column cells work!!!
---todo might be smarter to just append this to tabular commands and read argument
 
--- Initialize counter variable
-ltt.NumTabCols = 0
-ltt.NumTabColsAbv = 0 -- num of tab columns  if above 1
-ltt.TabColSpec = ''
-ltt.TabColSpecAbv = '' -- tab column spec if above 1
-ltt.CurTabColAbv = '' -- current tab column spec if above 1
-ltt.TabColNum = 0
-ltt.NumBkts = 0
-ltt.NumTabColsMX = 0
-
-
---todo re=enable
 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.get_TabColNum()
+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
@@ -62,58 +50,33 @@
       for _, sub in node.traverse_id(unset_t, nest.head) do
         col = col + sub + 1
       end
-      ltt.TabColNum = col
+      ltt.col_num = col
     else
-      ltt.TabColNum = 1
+      ltt.col_num = 1
     end
-    ltt.CurTabColAbv = ltt.TabColSpecAbv:sub(ltt.TabColNum,ltt.TabColNum)
-    ltt.NumTabColsMX = math.max(ltt.NumTabColsMX, ltt.TabColNum) -- a different way to calculate total cols
-    return ltt.TabColNum
+    ltt.col = ltt.col_spec[ltt.col_num]
 end
 
 
-function ltt.get_TabRowNum()
-    return tex.count['c at RowNumCnt'] -- access latex counter
-end
-
--- The next function computes the number of columns from
--- contents of string 'zz'
-function ltt.calc_NumTabCols( zz )
-    --help_wrt(zz, 'col spec OG')
-    -- -- NOT NEEDED: zz = zz:gsub ( "^.-(%b{}).-$", "%1" )  -- retain the first "{....}" substring
+function ltt.set_col_spec(zz)
+    -- contents of string 'zz'
+    -- register the table column specification
     zz = zz:gsub ( "%*%s-{(%d-)}%s-(%b{})" ,     -- expand expressions such as "*{5}{l}" to "lllll"
             function(y, z ) z = z:sub (2 , -2)  return string.rep (z, y) end ) --
     zz = zz:gsub ( "%b{}" , "" ) -- omit all stuff in curly braces and square
     zz = zz:gsub ( "%b[]" , "" )
     zz = zz:gsub ( "[@!|><%s%*\']" , "" )  -- some more characters to ignore
-    -- todo: any columns defined that break into more than one column should be expanded here
-    --help_wrt(zz, 'col spec CLEAN')
-    ltt.TabColSpec = zz -- stripped column spec with no {} or <
-    ltt.NumTabCols = string.len(ltt.TabColSpec)
-    if ltt.NumTabCols > 1 then
-        ltt.TabColSpecAbv = ltt.TabColSpec
-        ltt.NumTabColsAbv = ltt.NumTabCols
+    zz = zz:gsub('%a', ltt.col_replaces) -- sub extra column
+    _col_spec = zz:totable() -- requires pl extras
+    --help_wrt(_col_spec, 'helpme')
+    if #_col_spec > 1 then
+        ltt.col_spec = _col_spec
+    else
+        ltt.col_spec1 = _col_spec
     end
 end
 
---todo fix square brackets after letters, expand multiple
---calc_NumTabCols('ss')
---calc_NumTabCols('*{6}{s}')
---calc_NumTabCols('l*{6}{l}')
---calc_NumTabCols('lll')
---calc_NumTabCols('ll[]')
---calc_NumTabCols('ll[]*{6}{l}')
---calc_NumTabCols('*{6}{l}')
---calc_NumTabCols('y*{6}{sq}x')
---print(_TabColSpec.. '<---Column spec')
 
---http://ctan.mirror.rafal.ca/macros/latex/contrib/multirow/multirow.pdf
---http://ctan.mirror.colo-serv.net/macros/latex/contrib/makecell/makecell.pdf
--- todo CONSIDER THIS
--- https://tex.stackexchange.com/questions/331716/newline-in-multirow-environment
-
-
-
 --todo
 -- if p{} column, and multirow is 1, use {=} instead of {*}
 -- but note, makecell will not work. So you may want to skip it.multicolumn
@@ -122,6 +85,8 @@
 
 function ltt.MagicCell(s0,spec,mcspec,pre,content)
     --
+    ltt.set_col_num() -- register current column number and column spec
+
     local STR = ''
     reset_bkt_cnt()
 
@@ -132,8 +97,8 @@
     h, mcspec, c = ltt.get_HColSpec(h, mcspec, c)  -- infer horizontal alignment, num columns
 
     --help_wrt(_CurTabColAbv,'current column')
-    if s0 == _xTrue or (pl.List({'S', 'Q', 'L', 'R'}):contains(ltt.CurTabColAbv) -- special columns for SI
-            and c == '') then -- multicolumn cannot have {} around it todo test with siunitx, num rows, num columns
+    if s0 == _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
         add_bkt_cnt()
     end
@@ -167,7 +132,7 @@
 
 
 function ltt.parse_MagicCell_spec(spec)
-    local mrowsym = '*'
+    local mrowsym = '*' -- *  = natural width, = will match p{2cm} for example
     local skipmakecell = false
     if string.find(spec, '=')  then
         spec = spec:gsub('=', '')
@@ -175,9 +140,9 @@
         skipmakecell = true
     end
 
-    spec = spec:lower():gsub('%s','')  -- take lower case and remove
+    spec = spec:lower():gsub('%s','')  -- take lower case and remove space
     local vh, rc = spec:gextract('%a')  -- extract characters
-    local v = vh:gfirst({'t', 'm', 'b'}) or 't'
+    local v = vh:gfirst({'t', 'm', 'b'}) or ltt.col_ver_repl[ltt.col] or 't'
     local h = vh:gfirst({'l', 'c', 'r'}) or ''
     v = v:gsub('m', 'c')
 
@@ -191,43 +156,27 @@
 end
 
 
-ltt.TabColMapping = { -- horizontal cell alignment that multicolumn should use if () or [hori] not passed to func
-    l = 'l',
-    c = 'c',
-    r = 'r',
-    p = 'p',
-    P = 'c',
-    X = 'l',
-    Y = 'c',
-    Z = 'l',
-    N = 'c',
-    L = 'l',
-    R = 'r',
-    C = 'c',
-}
-
 function ltt.get_HColSpec(h, mcspec, c) -- take horizontal alignment
     -- c is num columns, h is horizontal alginment,
     --Assumes _TabColNum was calculated previosly
-    ltt.get_TabColNum()
      if c == '+' then  -- fill row to end
-        c =  tostring(ltt.NumTabColsAbv -  ltt.TabColNum + 1)
+        c =  tostring(#ltt.col_spec -  ltt.col_num + 1)
     end
     if h == '' then -- if horizontal not provided, use declared column
-        h = ltt.TabColMapping[ltt.CurTabColAbv] or 'l'
+        h = ltt.col_hor_repl[ltt.col] or 'l'
     end
     if c ~= '' then -- only make new mcspec if column nums > 0
         if mcspec == '' then -- and if no mcspec was passed
             mcspec = h
-            if ltt.TabColNum == 1 then -- if first column, auto detect padding
+            if ltt.col_num == 1 then -- if first column, auto detect padding
                 mcspec = '@{}'..mcspec
             end
-            if (ltt.TabColNum + tonumber(c) - 1) == ltt.NumTabColsAbv then  -- if end on last column
+            if (ltt.col_num + tonumber(c) - 1) == #ltt.col_spec then  -- if end on last column
                 mcspec = mcspec..'@{}'
             end
         else -- if mcspec if given, extract the alignment
-            ltt.calc_NumTabCols(mcspec)
-            h = ltt.TabColSpec -- get 1 character column spec from mcspec and override h
+            ltt.set_col_spec(mcspec)
+            h = ltt.col_spec1[1] -- get 1 character column spec from mcspec and override h
         end
     end
     return h, mcspec, c
@@ -234,8 +183,45 @@
 end
 
 
--- midrule stuff
 
+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'}
+--ltt.SI_cols = {'S'}
+--ltt.SI_cols = {'N'}
+
+
+
+
+
+-----
+--- midrule stuff
+-----
+
 function ltt.get_midrule_col(s)
     if string.find(s, '+')  then
         s = s:gsub('+', '')
@@ -242,15 +228,12 @@
         if (s == '') or (s == '0') then
             s = 1
         end
-        s = tostring(ltt.NumTabColsAbv - tonumber(s) + 1) -- use number of tabular columns above 0,
+        s = tostring(#ltt.col_spec - tonumber(s) + 1) -- use number of tabular columns above 0,
     end
     return s
 end
 
---todo if comma present, create multiple according to spec. Also allow LR in []
 
---- midrule stuff ---
-
 function ltt.make1cmidrule(s, r, c, cmd) -- s=square r=round c=curly
     cmd = '\\'..cmd
     if s ~= '' then
@@ -283,4 +266,16 @@
 end
 
 
-return ltt -- lutabulartools
\ No newline at end of file
+--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)
+--    help_wrt(ltt.col_spec,s)
+--end
+
+return ltt -- lutabulartools
+
+
+
+--http://ctan.mirror.rafal.ca/macros/latex/contrib/multirow/multirow.pdf
+--http://ctan.mirror.colo-serv.net/macros/latex/contrib/makecell/makecell.pdf
+-- https://tex.stackexchange.com/questions/331716/newline-in-multirow-environment

Modified: branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty
===================================================================
--- branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty	2022-02-27 21:33:46 UTC (rev 62252)
+++ branches/branch2021.final/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty	2022-02-27 21:33:55 UTC (rev 62253)
@@ -1,6 +1,6 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2021-11-07
-% Copyright (C) 2021 Kale Ewasiuk
+% 2022-02-27
+% Copyright (C) 2021-2022 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
 % of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,7 @@
 % OR OTHER DEALINGS IN THE SOFTWARE.
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{lutabulartools}[2021-11-07]
+\ProvidesPackage{lutabulartools}[2022-02-27]
 
 \RequirePackage{booktabs}
 \RequirePackage{multirow}
@@ -38,12 +38,19 @@
 \luadirect{lutabt = require('lutabulartools')}
 
 
+\newcolumntype{\ltt at ltrim}{@{}}
+\newcolumntype{\ltt at rtrim}{@{}}
+\DeclareOption{notrim}{
+  \newcolumntype{\ltt at ltrim}{}
+  \newcolumntype{\ltt at rtrim}{}
+}
 
-% DOES NOT WORK WITH colortbl package ???
 
 
 %% 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}
 
@@ -67,33 +74,19 @@
 }
 \newcommand*{\resetmidruleX}{\setcounter{midruleX}{0}}  %%% todo maybe put noalign in here
 
-
 \resetmidruleX
 
-%% https://tex.stackexchange.com/questions/145084/what-is-the-function-of-noalign
-%\begin{tabular}{rclc@{\midruleX}}  % inject midrule
-%\toprule
-%Number  & Student Id    & Name  & Score\\\midrule\resetmidruleX  % reset to 0
-%1       & 14-001    & Andy  & 75 \\
-%2       &           &       &    \\
-%3       &           &       &    \\
-%4       &           &       &    \\
-%5       &           &       &    \\
-%6       &           &       &    \\
-%7       &           &       &    \\
-%8       &           &       &    \\
-%9       &           &       &    \\\resetmidruleX
-%10      &           &       &    \\%\noalign{\resetmidruleX} % noalig required to not cause error with bottomrule, but that's oka because it should be used on row 9 anyway
-%\bottomrule
-%\end{tabular}
 
 
+
 %%%%
 
 %%% gray midrule and gray cmidrule
+\aboverulesep=0.0ex
+\belowrulesep=0.5ex
+\providecommand{\gmidrule}{\arrayrulecolor{lightgray}\specialrule{\lightrulewidth}{0.5\aboverulesep}{0.5\belowrulesep}\arrayrulecolor{black}}
+\cmidrulewidth=\lightrulewidth
 
-\providecommand{\gmidrule}{\arrayrulecolor{lightgray}\specialrule{\lightrulewidth}{0.4\aboverulesep}{0.6\belowrulesep}\arrayrulecolor{black}}
-
 %%% use gcmidrule for a gray "c" midrule
 % Copy \cmidrule from
 %  http://mirrors.ctan.org/macros/latex/contrib/booktabs/booktabs.dtx
@@ -113,7 +106,7 @@
     \global\advance\@cmidlb-\@cmidla
     \global\@thisrulewidth=#3
     \@setrulekerning{#4}
-    \ifnum\@lastruleclass=\z@\vskip 0.4\aboverulesep\fi
+    \ifnum\@lastruleclass=\z@\vskip 0.5\aboverulesep\fi
     \ifnum0=`{\fi}\@gtempa
     \noalign{\ifnum0=`}\fi\futurenonspacelet\@tempa\@xgcmidrule}
 \def\@xgcmidrule{%
@@ -123,7 +116,7 @@
    \else \ifx\@tempa\morecmidrules
        \vskip \cmidrulesep
        \global\@lastruleclass=\@ne\else
-       \vskip 0.6\belowrulesep
+       \vskip 0.5\belowrulesep
        \global\@lastruleclass=\z@
    \fi\fi
    \ifnum0=`{\fi}
@@ -167,30 +160,17 @@
 
 
 
-
-
-%%%  tabular commands
-
-\newcommand{\TabColNum}{\luadirect{tex.print(lutabt.get_TabColNum())}} % prints the current column number of tabular
-\newcommand{\NumTabCols}{\luadirect{tex.print(lutabt.NumTabCols)}} % prints the total num columns of tabular
-\newcounter{RowNumCnt}
-\setcounter{RowNumCnt}{1}
-
 \let\oldtabular\tabular
 \RenewExpandableDocumentCommand{\tabular}{ O{c} m }{%
-  \setcounter{RowNumCnt}{1}%
-  \luadirect{lutabt.calc_NumTabCols(\luastringN{#2})}%
-  \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason
-  \oldtabular[#1]{@{\stepcounter{RowNumCnt}}#2@{\luadirect{lutabt.get_TabColNum()}}}%
+  \luadirect{lutabt.set_col_spec(\luastringN{#2})}%
+  \oldtabular[#1]{\ltt at ltrim#2\ltt at rtrim}%
 }
 
 \expandafter\let\expandafter\oldtabulars\csname tabular*\endcsname
 \expandafter\let\expandafter\endoldtabulars\csname endtabular*\endcsname
 \RenewDocumentEnvironment{tabular*}{ m O{c} m }{%
-  \setcounter{RowNumCnt}{1}%
-  \luadirect{lutabt.calc_NumTabCols(\luastringN{#3})}%
-  \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason
-  \begin{oldtabulars}{#1}[#2]{@{\stepcounter{RowNumCnt}}#3@{\luadirect{lutabt.get_TabColNum()}}}
+  \luadirect{lutabt.set_col_spec(\luastringN{#3})}%
+  \begin{oldtabulars}{#1}[#2]{\ltt at ltrim#3\ltt at rtrim}%
 }{%
   \end{oldtabulars}%
 }
@@ -211,7 +191,45 @@
 )}}
 
 
+\NewDocumentCommand{\setMCrepl}{m m}{\luadirect{
+  lutabt.col_replaces.#1 = '#2'
+}}
+\NewDocumentCommand{\setMChordef}{ m m}{\luadirect{
+  lutabt.col_hor_repl.#1 = '#2'
+}}
+\NewDocumentCommand{\setMCverdef}{ m m}{\luadirect{
+  lutabt.col_ver_repl.#1 = '#2'
+}}
+\NewDocumentCommand{\addMCsicol}{ m }{\luadirect{
+  lutabt.SI_cols[\string##lutabt.SI_cols+1] = '#1'
+}}
 
 
+
 \ProcessOptions
 
+
+
+
+
+
+
+%%%  OLD STUFF,
+%% before I had a fall-back for counting columns (just calculate current column on last column once)
+%%   and kept track of row numbers. I felt that this wasn't needed, so I've removed.
+%\newcommand{\TabColNum}{\luadirect{tex.print(lutabt.get_TabColNum())}} % prints the current column number of tabular
+%\newcommand{\NumTabCols}{\luadirect{tex.print(lutabt.NumTabCols)}} % prints the total num columns of tabular
+%\newcounter{RowNumCnt}
+%\setcounter{RowNumCnt}{1}
+%  \setcounter{RowNumCnt}{1}%
+%  \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason
+%  \setcounter{RowNumCnt}{1}%
+%  \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason
+%\DeclareOption{notrimx}{
+%  \global\newcolumntype{\ltt at ltrim}{!{\stepcounter{RowNumCnt}}}
+%%  \global\newcolumntype{\ltt at rtrim}{!{\luadirect{lutabt.get_TabColNum()}}}
+%}
+%\DeclareOption{trimx}{
+%  \newcolumntype{\ltt at ltrim}{@{\stepcounter{RowNumCnt}}}
+%%  \newcolumntype{\ltt at rtrim}{@{\luadirect{lutabt.get_TabColNum()}}}
+%}



More information about the tex-live-commits mailing list.