texlive[72053] Master/texmf-dist: penlightplus (17aug24)

commits+karl at tug.org commits+karl at tug.org
Sat Aug 17 23:22:58 CEST 2024


Revision: 72053
          https://tug.org/svn/texlive?view=revision&revision=72053
Author:   karl
Date:     2024-08-17 23:22:58 +0200 (Sat, 17 Aug 2024)
Log Message:
-----------
penlightplus (17aug24)

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	2024-08-17 21:22:49 UTC (rev 72052)
+++ trunk/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex	2024-08-17 21:22:58 UTC (rev 72053)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2024-03-14
+% 2024-08-17
 % Copyright (C) 2021-2024 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -59,7 +59,6 @@
 \subtitle{Additions to the Penlight Lua Libraries}
 
 
-
 \begin{document}
 %
 
@@ -222,7 +221,7 @@
 %\luastringExpTest{ n o t f }{\NOTexp}
 
 
-\subsection*{Lua boolean expressions for LaTeX conditionals}
+\subsection*{Lua boolean expressions and a case-switch for conditionals}
 
 \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})
 
@@ -234,6 +233,17 @@
 \ifluaxv{''}{true}[false]\\
 \end{LTXexample}
 
+\cmd{\caseswitch{case}{kev-val choices}} The starred version will throw an error if the case is not found.
+Use \_\_ as a placeholder for a case that isn't matched.
+
+\begin{LTXexample}[width=0.3\linewidth]
+\def\caseswitchexample{\caseswitch{\mycase}{dog=DOG, cat=CAT, __=INVALID}}
+\def\mycase{dog} \caseswitchexample \\
+\def\mycase{human} \caseswitchexample
+\end{LTXexample}
+%\caseswitch*{\mycase}{dog=DOG, cat=CAT, __=INVALID}
+
+
 \subsection*{Creating and using Lua tables in LaTeX}
 \cmd{penlightplus} provides a Lua-table interface. Tables are stored in the
 \cmd{penlight.tbls} table.

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2024-08-17 21:22:49 UTC (rev 72052)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua	2024-08-17 21:22:58 UTC (rev 72053)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2024-03-14
+--% 2024-08-17
 --% Copyright (C) 2021-2024 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -857,7 +857,22 @@
 
 
 
+function penlight.caseswitch(s, c, kv)
+    local kvtbl = penlight.luakeys.parse(kv)
+    local sw = kvtbl[c] -- the returned switch
+    if sw == nil then -- if switch not found
+      if s == penlight.tex.xTrue then -- if star, throw error
+        pl.tex.pkgerror('penlight', 'case: "'..c..'" not found in key-vals: "'..kv..'"')
+        sw = ''
+      else
+        sw = kvtbl['__'] or '' -- use __ as not found case
+      end
+     end
+    tex.sprint(sw)
+end
 
+
+
 penlight.tbls = {}
 
 penlight.rec_tbl = ''

Modified: trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2024-08-17 21:22:49 UTC (rev 72052)
+++ trunk/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty	2024-08-17 21:22:58 UTC (rev 72053)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2024-03-14
+% 2024-08-17
 % Copyright (C) 2021-2024 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}[2024-03-14]
+\ProvidesPackage{penlightplus}[2024-08-17]
 
 \RequirePackage{luacode}
 \RequirePackage{luakeys}
@@ -97,6 +97,18 @@
 
 
 
+
+
+
+\NewDocumentCommand{\caseswitch}{s m +m}{\ignorespaces\luadirect{penlight.caseswitch(\luastring{#1},\luastring{#2},\luastringN{#3})}\unskip}
+% argument 1 is star option, which throws an error if case is not found
+% argument 2 is the case, fully expanded
+% argument 3 is a luakeys table of options, not expanded
+
+
+
+
+
 %%% tbls below
 
 \NewDocumentCommand{\tblnew}{m}{\luadirect{% initialize a tbl and set blank



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