texlive[68185] Master/texmf-dist: penlightplus (5sep23)

commits+karl at tug.org commits+karl at tug.org
Tue Sep 5 22:06:27 CEST 2023


Revision: 68185
          http://tug.org/svn/texlive?view=revision&revision=68185
Author:   karl
Date:     2023-09-05 22:06:27 +0200 (Tue, 05 Sep 2023)
Log Message:
-----------
penlightplus (5sep23)

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-09-05 20:06:19 UTC (rev 68184)
+++ trunk/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex	2023-09-05 20:06:27 UTC (rev 68185)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-08-27
+% 2023-09-04
 % Copyright (C) 2021-2023 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -58,6 +58,8 @@
 \title{penlightplus}
 \subtitle{Additions to the Penlight Lua Libraries}
 
+
+
 \begin{document}
 %
 
@@ -72,19 +74,21 @@
 (no document is made, but useful for testing your Lua code),
 you can access it by setting \cmd{__SKIP_TEX__ = true} before loading. For example:
  \begin{verbatim}
-package.path = package.path .. ';'..'path/to/texmf/tex/latex/penlightplus/?.lua'
-package.path = package.path .. ';'..'path/to/texmf/tex/latex/penlight/?.lua'
+package.path = package.path .. ';'..'path/to/texmf/tex/lualatex/penlightplus/?.lua'
+package.path = package.path .. ';'..'path/to/texmf/tex/lualatex/penlight/?.lua'
 penlight = require'penlight'
 
 __SKIP_TEX__ = true  --only required if you want to use
                      --penlightplus without a LaTeX run
 __PL_GLOBALS__ = true -- optional, include global definitions
+
 require'penlightplus'
-\end{verbatim}
 
+ \end{verbatim}
 
 
 
+
 The following global Lua variables are defined:
 
 \cmd{__SKIP_TEX__} If using the \cmd{penlightplus} package with \cmd{texlua} (good for troubleshooting), set this global before loading \cmd{penlight}\\
@@ -182,7 +186,7 @@
 
 \cmd{\ifluax{<Lua expr>}{<do if true>}[<do if false>]} and\\ \cmd{\ifluax{<Lua expr>}{<do if true>}[<do if false>]} for truthy (uses \cmd{penlight.hasval})
 
-\begin{LTXexample}
+\begin{LTXexample}[width=0.3\linewidth]
 \ifluax{3^3 == 27}{3*3*3 is 27}[WRONG]\\
 \ifluax{abc123 == nil}{Var is nil}[WRONG]\\
 \ifluax{not true}{tRuE}[fAlSe]\\
@@ -197,38 +201,55 @@
 
 \cmd{\newtbl{t}} declares a new table with name \cmd{t}\\
 \cmd{\chgtbl{t}} changes the 'recent' table\\
-\cmd{\tblfrkv{t}{key-val string}[luakeys opts]} new table from key-vals, used \cmd{luakeys} \\
+\cmd{\tblfrkv{t}{key-val string}[luakeys opts]} new table from key-vals using \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{\iftbl{i}{t}[f]} runs code \cmd{t} if the item is true else \cmd{f}\\
-\cmd{\iftblv{i}{t}[f]} runs code \cmd{t} if the item is truthy else \cmd{f}\\
+\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
+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).
 \cmd{t.key} where \cmd{t} is the table name and \cmd{key} is a string key,
-\cmd{t/int} where \cmd{int} is a numeric indexer (ie uses \cmd{t[int]}),
-or simply \cmd{ind} without the table name, where the assumed table is the last one that was created or changed to, (pure-numbers are not treated as strings in this case).
+\cmd{t/int} where \cmd{int} is an integer index (ie. uses \cmd{t[int]}, note that negative indexes are allowered where -1 is the last element),
+or simply use \cmd{ind} without the table name, where the assumed table is the last one that was created or changed to, (passing a number will used as an integer index).
+\enlargethispage{2em}
+\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]\\
+%% \kvtblundefcheck % would throw error
+\deftbl{my.first}{mydef} \mydef\\
+{\deftbl{last}{mydef} \mydef} \mydef\\
+{\gdeftbl{last}{mydef}} \mydef\\
 
