texlive[64724] Master/texmf-dist: lutabulartools (16oct22)

commits+karl at tug.org commits+karl at tug.org
Sun Oct 16 22:15:33 CEST 2022


Revision: 64724
          http://tug.org/svn/texlive?view=revision&revision=64724
Author:   karl
Date:     2022-10-16 22:15:33 +0200 (Sun, 16 Oct 2022)
Log Message:
-----------
lutabulartools (16oct22)

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

Modified: trunk/Master/texmf-dist/doc/luatex/lutabulartools/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/lutabulartools/README.md	2022-10-16 20:15:17 UTC (rev 64723)
+++ trunk/Master/texmf-dist/doc/luatex/lutabulartools/README.md	2022-10-16 20:15:33 UTC (rev 64724)
@@ -1,6 +1,6 @@
 # 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. The [github repo](https://github.com/kalekje/lutabulartools) has an MS Excel
+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, or produce midrules every Xth row with `\midruleX`. 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.
 
 

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

Modified: trunk/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex	2022-10-16 20:15:17 UTC (rev 64723)
+++ trunk/Master/texmf-dist/doc/luatex/lutabulartools/lutabulartools.tex	2022-10-16 20:15:33 UTC (rev 64724)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at 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
@@ -24,10 +24,14 @@
 
 
 \documentclass[11pt,parskip=half]{scrartcl}
+
+
 \setlength{\parindent}{0ex}
