texlive[61326] Master/texmf-dist: penlight (16dec21)

commits+karl at tug.org commits+karl at tug.org
Thu Dec 16 22:19:17 CET 2021


Revision: 61326
          http://tug.org/svn/texlive?view=revision&revision=61326
Author:   karl
Date:     2021-12-16 22:19:17 +0100 (Thu, 16 Dec 2021)
Log Message:
-----------
penlight (16dec21)

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

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

Modified: trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex	2021-12-16 21:19:00 UTC (rev 61325)
+++ trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex	2021-12-16 21:19:17 UTC (rev 61326)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2021-11-07
+% 2021-12-15
 % Copyright (C) 2021 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy

Modified: trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty	2021-12-16 21:19:00 UTC (rev 61325)
+++ trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty	2021-12-16 21:19:17 UTC (rev 61326)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2021-11-07
+% 2021-12-15
 % Copyright (C) 2021 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{penlight}[2021-11-07]
+\ProvidesPackage{penlight}[2021-12-15]
 
 \RequirePackage{luacode}
 

Modified: trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua	2021-12-16 21:19:00 UTC (rev 61325)
+++ trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua	2021-12-16 21:19:17 UTC (rev 61326)
@@ -20,7 +20,6 @@
     wrt('\n^^^^^\n')
 end
 
-
 function prt_array2d(t)
     for _, r in ipairs(t) do
         local s = ''
@@ -83,7 +82,7 @@
 -- -- -- --  functions below extend the array2d module
 
 
-local function map_slice1(func, L, i1, i2) -- map a function to a slice of an array, can use PlcExpr
+function pl.array2d.map_slice1(func, L, i1, i2) -- map a function to a slice of an array, can use PlcExpr
     i2 = i2 or i1
     local len = #L
     i1 = check_index(i1, len)
@@ -95,7 +94,7 @@
    return L
 end
 
-local function map_slice2(func, M, i1, j1, i2, j2) -- map a function to a slice of a Matrix
+function pl.array2d.map_slice2(func, M, i1, j1, i2, j2) -- map a function to a slice of a Matrix
     i1, j1, i2, j2 = check_slice(M, i1, j1, i2, j2)
     --for i,j in array2d.iter(M, true, i1, j1, i2, j2) do  --todo this did not work, penlight may have fixed this
     func = check_func(func)
@@ -107,12 +106,12 @@
    return M
 end
 
-local function map_columns(func, M, j1, j2) -- map function to columns of matrix
+function pl.array2d.map_columns(func, M, j1, j2) -- map function to columns of matrix
     j2 = j2 or j1
     return map_slice2(func, M, 1, j1, -1, j2)
 end
 
-local function map_rows(func, M, i1, i2) -- map function to rows of matrix
+function pl.array2d.map_rows(func, M, i1, i2) -- map function to rows of matrix
     i2 = i2 or i1
     return map_slice2(func, M, i1, 1, i2, -1)
 end
@@ -120,7 +119,7 @@
 
 -- -- -- -- -- -- -- --
 