-\begin{LTXexample}
-\tblfrkv{my}{a,b,c,first=john,last=smith}[defaults={x=0,1=one,n=false,y=yes}, naked_as_value=true]
-
-\settbl{my/4}{d}\gettbl{my/4}\\
-\settbl{5}{e}\gettbl{5}\\
-\gettbl{my.x}\\
-\iftbl{n}{t}[f]\\
-\iftblv{n}{t}[f]\\
-\iftbl{my.y}{t}[f]\\
-\iftblv{y}{t}[f]\\
+\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
 \end{LTXexample}
 
 
 
+
+
+
 \subsection*{Splitting strings}
 Splitting text (or a cmd) into oxford comma format via:
 \cmd{\splitToComma[expansion level]{text}{text to split on}}:
 
-\begin{LTXexample}
+\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}-\\

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2023-09-05 20:06:19 UTC (rev 68184)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2023-09-05 20:06:27 UTC (rev 68185)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2023-08-27
+--% 2023-09-04
 --% Copyright (C) 2021-2023 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -776,22 +776,36 @@
 
 penlight.tbls = {}
 
+penlight.rec_tbl = ''
+penlight.rec_tbl_opts = {}
+
+function penlight.get_tbl_index(s)
+    local tbl = ''
+    local key = ''
+    if s:find('%.') then
+        local tt = s:split('.')
+        tbl = tt[1]
+        key = tt[2]
+    elseif s:find('/') then
+        local tt = s:split('/')
+        tbl = tt[1]
+        key = tonumber(tonumber(tt[2]))
+        if key < 0 then key = #penlight.tbls[tbl]+1+key end
+    else
+        tbl = penlight.rec_tbl
+        key = tonumber(s) or s
+        if type(key) == 'number' and key < 0 then key = #penlight.tbls[tbl]+1+key end
+    end
+    if penlight.tbls[tbl] == nil or penlight.tbls[tbl][key] == nil then
+        penlight.tex.pkgerror('penlightplus',  'Invalid index of tbl using: "'..s..'"')
+    end
+    return tbl, key
+end
+
 function penlight.get_tbl_item(s, p) -- get item with string, p means print value
   p = p or false
-  local itm = 'tbl: INVALID INDEX WITH: "'..s..'"'
-  if s:find('%.') then
-    local tt = s:split('.')
-    itm = penlight.tbls[tt[1]][tt[2]]
-  elseif s:find('/') then
-    local tt = s:split('/')
-    itm = penlight.tbls[tt[1]][tonumber(tonumber(tt[2]))]
-  else
-    if s:isdigit() then
-      itm = penlight.tbls._recent[tonumber(s)]
-    else
-      itm = penlight.tbls._recent[s]
-    end
-  end
+  local tbl, key = penlight.get_tbl_index(s)
+  local itm = penlight.tbls[tbl][key]
   if p then
     tex.sprint(tostring(itm))
   end
@@ -800,22 +814,32 @@
 
 
 function penlight.set_tbl_item(s, v)
-  if s:find('%.') then
-    local tt = s:split('.')
-    penlight.tbls[tt[1]][tt[2]] = v
-  elseif s:find('/') then
-    local tt = s:split('/')
-    penlight.tbls[tt[1]][tonumber(tonumber(tt[2]))] = v
-  else
-    if s:isdigit() then
-      penlight.tbls._recent[tonumber(s)] = v
-    else
-      penlight.tbls._recent[s] = v
-   end
-  end
-  end
+  tbl, key = penlight.get_tbl_index(s)
+  penlight.tbls[tbl][key] = v
+end
 
