texlive[73334] Master/texmf-dist: luatbls (6jan25)
commits+karl at tug.org
commits+karl at tug.org
Mon Jan 6 22:19:57 CET 2025
Revision: 73334
https://tug.org/svn/texlive?view=revision&revision=73334
Author: karl
Date: 2025-01-06 22:19:57 +0100 (Mon, 06 Jan 2025)
Log Message:
-----------
luatbls (6jan25)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdf
trunk/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex
trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua
trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex 2025-01-06 21:19:47 UTC (rev 73333)
+++ trunk/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex 2025-01-06 21:19:57 UTC (rev 73334)
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje at gmail.com)
-% 2025-01-01
+% 2025-01-05
% Copyright (C) 2025 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -64,6 +64,8 @@
\begin{document}
%
+%TODO: need options in updating tables or csv
+
\maketitle
@@ -91,7 +93,9 @@
\llcmd{i }: the flexible indexer to get a single item.\\
\llcmd{I }: the flexible indexer to get a single or multiple items.\\
\llcmd{keyval }: a key-value string for the table. Standalone values are set to boolean.\\
-\llcmd{csv }: a key-value string where standalone values are parsed as array-like.
+\llcmd{csv }: a key-value string where standalone values are parsed as array-like.\\
+\llcmd{opts }: options for \cmd{luakeys.parse()}.\\
+\llcmd{cstemp }: a template for command-sequences, lengths, or toggles. By default is \cmd{ltbl<t><k>}.\\
There are a few ways to use the index (placeholder \cmd{i}.\\
\cmd{t.k} where \cmd{t} is the table name and \cmd{k} is a string key (i.e. uses \cmd{luatbls.t.k}),\\
@@ -101,7 +105,7 @@
In this case, passing a number will assume an integer index.
To use a \cmd{I},
-you can explicitly select tables and groups of keys by \cmd{t|seq}, or \cmd{t.k}, or \cmd{t/n}.
+you can select tables and groups of keys by \cmd{t|seq}, or \cmd{t.k}, or \cmd{t/n}.
If no \cmd{|./} is provided, the recent table is used and the argument is assumed to be a sequence of keys.
\cmd{penlightplus}'s command \cmd{penlight.seq.tbltrain()} syntax is used for \cmd{seq}uences.
To summarize what \cmd{seq} can be, a comma-separated list of numbers or keys are used to specify which elements are iterated over.
@@ -108,8 +112,15 @@
NumPy-like slicing is possibly with \cmd{:} to choose integer ranges.
If \cmd{*} is provided,
all string keys are iterated.
-If \cmd{I} is entirely blank, all elements of the recent table are used, which is equivalent to \cmd{t|*,:}.\\
+If \cmd{I} is entirely blank, all elements of the recent table are used, which is equivalent to \cmd{t|*,:}.
+
+The \cmd{cstemp} default can be changed with: \cmd{\luadirect{luatbls._cstemp = 'ltbl<t><k>'}},
+where \cmd{<t>} and \cmd{<k>} are the table and key names. Numerical keys are converted to capital letters: 1->A, 2->B.
+It is recommended that tables and keys contain letters only for predictable behaviour when using this feature.
+If the value of a tbl's key is a table, every element in that table is defined, and the keys of that nested table is
+appended to the cs: \cmd{ltbl<t><k1><k2>} (noting that numbers are converted to letters).
+
Note: nested tables are currently not fully supported. Some variations of commands have an \cmd{E} suffix which indicates
that nested elements can be explicitly indexed.
The table name must be specified, and the validity of table names and keys are not checked.
@@ -119,7 +130,6 @@
which will not expand the \cmd{v}, \cmd{keyval}, or \cmd{csv} args.
-
%%%
\subsection*{Creating Tables}
@@ -149,6 +159,9 @@
\cmd{\tblgetE{t.k}} An 'explicit' version of tbl get. Use this for nested tables. The tbl name must be specified.
The validity of table names and keys are not checked.\\
+\cmd{\tblsetE{i}{v}} the explicit version of \cmd{\tblset}. Quotes must be used for strings in the \cmd{v}, and arbitrary lua code can be entered.\\
+
+
\begin{LTXexample}
\tblfrkv{ex}{a,b,c,first=john,last=smith}%
[defaults={x=0,1=one,n=false,y=yes}]
@@ -159,11 +172,14 @@
\tblget{.x}\\
\tbladd{ex.newkey}{val}\tblget{newkey}\\
\tbladd{nk}{VAL}\tblget{nk}\\
+\tblsetE{ex.d}{math.mod2(3)}
+\tblget{d}
\end{LTXexample}
\begin{LTXexample}
\tblfrcsv{EX}{x={1,2,{1,2,3}},name=me}
\tblgetE{EX.x[1]}\\
+\tblsetE{EX.x[3][3]}{99}\\
\tblgetE{EX.x[3][3]}\\
\tblgetE{EX.name}\\
\end{LTXexample}
@@ -206,10 +222,10 @@
\cmd{\tblfor{I}{template}} and \cmd{\tblforN} By default, iterates over all elements (\cmd{seq = *,:}),
but arbitrary indices/keys can be iterated over as per \cmd{penlight.seq.tbltrain} syntax.
-\cmd{<k>} and \cmd{<v>} are placeholders in the template that are replaced by the keys and vals and can be changed by:
+\cmd{<k>} and \cmd{<v>} are placeholders in the template that are replaced by the keys and vals and can be changed by:\\
\cmd{\luadirect{luatbls._tblv = '<v>'}}
-If you want to iterate over a second-level tabel, you must use:\\
+If you want to iterate over a second-level table, you must use:\\
\cmd{\tblforE} and \cmd{\tblforEN}, and explicitly provide the table and element.
\begin{LTXexample}
@@ -227,34 +243,30 @@
\subsection*{Definitions}
-\cmd{\tbldef{i}[cs]} pushes the value to macro \cmd{\cs}. If cs is not provided, a default cs name of \cmd{dtbl<t><k>} is used.\\
-\cmd{\tblgdef{i}[cs]} like above but global definition is used.\\
+\cmd{\tbldef{i}[cstemp]} pushes the value to macro \cmd{cstemp}.\\
+\cmd{\tblgdef{i}[cstemp]} like above but global definition is used.\\
-\cmd{\tbldefs{I}[cspfx]} and \cmd{\tblgdefs{I}[cspfx]} defines items in table \cmd{t} (use recent if blank) with format \cmd{<cspfx><key>} where \cmd{cspfx} is a command sequence prefix.
-If \cmd{cspfx} is blank, keys will be defined as \cmd{dtbl<t><k>}.
-The default \cmd{cspfx} is changed by:\\\cmd{\luadirect{luatbls._cspfx = 'dtbl'}}\\
-Numerical keys are converted to capital letters: 1->A, 2->B.
-It is recommended that tables and keys contain letters only for predictable behaviour when using this feature.\\
-If the value of a tbl's key is a table, every element in that table is defined, and the keys of that nested table is
-appended to the cs: \cmd{dtbl<t><k1><k2>} (noting that numbers are converted to letters).\\
+\cmd{\tbldefs{I}[cstemp]} and \cmd{\tblgdefs{I}[cstemp]} defines items in table \cmd{t} (use recent if blank).
+%\newlength{\tesst}
+%\setlength{\tesst}{ 1 cm }
\begin{LTXexample}
\tblfrcsv{EX}{n1,kA=v1,n2,n3,n4,
kB=v2,kC=v3,n5,n6}
-1>\tbldef{kA}{mycs}\mycs\tbldef{kA}{}\dtblEXkA\\
-2> \tbldef{EX/1}{}\dtblEXA
+1>\tbldef{kA}[mycs]\mycs\tbldef{kA}\ltblEXkA\\
+2> \tbldef{EX/1}\ltblEXA
\end{LTXexample}
\begin{LTXexample}
\tblfrcsv{EX}{x={1,2,3}}
-1>\tbldef{x}{mycs}\mycsA, \mycsB \\
-2>\tbldefs{}\dtblEXxA, \dtblEXxB
+1>\tbldef{x}[mycs]\mycsA, \mycsB \\
+2>\tbldefs{}\ltblEXxA, \ltblEXxB
\end{LTXexample}
-\cmd{\tbldefxy{i}[cspfx]} splits the value of item by space, and creates two definitions \cmd{<cspfx>x} and \cmd{<cspfx>y}.
+\cmd{\tbldefxy{i}[cstemp]} splits the value of item by space, and creates two definitions \cmd{<cstemp>x} and \cmd{<cstemp>y}.
This might be useful for passing and using tikz coordinates, for example \cmd{xy=0 5}. An error is thrown if the values
are non-numeric.\\
@@ -261,11 +273,37 @@
\begin{LTXexample}[width=0.5\linewidth]
\tblfrkv{EX}{coords=12 34,other}
\tbldefxy{coords}[d]\dx, \dy \\
-\tbldefxy{coords}\dtblEXcoordsx, \dtblEXcoordsy \\
+\tbldefxy{coords}\ltblEXcoordsx, \ltblEXcoordsy \\
\end{LTXexample}
+\cmd{\tblmaketoggle{i}[cstemp]} will create and set a toggle (see etoolbox) for a truth-y value (see \cmd{pl.hasval})\\
+\cmd{\tblmaketoggles{I}[cstemp]} will iterate over I and create and set global toggles (see etoolbox) for boolean values\\
+\begin{LTXexample}
+ \tblfrkv{ex}{atog=true,!btog}
+ \tblmakegtoggles{}
+ \iftoggle{ltblexatog}{True}{}\\
+ \iftoggle{ltblexbtog}{}{False}\\
+\end{LTXexample}
+
+\cmd{\tblmakelength{i}[cstemp]} will 'forcefully' create a length for an element. Glue expressions are permitted. See
+etoolbox's \cmd{\deflength{}}\\
+\cmd{\tblmakelengths{I}[cstemp]} will iterate over I and create global lengths for elements that are tex dimensions. If
+plain numbers are found, \cmd{sp} units are used (in case the \cmd{convert_dimensions=true} luakeys option is used, which converts to sp)\\
+
+
+\begin{LTXexample}
+ \tblfrkv{ex}{alen=1cm,blen=2cm,clen=10mm*2+2cm}[convert_dimensions]
+ \tblmakelengths{}[<k>]
+ I\hspace{\alen}I\\
+ I\hspace{\blen}I\\
+ \tblmakelength{clen}[LEN]
+ I\hspace{\LEN}I
+\end{LTXexample}
+
+
+
\subsection*{Utilities}
\cmd{\tblapply{I}{func1(<v>,x,y)|:func2}[newtable]} apply a Lua function(s).\\If \cmd{newtable} is provided, a new table is created (and made the recent table)
@@ -295,19 +333,16 @@
3> \tblget{new/1}
\end{LTXexample}
-%\begin{luacode*}
-% penlight.wrth(penlight.tablex.list2comma({'a','b','c'}),'XYZ')
-%\end{luacode*}
-%\tblprt*{ex}
-
\cmd{\tblprt{t}} pretty-print the table in console. Using \cmd{\tblprt*{}} will terminate the LaTeX program immediately after and issue an error, which could be useful for debugging.
+\clearpage
+
\luadirect{luatbls._debug = true}
\subsubsection*{An Example}
Modified: trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua 2025-01-06 21:19:47 UTC (rev 73333)
+++ trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua 2025-01-06 21:19:57 UTC (rev 73334)
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje at gmail.com)
---% 2025-01-01
+--% 2025-01-05
--% Copyright (C) 2025 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -33,7 +33,7 @@
luatbls._xysep = '%s+' -- spaces separate x-y coordinates
luatbls._tblv = '<v>'
luatbls._tblk = '<k>'
-luatbls._cspfx = 'dtbl'
+luatbls._cstemp = 'ltbl<t><k>'
luatbls._debug = false
function luatbls._dprint(s1, s2)
@@ -157,26 +157,33 @@
return k
end
+function luatbls._make_def_name(t, k, temp)
+ if temp == penlight.tex.xNoValue then
+ temp = luatbls._cstemp
+ end
+ k = luatbls._make_alpha_key(k)
+ return temp:gsub('<t>',t):gsub('<k>',k)
+end
+
function luatbls._def_tbl(ind, def, g)
local _tbl, _key = luatbls._get_tbl_index(ind)
- if def == '' then def = luatbls._cspfx.._tbl..luatbls._make_alpha_key(_key) end
- luatbls._def_tbl_one(luatbls[_tbl][_key], def, g)
+ def = luatbls._make_def_name(_tbl, _key, def)
+ luatbls._def_tbl_one(luatbls[_tbl][_key], def, g)
end
-function luatbls._def_tbl_some(tblseq, def, g)
- for t, k, v in luatbls._iter_tbls_vals(tblseq) do
- if def == '' then def = luatbls._cspfx..t end
- local def2 = def .. luatbls._make_alpha_key(k)
- luatbls._def_tbl_one(v, def2, g)
+function luatbls._def_tbl_some(Ind, def, g)
+ for t, k, v in luatbls._iter_tbls_vals(Ind) do
+ local newdef = luatbls._make_def_name(t, k, def)
+ luatbls._def_tbl_one(v, newdef, g)
end
end
+
function luatbls._def_tbl_one(v, cs, g)
if type(v) == 'table' then
for kk, vv in pairs(v) do
- kk = luatbls._make_alpha_key(kk)
- token.set_macro(cs..kk, tostring(vv), g)
+ token.set_macro(cs..luatbls._make_alpha_key(kk), tostring(vv), g)
end
else
token.set_macro(cs, tostring(v), g)
@@ -186,7 +193,7 @@
function luatbls._def_tbl_coords(ind, def)
local tbl, key = luatbls._get_tbl_index(ind)
local str = luatbls[tbl][key]
- if def == '' then def = luatbls._cspfx..tbl..key end
+ def = luatbls._make_def_name(tbl, key, def)
local x, y = str:strip():splitv(luatbls._xysep)
if (not penlight.hasval(x)) or (not penlight.hasval(y)) then
penlight.tex.pkgerror('luatbls', '_def_tbl_coords function could not parse coordiantes given as "'..str..'" ensure two numbers separated by space are given!', '', true)
@@ -196,6 +203,62 @@
end
+
+function luatbls._make_one_toggle(def, v, g)
+ tex.sprint(g..'\\providetoggle{'..def..'}')
+ tex.sprint(g..'\\toggle'..tostring(v)..'{'..def..'}')
+end
+
+function luatbls._make_toggle_tbl(ind, def, g)
+ g = g or ''
+ local t, k = luatbls._get_tbl_index(ind)
+ local v = luatbls[t][k]
+ def = luatbls._make_def_name(t, k, def)
+ luatbls._make_one_toggle(def, penlight.hasval(v), g)
+end
+
+function luatbls._make_toggles_tbl(Ind, def, g)
+ g = g or ''
+ for t, k, v in luatbls._iter_tbls_vals(Ind) do
+ if type(v) == 'boolean' then
+ local newdef = luatbls._make_def_name(t, k, def)
+ luatbls._make_one_toggle(newdef, v, g)
+ end
+ end
+end
+
+
+function luatbls._make_one_length(def, v, g)
+ tex.sprint(g..'\\providenewlength{\\'..def..'}')
+ tex.sprint(g..'\\deflength{\\'..def..'}{'..v..'}')
+end
+
+function luatbls._make_length_tbl(ind, def, g)
+ g = g or ''
+ local t, k = luatbls._get_tbl_index(ind)
+ local v = luatbls[t][k]
+ if type(v) == 'number' then
+ v = tostring(v)..'sp'
+ end
+ local def = luatbls._make_def_name(t, k, def)
+ luatbls._make_one_length(def, v, g)
+end
+
+function luatbls._make_lengths_tbl(Ind, def, g)
+ g = g or ''
+ for t, k, v in luatbls._iter_tbls_vals(Ind) do
+ if type(v) == 'number' then
+ v = tostring(v)..'sp'
+ end
+ if v:istexdim() then
+ local newdef = luatbls._make_def_name(t, k, def)
+ luatbls._make_one_length(newdef, v, g)
+ end
+ end
+end
+
+
+
function luatbls._for_tbl_prt(k, v,cmd)
local cmd_new = cmd:gsub(luatbls._tblv, tostring(v)):gsub(luatbls._tblk, tostring(k)):gsub('(\\%w+) ', '%1') -- for some reason a space gets added to \cs, maybe
luatbls._dprint(cmd_new, '_for_tbl replacement')
@@ -202,8 +265,8 @@
tex.sprint(cmd_new)
end
-function luatbls._for_tbl(tblseq, cmd)
- for t, k, v in luatbls._iter_tbls_vals(tblseq) do
+function luatbls._for_tbl(Ind, cmd)
+ for t, k, v in luatbls._iter_tbls_vals(Ind) do
luatbls._for_tbl_prt(k, v,cmd)
end
end
Modified: trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty 2025-01-06 21:19:47 UTC (rev 73333)
+++ trunk/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty 2025-01-06 21:19:57 UTC (rev 73334)
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje at gmail.com)
-% 2025-01-01
+% 2025-01-05
% Copyright (C) 2025 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -131,7 +131,9 @@
luatbls._set_tbl_item(\luastring{#1}, \luastringN{#2})
}}
+\NewDocumentCommand{\tblsetE}{m m}{\luadirect{luatbls.#1 = #2}}% set item with {value}
+
\NewDocumentCommand{\tblif}{ m m O{}}{\ifluax{luatbls._get_tbl_item(\luastring{#1})}{#2}[#3]}
\NewDocumentCommand{\tblifv}{m m O{}}{\ifluaxv{luatbls._get_tbl_item(\luastring{#1})}{#2}[#3]}
@@ -146,14 +148,33 @@
\NewDocumentCommand{\tblforEN}{ m m }{\luadirect{luatbls._for_tbl_e(luatbls.#1, \luastringN{#2})}}
-\NewDocumentCommand{\tbldef}{ m m }{\luadirect{luatbls._def_tbl(\luastring{#1}, \luastring{#2})}}
-\NewDocumentCommand{\tblgdef}{ m m }{\luadirect{luatbls._def_tbl(\luastring{#1}, \luastring{#2}, 'global')}}
+\NewDocumentCommand{\tbldef}{ m o }{\luadirect{luatbls._def_tbl(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblgdef}{ m o }{\luadirect{luatbls._def_tbl(\luastring{#1}, \luastring{#2}, 'global')}}
-\NewDocumentCommand{\tbldefs}{ m O{} }{\luadirect{luatbls._def_tbl_some(\luastring{#1}, \luastring{#2})}}
-\NewDocumentCommand{\tblgdefs}{ m O{} }{\luadirect{luatbls._def_tbl_some(\luastring{#1}, \luastring{#2}, 'global')}}
+\NewDocumentCommand{\tbldefs}{ m o }{\luadirect{luatbls._def_tbl_some(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblgdefs}{ m o }{\luadirect{luatbls._def_tbl_some(\luastring{#1}, \luastring{#2}, 'global')}}
-\NewDocumentCommand{\tbldefxy}{ m O{} }{\luadirect{luatbls._def_tbl_coords(\luastring{#1}, \luastring{#2})}}% define #2x and #2y from a space delimited x-y pair
+
+\ProvideDocumentCommand{\providenewlength}{ m }{\ifdeflength{#1}{}{\newlength{#1}}}
+
+
+\NewDocumentCommand{\tblmaketoggle}{ m o }{\luadirect{luatbls._make_toggle_tbl(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblmakegtoggle}{ m o }{\luadirect{luatbls._make_toggle_tbl(\luastring{#1}, \luastring{#2}, '\\global')}}
+
+\NewDocumentCommand{\tblmaketoggles}{ m o }{\luadirect{luatbls._make_toggles_tbl(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblmakegtoggles}{ m o }{\luadirect{luatbls._make_toggles_tbl(\luastring{#1}, \luastring{#2}, '\\global')}}
+
+
+\NewDocumentCommand{\tblmakelength}{ m o }{\luadirect{luatbls._make_length_tbl(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblmakeglength}{ m o }{\luadirect{luatbls._make_length_tbl(\luastring{#1}, \luastring{#2}, '\\global')}}
+
+\NewDocumentCommand{\tblmakelengths}{ m o }{\luadirect{luatbls._make_lengths_tbl(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblmakeglengths}{ m o }{\luadirect{luatbls._make_lengths_tbl(\luastring{#1}, \luastring{#2}, '\\global')}}
+
+
+\NewDocumentCommand{\tbldefxy}{ m o }{\luadirect{luatbls._def_tbl_coords(\luastring{#1}, \luastring{#2})}}% define #2x and #2y from a space delimited x-y pair
+
\NewDocumentCommand{\tblapply}{m m O{}}{\luadirect{luatbls._apply_tbl(\luastring{#1}, \luastring{#2}, \luastring{#3})}}
\NewDocumentCommand{\tblprt}{s m}{%
More information about the tex-live-commits
mailing list.