+
 \newcommand{\llcmd}[1]{\leavevmode\llap{\texttt{\detokenize{#1}\ }}}
-\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}}
-\newcommand{\qcmd}[1]{``\cmd{#1}''}
+\def\cmd{\bgroup\catcode`\\=12 \catcode`\ =12 \cmdA}
+\def\cmdA#1{\egroup{\texttt{\detokenize{#1}}}}
+
 \usepackage{url}
 \usepackage{showexpl}
 \lstset{explpreset={justification=\raggedright,pos=r,wide=true}}
@@ -57,12 +61,15 @@
 
 \newcommand{\tMC}{\cmd{\\MC}}
 
+
+\usepackage{longtable}
+
 \usepackage[pl,extrasnoglobals]{penlight}
 
 
 \RequirePackage{lutabulartools}
 \title{lutabulartools}
-\subtitle{some useful tabular tools (LuaLaTeX-based)}
+\subtitle{some useful LuaLaTeX-based tabular tools}
 
 \usepackage{tabularx}
 \usepackage{siunitx}
@@ -69,6 +76,8 @@
 
 \lttdebugON
 
+\usepackage{hyperref}
+
 \begin{document}
 
 %  todo: can improve naming... set col spec to a table instead of a string
@@ -127,31 +136,31 @@
 
 \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.
+You can use one of three: \cmd{t}, \cmd{m}, \cmd{b} for top, middle, bottom (vertical alignment),
+and/or \cmd{l}, \cmd{c}, \cmd{r} for horizontal alignment, in no particular order.
 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. 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,
+\cmd{C,R}, \cmd{C}, or \cmd{,R} are a valid inputs,
 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 (positive numbers occupy columns to the right
+you can pass \cmd{,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),
+Additionally, you can pass \cmd{+} in place of C (number of columns wide),
 and it will make the cell width fill until the end of the current row.
 
 Examples:\\
-\qcmd{\MC[2,2]} means two columns wide, two rows 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.\\
+\cmd{\MC[2,2]} means two columns wide, two rows tall.\\
+\cmd{\MC[2,1]} or \cmd{\MC[2]}  means two columns wide, one row tall.\\
+\cmd{\MC[1,2]} or \cmd{\MC[,2]} means one column wide, two rows tall.\\
+\cmd{\MC[+,2]}, if placed in the first column, occupies the entire row and is two rows tall.\\
+\cmd{\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).
+So, \cmd{\MC[l1,2b]} and \cmd{\MC[1,2 lb]} are both left-bottom aligned (spaces are ignored).
 
 
 \llcmd{(override}%
@@ -298,9 +307,9 @@
 or omit the last number.\\
 \llcmd{\cmidrule}is a single partial rule, with the above features\\
 \llcmd{\gcmidrule}is a single partial gray rule, with the above features\\
-You can add multiple \qcmd{cmidrule}'s with the \texttt{(g)cmidrules} command. Separate with a comma.
-You can apply global trimming of the rules with the \qcmd{()} optional argument, and then
-override it for a specific rule by placing \qcmd{r} or \qcmd{l} with the span specification.\\
+You can add multiple \cmd{cmidrule}'s with the \texttt{(g)cmidrules} command. Separate with a comma.
+You can apply global trimming of the rules with the \cmd{()} optional argument, and then
+override it for a specific rule by placing \cmd{r} or \cmd{l} with the span specification.\\
 \llcmd{\gcmidrules}Can produce multiple, light gray partial rules\\
 \llcmd{\cmidrules}Can produce multiple black partial rules.\\
 Here's an example:
@@ -332,27 +341,34 @@
 \llcmd{\midruleX}%
 With this command, you can place a rule
 every X rows.
-You can change the step size and what kind of midrule you prefer.
-\begin{verbatim}
-\def\midruleXstep{5}
-\def\midruleXrule{\gmidrule}
-\end{verbatim}
-
-
-To use, insert \cmd{@{\midrulex}} at the end of each row using the tabular column spec.
+To use, place \cmd{@{\midruleX}} at the end of the tabular column spec, eg. \cmd{\begin{tabular}{ll@{\midruleX}}..}.
+You can configure the step size and what kind of midrule you prefer with the following key-val syntax, with default values below:\\
+\cmd{\setmidruleX{step=5,rule=midrule,reset=false,resetnum=0,cntr=0}}\\
+\cmd{step} is the number of rows (X) before applying the rule set by \cmd{rule}. \\
+Concering \cmd{longtable}s: If \cmd{reset} is set to \cmd{true},
+\cmd{\midruleX} will also add a unique \cmd{\label{}} on each row, and if the row starts on a newpage,
+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.
 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 or in a cell.
+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 \\
+%\end{tabular}
 
+%
 \begin{LTXexample}
-\def\midruleXstep{3}
-\def\midruleXrule{\cmidrules{1,3-4r}}
+\setmidruleX{step=3,rule=gmidrule}
 \begin{tabular}{rclc@{\midruleX}}
                 % ^^^ inject midrule
 \toprule
 Num  & . & . & .  \\
-\midrule\resetmidruleX  % reset
+\midrule\resetmidruleX
+% reset so header dont count
 1    & & &  \\
 2    & & &  \\
 3    & & &  \\
@@ -364,10 +380,83 @@
 9    & & &  \\
 10   & & &  \\
 11   & & &  \\
-\resetmidruleX % no bottom rule
+\resetmidruleX % resest
+   % so no bottom gray rule
 12   & & &  \\
 \bottomrule
 \end{tabular}
 \end{LTXexample}
 
+%}
+
+%
+
+\pagebreak
+
+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}
+\def\tblhead{\toprule No & Name & Place & other\\\midrule}
+\def\tblcontinued{\MC[+l]{Continued...}\\}
+\def\tblcontinues\MC[+r]{...Continues}\\}
+\begin{longtable}{rclc@{\midruleX}}
+  \tblhead\endfirsthead
+  \tblcontinued\head\endhead % all the lines above this will be repeated on every page
+  \tblcontinues\endfoot
+  \bottomrule End.\endlastfoot
+  \resetmidruleX
+1       &           &       &  \\
+2       &           &       &    \\
+3       &           &       &    \\
+4       &           &       &    \\
+5       &           &       &    \\
+6       &           &       &    \\
+7       &           &       &    \\
+8       &           &       &    \\
+9       &           &       &    \\
+10      &           &       &    \\
+11      &           &       &    \\
+12      &           &       &    \\
+13      &           &       &    \\
+14      &           &       &    \\
+15      &           &       &    \\\newpage
+16      &           &       &    \\
+17      &           &       &    \\\resetmidruleX
+18      &           &       &    \\
+19      &           &       &    \\
+\end{longtable}
+\end{verbatim}
+
+\setmidruleX{reset=true,resetnum=0}
+\def\tblhead{\toprule No & Name & Place & other\\\midrule}
+\def\tblcontinued{\MC[+l]{Continued...}\\}
+\def\tblcontinues{\MC[+r]{...Continues}\\}
+\begin{longtable}{rclc@{\midruleX}}
+  \tblhead\endfirsthead
+  \tblcontinued\tblhead\endhead % all the lines above this will be repeated on every page
+  \tblcontinues\endfoot
+  \bottomrule End.\endlastfoot
+  \resetmidruleX
+1       &           &       &  \\
+2       &           &       &    \\
+3       &           &       &    \\
+4       &           &       &    \\
+5       &           &       &    \\
+6       &           &       &    \\
+7       &           &       &    \\
+8       &           &       &    \\
+9       &           &       &    \\
+10      &           &       &    \\
+11      &           &       &    \\
+12      &           &       &    \\
+13      &           &       &    \\
+14      &           &       &    \\
+15      &           &       &    \\\newpage
+16      &           &       &    \\
+17      &           &       &    \\
+18      &           &       &    \\\resetmidruleX
+19      &           &       &    \\
+\end{longtable}
+
+
 \end{document}

Modified: trunk/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua	2022-10-16 20:15:17 UTC (rev 64723)
+++ trunk/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.lua	2022-10-16 20:15:33 UTC (rev 64724)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at 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,17 +45,12 @@
 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
@@ -62,7 +57,7 @@
     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 @@
 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 at tabular@row@'..ltt.mrX.pgcntr..'}}')
+    local _, pgcurr = pl.tex.get_ref_info('ltt at tabular@row@'..ltt.mrX.pgcntr)
+    local _, pgprev = pl.tex.get_ref_info('ltt at 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 at row@'..ltt.tabular_row_pages_cntr..'}}')
+--    if ltt.get_ref_page('tabular at row@'..ltt.tabular_row_pages_cntr) -
+--            ltt.get_ref_page('tabular at 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)

Modified: trunk/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty	2022-10-16 20:15:17 UTC (rev 64723)
+++ trunk/Master/texmf-dist/tex/luatex/lutabulartools/lutabulartools.sty	2022-10-16 20:15:33 UTC (rev 64724)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at 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
@@ -23,7 +23,7 @@
 % OR OTHER DEALINGS IN THE SOFTWARE.
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{lutabulartools}[2022-04-16]
+\ProvidesPackage{lutabulartools}[2022-10-15]
 
 \RequirePackage{booktabs}
 \RequirePackage{multirow}
@@ -49,38 +49,16 @@
 
 
 
-%% 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
+%%% midrule every X rows
 
-\def\midruleXstep{5}
-\def\midruleXrule{\gmidrule}
+\def\midruleX{\aftergroup\aftergroup\aftergroup\midruleX at aux}
+\def\midruleX at 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{\midruleXreset}{O{0}}{\luadirect{lutabt.mrX.cntr = tonumber(\luastring{#1})}}
+\NewCommandCopy\resetmidruleX\midruleXreset
 
-\newcounter{midruleX}
-\newcommand*{\midruleX}{%
-  \aftergroup\aftergroup\aftergroup\midruleXaux
-}
-\newif\ifmidruleX
 
-\newcommand*{\midruleXaux}{%
-  \noalign{%
-    \stepcounter{midruleX}%
-    \ifnum\value{midruleX}=\midruleXstep %
-      \global\midruleXtrue
-      \resetmidruleX%
-    \else
-      \global\midruleXfalse
-    \fi
-  }
-  \ifmidruleX\midruleXrule\fi
-}
-\newcommand*{\resetmidruleX}{\setcounter{midruleX}{0}}  %%% todo maybe put noalign in here
 
-\resetmidruleX
-
-
-
-
 %%%%
 
 %%% gray midrule and gray cmidrule
@@ -235,3 +213,45 @@
 %  \newcolumntype{\ltt at ltrim}{@{\stepcounter{RowNumCnt}}}
 %%  \newcolumntype{\ltt at rtrim}{@{\luadirect{lutabt.get_TabColNum()}}}
 %}
+
+
+%% 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}
+%
+%\newcounter{midruleX}
+%\newcommand*{\midruleXa}{%
+%  \aftergroup\aftergroup\aftergroup\midruleXaux
+%}
+%
+%\newif\ifmidruleX
+%
+%\newcommand*{\midruleXaux}{%
+%  \noalign{%
+%    \stepcounter{midruleX}%
+%    \ifnum\value{midruleX}=\midruleXstep %
+%      \global\midruleXtrue
+%      \resetmidruleX%
+%    \else
+%      \global\midruleXfalse
+%    \fi
+%  }
+%  \ifmidruleX\midruleXrule\fi
+%}
+
+%\newcommand*{\resetmidruleX}{\setcounter{midruleX}{0}}  %
+%\resetmidruleX
+
+%\NewDocumentCommand{\resetmidruleXonNP}{O{0}}{\luadirect{lutabt.reset_midruleX_on_newpage(\luastring{#1})}}
+
+%
+%\NewDocumentCommand{\IfmidruleX}{m m}{%  if a midruleX was placed, do #1, if not, do #2
+%  \ifnum\the\value{midruleX}=0
+%      #1
+%    \else
+%      #2
+%  \fi%
+%}
\ No newline at end of file



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