+function penlight.check_recent_tbl_undefault()
+    local undefaults = {}
+    if penlight.rec_tbl_opts ~= nil then
+        local defaults = penlight.tablex.union(
+                penlight.rec_tbl_opts.defs or {},
+                penlight.rec_tbl_opts.defaults or {}
+        )
+        for k, v in pairs(penlight.tbls[penlight.rec_tbl]) do
+            if defaults[k] == nil then
+                undefaults[#undefaults+1] = k
+            end
+        end
+        if penlight.hasval(undefaults) then
+            penlight.tex.pkgerror('penlightplus',
+                    'Invalid keys passed to tbl keyval:  ' .. (', '):join(undefaults) ..
+                    ' ;   choices are:  ' .. (', '):join(penlight.tablex.keys(defaults))
+            )
+        end
+    end
+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-09-05 20:06:19 UTC (rev 68184)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2023-09-05 20:06:27 UTC (rev 68185)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-08-27
+% 2023-09-04
 % 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-08-27]
+\ProvidesPackage{penlightplus}[2023-09-04]
 
 \RequirePackage{luacode}
 \RequirePackage{luakeys}
@@ -102,25 +102,27 @@
 \NewDocumentCommand{\ifluaxv}{m m O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]}
 
 
-%   testing ifluax
-%  {-->\ifluax{1 == 2}{\LARGE TRUE}[\tiny FALSE]<--test\\
-%  -->\ifluax{abc == nil}{\LARGE TRUE}[\tiny FALSE]<--test}
 
-
 %%%
 
 \NewDocumentCommand{\newtbl}{m}{\luadirect{
   penlight.tbls[\luastring{#1}] = {}
-  penlight.tbls._recent = penlight.tbls[\luastring{#1}]
+  penlight.rec_tbl = \luastring{#1}
 }}
 
 \NewDocumentCommand{\tblfrkv}{m m O{}}{ \luadirect{
-  penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(\luastring{#2}, penlight.luakeys.parse(\luastring{#3}))
-  penlight.tbls._recent = penlight.tbls[\luastring{#1}]
+  penlight.rec_tbl_opts = penlight.luakeys.parse(\luastring{#3})
+  penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(\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{\kvtblundefcheck}{}{\luadirect{penlight.check_recent_tbl_undefault()}} % todo
+
 \NewDocumentCommand{\chgtbl}{ m }{ \luadirect{
-  penlight.tbls._recent = penlight.tbls[\luastring{#1}]
+  penlight.rec_tbl = \luastring{#1}
 }}
 
 \NewDocumentCommand{\gettbl}{m}{\luadirect{
@@ -143,38 +145,3 @@
 
 \NewDocumentCommand{\iftblv}{m m O{}}{\ifluaxv{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]}
 
-
-
-%\NewDocumentCommand{\tblupd}{ m m}{\luadirect{
-%  penlight.tablex.update(penlight.tbls[\luastring{#1}], penlight.tbls[\luastring{#2}])
-%}}
-%
-%\NewDocumentCommand{\tblupdkv}{ m m }{\luadirect{
-%  penlight.tablex.update(penlight.tbls[\luastring{#1}], penlight.luakeys.parse(\luastring{#2}))
-%}}
-
-%
-%% todo need a get table function. If blank is passed, the last table referenced is used.
-%\NewDocumentCommand{\tblfrkvII}{ m m m }{\luadirect{
-%  _G[\luastring{#1}] = penlight.tablex.update(penlight.luakeys.parse(\luastring{#2}), luakeys.parse(\luastring{#3}))
-%}}
-
-%\NewDocumentCommand{\tbldo}{m m O{} }{\luadirect{
-%  % tex.sprint(tostring(_G[\luastring{#1}][#2]))
-%  % todo allow one to use pl tablex function here,
-%  % {tbl}{update}[arg1][arg2]
-%  penlight.tablex[\luastring[#1]](_G[\luastring{}], _G[\luastring{}])
-%}}
-
-
-
-
-%%%%%%%%5
-
-%\begin{luacode*}
-%  function set_dim(name, len)
-%    tex.sprint('\\global\\let\\'..name..'\\relax') -- reset length
-%    tex.sprint('\\global\\newlength{\\'..name..'}') -- make new len
-%    tex.setglue(name, tex.sp(len))
-%  end
-%\end{luacode*}



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