texlive[69070] Master/texmf-dist: penlightplus (8dec23)

commits+karl at tug.org commits+karl at tug.org
Fri Dec 8 22:37:37 CET 2023


Revision: 69070
          https://tug.org/svn/texlive?view=revision&revision=69070
Author:   karl
Date:     2023-12-08 22:37:37 +0100 (Fri, 08 Dec 2023)
Log Message:
-----------
penlightplus (8dec23)

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-12-08 21:37:27 UTC (rev 69069)
+++ trunk/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex	2023-12-08 21:37:37 UTC (rev 69070)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-11-25
+% 2023-12-08
 % Copyright (C) 2021-2023 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -104,8 +104,26 @@
 \llcmd{pl.hasval(x)} Python-like boolean testing\\
 \llcmd{COMP'xyz'()} Python-like comprehensions:\\\url{https://lunarmodules.github.io/Penlight/libraries/pl.comprehension.html}\\
 \llcmd{math.mod(n,d)}, \cmd{math.mod2(n)} math modulous\\
+\\
+
+\llcmd{string.}\cmd{upfirst(s)} uppercase first letter\\
+\llcmd{string.}\cmd{delspace(s)} delete all spaces\\
+\llcmd{string.}\cmd{trimfl(s)}remove first and last chars\\
+\llcmd{string.}\cmd{appif(s, append, bool, alternate)}\\
+\llcmd{string.}\cmd{gfirst(s, t)}return first matched patter from an array of patterns t\\
+%\llcmd{string.}\cmd{gnum(s)} extract a number from a string\\
+\llcmd{string.}\cmd{gextract(s)} extract a pattern from a string (returns capture and new string with capture removed)\\
 \llcmd{string.}\cmd{totable(s)} string a table of characters\\
+\llcmd{string.}\cmd{tolist(s)} string a table of characters\\
+\llcmd{string.}\cmd{containsany(s,t)} checks if any of the array of strings \cmd{t} are in \cmd{s} using \cmd{string.find}\\
+\llcmd{string.}\cmd{containsanycase(s,t)} case-insensitive version\\
 \llcmd{string.}\cmd{delspace(s)} clear spaces from string\\
+\llcmd{string.}\cmd{subpar(s, c)} replaces \cmd{\\par} with a character of your choice default is space\\
+\llcmd{string.}\cmd{fmt(s, t, fmt)} format a string like \cmd{format_operator}, but with
+a few improvements. \cmd{t} can be an array (reference items like \cmd{\$1} in the string),
+and \cmd{fmt} can be a table of formats (keys correspond to those in \cmd{t}), or a string that
+is processed by luakeys.\\
+
 \llcmd{pl.}\cmd{char(n)} return letter corresponding to 1=a, 2=b, etc.\\
 \llcmd{pl.}\cmd{Char(n)} return letter corresponding to 1=A, 2=B, etc.\\
 
@@ -122,7 +140,7 @@
 \llcmd{prt(x),prtn(x)} print without or with a newline at end. Tries to help with special characters or numbers printing.\\
 \llcmd{prtl(l),prtt(t)} print a literal string, or table\\
 \llcmd{wrt(x), wrtn(x)} write to log\\
-\llcmd{help_wrt}\cmd{(s1, s2)} pretty-print something to console. S2 is a flag to help you find., alias is \cmd{wrth}\\
+\llcmd{wrh}\cmd{(s1, s2)} pretty-print something to console. S2 is a flag to help you find., alias is \cmd{help_wrt}, also in \cmd{pl.wrth}\\
 \llcmd{prt_array2d(tt)} pretty print a 2d array\\
 \\
 \llcmd{pkgwarn}\cmd{(pkg, msg1, msg2)} throw a package warning\\
@@ -142,9 +160,11 @@
 
 \subsubsection*{global extras}
 If the package option \cmd{globals} is used, many additional globals are set for easier scripting.
-All \cmd{pl.tex} functions, and variables, \cmd{pl.hasval},  \cmd{pl.COMP}, \cmd{pl.utils.kpairs}, \cmd{pl.utils.npairs} become globals.
-\cmd{pl.tablex} is aliased as \cmd{TX} (which also includes all native Lua table functions), and
-\cmd{pl.array2d} is aliased as \cmd{A2d}.
+\cmd{pl.hasval},  \cmd{pl.COMP}, \cmd{pl.utils.kpairs}, \cmd{pl.utils.npairs} become globals.
+\cmd{pl.tablex} is aliased as \cmd{pl.tbx and tbx} (which also includes all native Lua table functions), and
+\cmd{pl.array2d} is aliased as \cmd{pl.a2d and a2d}.
+
+If you want global \cmd{pl.tex} funcs and vars, call \cmd{pl.make_tex_global()}
 \\
 
 
@@ -198,6 +218,7 @@
 \cmd{penlightplus} provides a Lua-table interface. Tables are stored in the
 \cmd{penlight.tbls} table.
 
+%%%
 
 \cmd{\tblnew{t}} declares a new table with name \cmd{t}\\
 \cmd{\tblchg{t}} changes the 'recent' table\\
@@ -206,7 +227,8 @@
  \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{\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{\tbldef{i}{d}} pushes the value to macro \cmd{d}\\
+\cmd{\tbldefall{t}{d}} define all item in table \cmd{t} (use recent if blank) with format \cmd{d<key>}, if \cmd{d} is blank, commands are defined as \cmd{tbl<t><k>} \\
 \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}\\
@@ -232,9 +254,13 @@
 \tblifv{y}{tR}[fA]\\
 %% \kvtblundefcheck % would throw error
 \tbldef{my.first}{mydef} \mydef\\
+\tbldef{first}{}\dtblmyfirst\\
 {\tbldef{last}{mydef} \mydef} \mydef\\
 {\tblgdef{last}{mydef}} \mydef\\
 
+\tbldefall{}{}\dtblmyfirst\\
+\tbldefall{my}{DEF}\DEFfirst
+
 \tblset{my.a}{12 36}
 \tbldefxy{my.a}{coord} (\coordx,\coordy)
 
@@ -248,17 +274,16 @@
 \end{LTXexample}
 
 
-\tblfrcsv{me}{
-Hello=world,
+%\tblfrcsv{me}{
+%Hello=world,
+%
+%Bonjour=terre,
+%}
+%\tblget{Hello}
+%\tblget{Bonjour}
 
 
-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}.
+Note: for this 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.
 
 
@@ -312,5 +337,25 @@
 %  }
 %
 %  \THINg[color=blue,size=tiny]{Kale}