-function sortOP(M, op, ele) -- sort a 2d array based on operator criteria, ele is column, ie sort on which element
+function pl.array2d.sortOP(M, op, ele) -- sort a 2d array based on operator criteria, ele is column, ie sort on which element
        M_new = {}
         for row in pl.seq.sort(M, comp_2ele_func(op, ele)) do
             M_new[#M_new+1] = row
@@ -128,13 +127,13 @@
         return M_new
 end
 
-local function like(M1, v)
+function pl.array2d.like(M1, v)
     v = v or 0
     r, c = pl.array2d.size(M1)
     return pl.array2d.new(r,c,v)
 end
 
-local function from_table(t) -- turns a labelled table to a 2d, label-free array
+function pl.array2d.from_table(t) -- turns a labelled table to a 2d, label-free array
     t_new = {}
     for k, v in pairs(t) do
         if type(v) == 'table' then
@@ -150,7 +149,7 @@
     return t_new
 end
 
-local function toTeX(M, EL) --puts & between columns, can choose to end line with \\ if EL is true (end-line)
+function pl.array2d.toTeX(M, EL) --puts & between columns, can choose to end line with \\ if EL is true (end-line)
     EL = EL or false
     if EL then EL = '\\\\' else EL = '' end
     return pl.array2d.reduce2(_1..EL.._2, _1..'&'.._2, M)..EL
@@ -158,15 +157,6 @@
 
 -- -- -- -- -- -- --
 
--- add to array2d module
-pl.array2d['map_columns'] = map_columns
-pl.array2d['map_rows'] = map_rows
-pl.array2d['map_slice2'] = map_slice2
-pl.array2d['map_slice1'] = map_slice1
-pl.array2d['from_table'] = from_table
-pl.array2d['toTeX'] = toTeX
-pl.array2d['sortOP'] = sortOP
-pl.array2d['like'] = like
 
 
 
@@ -173,16 +163,35 @@
 
 -- -- -- -- -- -- -- -- -- -- -- --  functions below extend the operator module
 
-local function strgt(a,b) return tostring(a) > tostring(b) end
-local function strlt(a,b) return tostring(a) < tostring(b) end
-pl.operator['strgt'] = strgt
-pl.operator['strlt'] = strlt
+function pl.operator.strgt(a,b) return tostring(a) > tostring(b) end
+function pl.operator.strlt(a,b) return tostring(a) < tostring(b) end
 
 
 
 
+-- -- -- -- string stuff
+local lpeg = require"lpeg"
+local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V
 
-local function gextract(s, pat) --extract a pattern from string, returns both
+local number = P{"number",
+    number = (V"int" * V"frac"^-1 * V"exp"^-1) / tonumber,
+    int = V"sign"^-1 * (R"19" * V"digits" + V"digit"),
+    digits = V"digit" * V"digits" + V"digit",
+    digit = R"09",
+    sign = S"+-",
+    frac = P"." * V"digits",
+    exp = S"eE" * V"sign"^-1 * V"digits",
+    }
+
+
+local mt = getmetatable("") -- register functions with str
+
+
+function mt.__index.gnum(s)
+    return number:match(s)
+end
+
+function mt.__index.gextract(s, pat) --extract a pattern from string, returns both
     local s_extr = ''
     local s_rem = s
     for e in s:gmatch(pat) do
@@ -192,7 +201,7 @@
     return s_extr, s_rem
 end
 
-local function gfirst(s, t) -- get the first pattern found from a table of pattern
+function mt.__index.gfirst(s, t) -- get the first pattern found from a table of pattern
     for _, pat in pairs(t) do
         if string.find(s, pat) then
             return pat
@@ -200,7 +209,7 @@
     end
 end
 
-local function appif(S, W, B, O) --append W ord to S tring if B oolean true, otherwise O ther
+function mt.__index.appif(S, W, B, O) --append W ord to S tring if B oolean true, otherwise O ther
     --append Word to String
     if B then --if b is true
         S = S .. W
@@ -211,12 +220,10 @@
     return S
 end
 
-local mt = getmetatable("") -- register functions with str
-mt.__index["gextract"] = gextract
-mt.__index["gfirst"] = gfirst
-mt.__index["app_if"] = appif
 
 
+-- -- -- -- -- math stuffs
+
 function mod(a, b) -- math modulo, return remainder only
     return a - (math.floor(a/b)*b)
 end
@@ -226,9 +233,11 @@
 end
 
 function hasval(x)  -- if something has value
-    if (x == nil) or (x == false) or (x == 0) or (x == '') then
+    if (type(x) == 'function') then
+        return true
+    elseif (x == nil) or (x == false) or (x == 0) or (x == '') then
         return false
-    elseif (type(x) ~= 'number') or (type(x) ~= 'string') then
+    elseif (type(x) ~= 'boolean') and (type(x) ~= 'number') and (type(x) ~= 'string') then
         if #x == 0 then
             return false
         else
@@ -241,65 +250,12 @@
 
 
 
--- testing here
-____zzz__ = [[
-function hasStrKey(T)
-    --checks if a Table contains a string-type key
-    local hasaStrKey = false
-    for k, v in pairs(T) do  --look through table pairs
-        if type(k) == "string" then  --if any string found, return true
-            hasaStrKey = true
-            break
-        end
-    end
-    return hasaStrKey
-end
 
 
-function any()
-    --todo go through table or list of args and return true of anything is something
-end
 
-function all()
-    --todo go through table or list of args and return true of anything is something
-end
 
 
-    --elseif x == {} then
-    --    return false
 
-n = nil
-b = false
-z = 0
-e = ''
-t = {}
-
---s = 'a'
---n = 1
-
-
-if is(nil) then
-    print('TRUE')
-else
-    print('FALSE')
-end
-
---print({}=={})
---print(0.0==0)
-
-
-]]
-
-
-
-
-
-
-
-
-
-
-
 -- Some simple and helpful LaTeX functions
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@@ -343,8 +299,10 @@
 end
 
 function add_bkt_cnt(n)
+    -- add open bracket n times, returns brackets
      n = n or 1
     _NumBkts = _NumBkts + n
+    return ('{'):rep(n)
 end
 
 function close_bkt_cnt()
@@ -361,7 +319,7 @@
 
 
 --definition helpers -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--- todo add this
+-- todo add and improve this
 
 local function defcmd_nest(cs) -- for option if you'd like your commands under  a parent ex. \csparent{var}
     tex.print('\\gdef\\'..cs..'#1{\\csname '..var..'--#1--\\endcsname}')



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