texlive[68973] Master/texmf-dist: penlightplus (26nov23)

commits+karl at tug.org commits+karl at tug.org
Sun Nov 26 22:05:12 CET 2023


Revision: 68973
          https://tug.org/svn/texlive?view=revision&revision=68973
Author:   karl
Date:     2023-11-26 22:05:12 +0100 (Sun, 26 Nov 2023)
Log Message:
-----------
penlightplus (26nov23)

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

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

Modified: trunk/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex	2023-11-26 21:05:03 UTC (rev 68972)
+++ trunk/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex	2023-11-26 21:05:12 UTC (rev 68973)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-09-04
+% 2023-11-25
 % Copyright (C) 2021-2023 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -157,7 +157,7 @@
 no, once, twice, or full expansion. For example, we can control the expansion of args 2 and 3 with arg 1:
 
 \begin{verbatim}
-	\NewDocumentCommand{\splitToComma}{ O{nn} m m }{%
+	\NewDocumentCommand{\splittocomma}{ O{nn} m m }{%
   \MakeluastringCommands[nn]{#1}%
   \luadirect{penlight.tex.split2comma(\plluastringA{#2},\plluastringB{#3})}%
 }
@@ -199,17 +199,19 @@
 \cmd{penlight.tbls} table.
 
 
-\cmd{\newtbl{t}} declares a new table with name \cmd{t}\\
-\cmd{\chgtbl{t}} changes the 'recent' table\\
+\cmd{\tblnew{t}} declares a new table with name \cmd{t}\\
+\cmd{\tblchg{t}} changes the 'recent' table\\
 \cmd{\tblfrkv{t}{key-val string}[luakeys opts]} new table from key-vals using \cmd{luakeys} \\
+\cmd{\tblfrkvN{t}{key-val string}[luakeys opts]} does not expand key-val string \cmd{luakeys} \\
  \cmd{\tblfrcsv} a shorthand \cmd{\tblfrkv{t}{csv}[naked_as_value=true,opts]}, a good way to convert  a comma-separated list to an array\\
-\cmd{\settbl{i}{v}} sets a value of the table/index \cmd{i} to \cmd{v}\\
-\cmd{\gettbl{i}} gets the value and \cmd{tex.sprint()}'s it\\
-\cmd{\deftbl{i}{d}} pushes the value to a \cmd{cs} named \cmd{d}\\
-\cmd{\gdeftbl{i}{d}} pushes the value to a global\\
+\cmd{\tblset{i}{v}} sets a value of the table/index \cmd{i} to \cmd{v}\\
+\cmd{\tblget{i}} gets the value and \cmd{tex.sprint()}'s it\\
+\cmd{\tbldef{i}{d}} pushes the value to a \cmd{cs} named \cmd{d}\\
+\cmd{\tblgdef{i}{d}} pushes the value to a global\\
+\cmd{\tbldefxy{i}{d}} splits the value of item by spaces creates two definitions \cmd{\dx} and \cmd{\dy}. Useful for pasing tikz coordinates like \cmd{xy=0 5}\\
 \cmd{\iftbl{i}{tr}[fa]} runs code \cmd{ta} if the item is true else \cmd{fr}\\
 \cmd{\iftblv{i}{tr}[fa]} runs code \cmd{ta} if the item is truthy else \cmd{fr}\\
-\cmd{\kvtblundefcheck} will throw an error if you use define a table from key-values
+\cmd{\tblkvundefcheck} will throw an error if you use define a table from key-values
 and use a key that was not specified in the luakeys parse options via \cmd{opts.defaults} or \cmd{opts.defs}.
 
 There are 3 ways to use the index (placeholder \cmd{{i}} above).
@@ -220,53 +222,68 @@
 \begin{LTXexample}[width=0.3\linewidth]
 \tblfrkv{my}{a,b,c,first=john,last=smith}%
 	[defaults={x=0,1=one,n=false,y=yes}]
-\gettbl{my.a}\\
-\gettbl{my.x}\\
-\iftbl{n}{tr}[fa]\\
-\iftblv{n}{TR}[FA]\\
-\iftbl{my.y}{Tr}[Fa]\\
-\iftblv{y}{tR}[fA]\\
+\tblget{my.a}\\
+\tblset{a}{tRuE!!}
+\tblget{a}\\
+\tblget{my.x}\\
+\tblif{n}{tr}[fa]\\
+\tblifv{n}{TR}[FA]\\
+\tblif{my.y}{Tr}[Fa]\\
+\tblifv{y}{tR}[fA]\\
 %% \kvtblundefcheck % would throw error
-\deftbl{my.first}{mydef} \mydef\\
-{\deftbl{last}{mydef} \mydef} \mydef\\
-{\gdeftbl{last}{mydef}} \mydef\\
+\tbldef{my.first}{mydef} \mydef\\
+{\tbldef{last}{mydef} \mydef} \mydef\\
+{\tblgdef{last}{mydef}} \mydef\\
 
+\tblset{my.a}{12 36}
+\tbldefxy{my.a}{coord} (\coordx,\coordy)
+
 \tblfrcsv{me}{a,b,"c,see",d,e}
-\gettbl{me/1},\gettbl{2}\\
-\gettbl{3}\\
-\settbl{me/4}{D}\gettbl{me/4}\\
-\settbl{5}{E}\gettbl{5}\\
-\gettbl{-2},\gettbl{me/-1}\\
-%% \gettbl{k} % would throw error
+\tblget{me/1},\tblget{2}\\
+\tblget{3}\\
+\tblset{me/4}{D}\tblget{me/4}\\
+\tblset{5}{E}\tblget{5}\\
+\tblget{-2},\tblget{me/-1}\\
+%% \tblget{k} % would throw error
 \end{LTXexample}
 
 
+\tblfrcsv{me}{
+Hello=world,
 
 
+Bonjour=terre,
+}
+\tblget{Hello}
+\tblget{Bonjour}
 
 
+Note: for thisf versions: all latex tbl commands are now prefixed with \cmd{tbl}, eg., \cmd{tblget}, \cmd{tblset}.
+Old-style commands eg. \cmd{gettbl} will be kept as aliases for a few more releases then removed.
+
+
 \subsection*{Splitting strings}
 Splitting text (or a cmd) into oxford comma format via:
-\cmd{\splitToComma[expansion level]{text}{text to split on}}:
+\cmd{\splittocomma[expansion level]{text}{text to split on}}:
 
 \begin{LTXexample}[width=0.3\linewidth]
--\splitToComma{  j doe  }{\and}-\\
--\splitToComma{  j doe \and s else  }{\and}-\\
--\splitToComma{  j doe \and s else \and a per }{\and}-\\
--\splitToComma{  j doe \and s else \and a per \and f guy}{\and}-
+-\splittocomma{  j doe  }{\and}-\\
+-\splittocomma{  j doe \and s else  }{\and}-\\
+-\splittocomma{  j doe \and s else \and a per }{\and}-\\
+-\splittocomma{  j doe \and s else \and a per \and f guy}{\and}-
 
 \def\authors{j doe \and s else \and a per \and f guy}
-\splitToComma[o]{\authors}{\and}
+\splittocomma[o]{\authors}{\and}
 \end{LTXexample}
 
 The expansion level is up to two characters, \cmd{n|o|t|f}, to control the expansion of each argument.
 
-You can do a similar string split but to \cmd{\item} instead of commas with \cmd{\splitToItems}
+You can do a similar string split but to \cmd{\item} instead of commas with \cmd{\splittoitems}
 \begin{LTXexample}
 \begin{itemize}
-  \splitToItems{kale\and john}{\and}
-  \splitToItems{kale -john -someone else}{-}
-  \splitToItems{1,2,3,4}{,}
+  \splittoitems{kale\and john}{\and}
+  \splittoitems{kale -john -someone else}{-}
+  \splittoitems{1,2,3,4}{,}
 \end{itemize}
 \end{LTXexample}
 

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2023-11-26 21:05:03 UTC (rev 68972)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2023-11-26 21:05:12 UTC (rev 68973)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2023-09-04
+--% 2023-11-25
 --% Copyright (C) 2021-2023 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -449,6 +449,10 @@
     return str:sub(2,-2)
 end
 
+function str_mt.__index.subpar(s, r)
+    r = r or ' '
+    return (s:gsub('\\par', r))
+end
 
 
 -- -- -- -- function stuff
@@ -802,6 +806,7 @@
     return tbl, key
 end
 
+
 function penlight.get_tbl_item(s, p) -- get item with string, p means print value
   p = p or false
   local tbl, key = penlight.get_tbl_index(s)
@@ -840,6 +845,18 @@
 end
 
 
+penlight.tbl_xysep = '%s+' -- spaces separate x-y coords
+function penlight.def_tbl_coords(str, def)
+    -- todo could definitely make this flexible for a table...
+    local x, y = str:strip():splitv(penlight.tbl_xysep)
+     --if (~penlight.hasval(x)) or (~penlight.hasval(y))  then
+     --  penlight.tex.pkgerror('penlightplus', 'def_tbl_coords function could not parse coordiantes given as "'..str..'" ensure two numbers separated by space are given!', '', true)
+     --end
+    token.set_macro(def..'x', tostring(x))
+    token.set_macro(def..'y', tostring(y))
+end
+
+
 if penlight.hasval(__PL_GLOBALS__) then
     -- iterators
     kpairs = penlight.utils.kpairs

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2023-11-26 21:05:03 UTC (rev 68972)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2023-11-26 21:05:12 UTC (rev 68973)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-09-04
+% 2023-11-25
 % Copyright (C) 2021-2023 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,7 +22,7 @@
 % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
 % OR OTHER DEALINGS IN THE SOFTWARE.
 
-\ProvidesPackage{penlightplus}[2023-09-04]
+\ProvidesPackage{penlightplus}[2023-11-25]
 
 \RequirePackage{luacode}
 \RequirePackage{luakeys}
@@ -62,12 +62,12 @@
   \luadirect{penlight.tex.aliasluastring(\luastring{#2},\luastring{#1})}%
 }
 
-\NewDocumentCommand{\splitToComma}{ O{nn} m m }{%
+\NewDocumentCommand{\splittocomma}{ O{nn} m m }{%
   \MakeluastringCommands[nn]{#1}%
   \luadirect{penlight.tex.split2comma(\plluastringA{#2},\plluastringB{#3})}%
 }
 
-\NewDocumentCommand{\splitToItems}{ O{NN} m m }{%
+\NewDocumentCommand{\splittoitems}{ O{NN} m m }{%
   \MakeluastringCommands[nn]{#1}%
   \luadirect{penlight.tex.split2items(\plluastringA{#2},\plluastringB{#3})}%
 }
@@ -103,45 +103,67 @@
 
 
 
-%%%
+%%% tbls below
 
-\NewDocumentCommand{\newtbl}{m}{\luadirect{
+\NewDocumentCommand{\tblnew}{m}{\luadirect{% initialize a tbl
   penlight.tbls[\luastring{#1}] = {}
   penlight.rec_tbl = \luastring{#1}
 }}
 
-\NewDocumentCommand{\tblfrkv}{m m O{}}{ \luadirect{
+\NewDocumentCommand{\tblfrkv}{m +m O{}}{\luadirect{%
   penlight.rec_tbl_opts = penlight.luakeys.parse(\luastring{#3})
-  penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(\luastring{#2}, penlight.rec_tbl_opts)
+  penlight.wrth(\luastring{#2}, '??')
+  penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(string.subpar(\luastring{#2}), penlight.rec_tbl_opts)
   penlight.rec_tbl = \luastring{#1}
 }}
 
-\NewDocumentCommand{\tblfrcsv}{m m O{}}{\tblfrkv{#1}{#2}[naked_as_value=true,#3]}
+\NewDocumentCommand{\tblfrkvN}{m +m O{}}{\luadirect{%
+  penlight.rec_tbl_opts = penlight.luakeys.parse(\luastring{#3})
+  penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(string.subpar(\luastringN{#2}), penlight.rec_tbl_opts)
+  penlight.rec_tbl = \luastring{#1}
+}}
 
+\NewDocumentCommand{\tblfrcsv}{m +m O{}}{\tblfrkv{#1}{#2}[naked_as_value=true,#3]}
 
-\NewDocumentCommand{\kvtblundefcheck}{}{\luadirect{penlight.check_recent_tbl_undefault()}} % todo
 
-\NewDocumentCommand{\chgtbl}{ m }{ \luadirect{
+\NewDocumentCommand{\tblkvundefcheck}{}{\luadirect{penlight.check_recent_tbl_undefault()}}% check defaults list and throw error if foreign keys were used
+
+\NewDocumentCommand{\tblchg}{ m }{\luadirect{% change recent table
   penlight.rec_tbl = \luastring{#1}
 }}
 
-\NewDocumentCommand{\gettbl}{m}{\luadirect{
+
+\NewDocumentCommand{\tblget}{m}{\luadirect{% get an item
   penlight.get_tbl_item(\luastring{#1}, true)
 }}
 
-\NewDocumentCommand{\settbl}{m m}{\luadirect{
+\NewDocumentCommand{\tblset}{m m}{\luadirect{% set item with {value}
   penlight.set_tbl_item(\luastring{#1}, \luastring{#2})
 }}
 
-\NewDocumentCommand{\deftbl}{ m m }{\luadirect{% define a table, use * to make definition
+\NewDocumentCommand{\tbldef}{ m m }{\luadirect{% define a table, use * to make definition
   token.set_macro(\luastring{#2}, tostring(penlight.get_tbl_item(\luastring{#1})))
 }}
 
-\NewDocumentCommand{\gdeftbl}{ m m }{\luadirect{% define a table, use * to make global definition
+\NewDocumentCommand{\tblgdef}{ m m }{\luadirect{% define a table, use * to make global definition
   token.set_macro(\luastring{#2}, tostring(penlight.get_tbl_item(\luastring{#1})), 'global')
 }}
 
-\NewDocumentCommand{\iftbl}{m m O{}}{\ifluax{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]}
+\NewDocumentCommand{\tbldefxy}{ m m }{\luadirect{penlight.def_tbl_coords(penlight.get_tbl_item(\luastring{#1}), \luastring{#2})}}% define #2x and #2y from a space delimited x-y pair
 
-\NewDocumentCommand{\iftblv}{m m O{}}{\ifluaxv{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]}
 
+\NewDocumentCommand{\tblif}{m m O{}}{\ifluax{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]}
+
+\NewDocumentCommand{\tblifv}{m m O{}}{\ifluaxv{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]}
+
+
+% legacy code, delete this
+\let\kvtblundefcheck\tblkvundefcheck
+\let\chgtbl\tblchg
+\let\newtbl\tblnew
+\let\gettbl\tblget
+\let\settbl\tblset
+\let\deftbl\tbldef
+\let\gdeftbl\tblgdef
+\let\iftbl\tblif
+\let\iftblv\tblifv
\ No newline at end of file



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