-  
+%
+%\begin{luacode*}
+%penlight.wrth(('$1'):fmt(5.5,'.8f','XYZ'))
+%function prttol()
+%  penlight.tbls.tol[3] =  penlight.tbls.tol[3] or 3
+%  penlight.tbls.tol[4] =  penlight.tbls.tol[1]*(1.0-penlight.tbls.tol[3]/100.0) + 0.0
+%  penlight.tbls.tol[5] =  penlight.tbls.tol[1]*(1.0+penlight.tbls.tol[3]/100.0) + 0.0
+%  penlight.tbls.tol['k'] = 'fuckboi'
+%  penlight.wrth(('$k $1\\$2 (\\pmpct{$3} tolerance, $4\\ndash$5\\$2)'):fmt(penlight.tbls.tol, '4=.1f, 5=.1f'), 'XYZ')
+%end
+%\end{luacode*}
+%\NewDocumentCommand{\prttol}{ m }{%  {50.0,kV,3}   % 50\us (\pmpct{20} tolerance, 40=--60\us)
+%\tblfrcsv{tol}{#1}\luadirect{prttol()}}
+%
+%\prttol{50,kV,3.21}
+%
+%\begin{luacode*}
+%--pl.wrth(('2.23'):gnum())
+%\end{luacode*}
+
+
 \end{document}
\ No newline at end of file

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2023-12-08 21:37:27 UTC (rev 69069)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2023-12-08 21:37:37 UTC (rev 69070)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2023-11-25
+--% 2023-12-08
 --% Copyright (C) 2021-2023 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -7,7 +7,7 @@
 --% in the Software without restriction, including without limitation the rights
 --% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 --% copies of the Software, and to permit persons to whom the Software is
---% furnished to do so, subject to the following conditions:
+--% furnished to do so, subjdeect to the following conditions:
 --%
 --% The above copyright notice and this permission notice shall be included in
 --% all copies or substantial portions of the Software.
@@ -24,6 +24,7 @@
 
 
 
+-- https://lunarmodules.github.io/Penlight/
 
 __PL_PLUS__ = true
 __PL_SKIP_TEX__ = __PL_SKIP_TEX__ or false --if declared true before here, it will use regular print functions
@@ -34,7 +35,6 @@
 
 penlight.luakeys = require'luakeys'()
 
-
 penlight.COMP = require'pl.comprehension'.new() -- for comprehensions
 
 -- http://lua-users.org/wiki/SplitJoin -- todo read me!!
@@ -63,14 +63,16 @@
 -- Some simple and helpful LaTeX functions -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
 -- xparse defaults
-penlight.tex._xTrue = '\\BooleanTrue '
-penlight.tex._xFalse = '\\BooleanFalse '
-penlight.tex._xNoValue = '-NoValue-'
 
 penlight.tex.xTrue = '\\BooleanTrue '
 penlight.tex.xFalse = '\\BooleanFalse '
 penlight.tex.xNoValue = '-NoValue-'
 
+penlight.tex._xTrue = '\\BooleanTrue '
+penlight.tex._xFalse = '\\BooleanFalse '
+penlight.tex._xNoValue = '-NoValue-'
+
+
 --Generic LuaLaTeX utilities for print commands or environments
 
 if not __PL_SKIP_TEX__ then
@@ -130,7 +132,7 @@
     end
 end
 
-function penlight.tex.help_wrt(s1, s2) -- helpful printing, makes it easy to debug, s1 is object, s2 is note
+function penlight.tex.wrth(s1, s2) -- helpful printing, makes it easy to debug, s1 is object, s2 is note
     local wrt2 = wrt or texio.write_nl or print
     s2 = s2 or ''
     wrt2('\nvvvvv '..s2..'\n')
@@ -141,9 +143,8 @@
     end
     wrt2('\n^^^^^\n')
 end
-penlight.help_wrt = penlight.tex.help_wrt
+penlight.help_wrt = penlight.tex.wrth
 penlight.wrth = penlight.help_wrt
-penlight.tex.wrth = penlight.help_wrt
 
 function penlight.tex.prt_array2d(t)
     for _, r in ipairs(t) do
@@ -455,6 +456,23 @@
 end
 
 
+function str_mt.__index.fmt(s, t, fmt) -- format a $1 string with an array or table and formats
+    -- formats can be a luakeys string, or a table
+    fmt = fmt or {}
+    if type(fmt) == 'string' then
+        fmt = penlight.tablex.strinds(penlight.luakeys.parse(fmt, {naked_as_value=true}))
+    end
+    if type(t) ~= 'table' then t = {t} end
+    t = penlight.tablex.strinds(t)
+    for k, f in pairs(fmt)  do -- apply formats
+        t[k] = string.format('%'..f, t[tostring(k)])
+    end
+    return s % t
+end
+
+
+
+
 -- -- -- -- function stuff
 
 function penlight.clone_function(fn)
@@ -501,7 +519,19 @@
 
 -- table stuff below
 
+function penlight.tablex.strinds(t) -- convert indices that are numbers to string indices
+    local t_new = {}
+    for i, v in pairs(t) do -- ensure all indexes are strings
+      if type(i) == 'number' then
+          t_new[tostring(i)] = v
+      else
+          t_new[i] = v
+      end
+    end
+  return t_new
+end
 
+
 function penlight.tablex.map_slice(func, T, j1, j2)
     if type(j1) == 'string' then
         return penlight.array2d.map_slice(func, {T}, ','..j1)[1]
@@ -783,6 +813,13 @@
 penlight.rec_tbl = ''
 penlight.rec_tbl_opts = {}
 
+function penlight.get_tbl_name(s)
+    if s == '' then
+        return penlight.rec_tbl
+    end
+    return s
+end
+
 function penlight.get_tbl_index(s)
     local tbl = ''
     local key = ''
@@ -844,25 +881,53 @@
     end
 end
 
-
-penlight.tbl_xysep = '%s+' -- spaces separate x-y coords
+-- TODO TODO TODO get error working xy def, and referene which table for key-vals
+penlight.tbl_xysep = '%s+' -- spaces separate x-y coordinates
 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
+     if (not penlight.hasval(x)) or (not 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
 
 
+--
+
+function penlight.make_tex_global()
+    for k,v in pairs(penlight.tex) do  -- make tex functions global
+            _G[k] = v
+        end
+end
+
+
+penlight.kpairs = penlight.utils.kpairs
+penlight.npairs = penlight.utils.npairs
+penlight.writefile = penlight.utils.writefile
+penlight.readfile = penlight.utils.readfile
+penlight.readlines = penlight.utils.readfile
+penlight.filterfiles = penlight.utils.filterfiles
+
+-- adopt table functions in tablex
+penlight.tablex.concat = table.concat
+penlight.tablex.insert = table.insert
+penlight.tablex.maxn = table.maxn
+penlight.tablex.remove = table.remove
+penlight.tablex.sort = table.sort
+
+penlight.tbx = penlight.tablex
+penlight.a2d = penlight.array2d
+
 if penlight.hasval(__PL_GLOBALS__) then
     -- iterators
     kpairs = penlight.utils.kpairs
     npairs = penlight.utils.npairs
-    --enum = utils.enum
 
+    hasval = penlight.hasval
+    COMP = penlight.COMP
+
     for k,v in pairs(penlight.tablex) do  -- extend the table table to contain tablex functions
         if k == 'sort' then
             table.sortk = v
@@ -873,38 +938,15 @@
         end
     end
     table.join = table.concat -- alias
-    -- todo should tablex have all table functions
 
-    penlight.tablex.concat = table.concat
-    penlight.tablex.insert = table.insert
-    penlight.tablex.maxn = table.maxn
-    penlight.tablex.remove = table.remove
-    penlight.tablex.sort = table.sort
-
-    hasval = penlight.hasval
-    COMP = penlight.COMP
-
-    -- shortcuts
--- http://stevedonovan.github.io/Penlight/api/libraries/penlight.utils.html
-    penlight.writefile = penlight.utils.writefile
-    penlight.readfile = penlight.utils.readfile
-    penlight.readlines = penlight.utils.readfile
-    penlight.filterfiles = penlight.utils.filterfiles
-
-    penlight.a2 = penlight.array2d
-    A2d = penlight.array2d
-    penlight.tbl = penlight.tablex
-    TX = penlight.tablex
-
-    for k,v in pairs(penlight.tex) do  -- make tex functions global
-        _G[k] = v
-    end
-
+	a2d = penlight.array2d
+    tbx = penlight.tablex
 end
 
 
 
 
+-- graveyard
 
     --_xTrue = penlight.tex._xTrue
     --_xFalse = penlight.tex._xFalse

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2023-12-08 21:37:27 UTC (rev 69069)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2023-12-08 21:37:37 UTC (rev 69070)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-11-25
+% 2023-12-08
 % 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-11-25]
+\ProvidesPackage{penlightplus}[2023-12-08]
 
 \RequirePackage{luacode}
 \RequirePackage{luakeys}
@@ -105,7 +105,7 @@
 
 %%% tbls below
 
-\NewDocumentCommand{\tblnew}{m}{\luadirect{% initialize a tbl
+\NewDocumentCommand{\tblnew}{m}{\luadirect{% initialize a tbl and set blank
   penlight.tbls[\luastring{#1}] = {}
   penlight.rec_tbl = \luastring{#1}
 }}
@@ -112,7 +112,6 @@
 
 \NewDocumentCommand{\tblfrkv}{m +m O{}}{\luadirect{%
   penlight.rec_tbl_opts = penlight.luakeys.parse(\luastring{#3})
-  penlight.wrth(\luastring{#2}, '??')
   penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(string.subpar(\luastring{#2}), penlight.rec_tbl_opts)
   penlight.rec_tbl = \luastring{#1}
 }}
@@ -141,10 +140,25 @@
   penlight.set_tbl_item(\luastring{#1}, \luastring{#2})
 }}
 
-\NewDocumentCommand{\tbldef}{ m m }{\luadirect{% define a table, use * to make definition
-  token.set_macro(\luastring{#2}, tostring(penlight.get_tbl_item(\luastring{#1})))
+% todo if no definition is provided, assume <tblname><key>
+\NewDocumentCommand{\tbldef}{ m m }{\luadirect{% define a {table key}{def}
+  local _tbl, _key = penlight.get_tbl_index(\luastring{#1})
+  local _tbl_def_ = \luastring{#2}
+  if _tbl_def_ == '' then _tbl_def_ = 'dtbl'.._tbl.._key end
+  token.set_macro(_tbl_def_, tostring(penlight.tbls[_tbl][_key]))
 }}
 
+\NewDocumentCommand{\tbldefall}{ m m }{\luadirect{% define all {table} keys to {table} \table<key1>
+   % todo maybe change tbldef {def} to [def] and make same as table name
+    local _tbl = penlight.get_tbl_name(\luastring{#1})
+    local _tbl_def_ = \luastring{#2}
+     if _tbl_def_ == '' then _tbl_def_ = 'dtbl'.._tbl end
+   for k, v in pairs(penlight.tbls[_tbl]) do
+    token.set_macro(_tbl_def_..k, tostring(v))
+  end
+}}
+
+
 \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')
 }}



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