summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-03-01 21:45:51 +0000
committerKarl Berry <karl@freefriends.org>2024-03-01 21:45:51 +0000
commit86df9231241afb195794206c6c7204255a9f3d8c (patch)
tree5f38c2ac98de1a1fff5acecf90dc5ddf31e1ff19 /Master/texmf-dist/tex/luatex
parentedfd6ab3ed7259f3284e48f303725e60a2b96cbe (diff)
penlightplus (1mar24)
git-svn-id: svn://tug.org/texlive/trunk@70312 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua120
-rw-r--r--Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty80
2 files changed, 141 insertions, 59 deletions
diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
index 6aa1331fdd5..a831c6721d8 100644
--- a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
+++ b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua
@@ -1,6 +1,6 @@
--% Kale Ewasiuk (kalekje@gmail.com)
---% 2023-12-08
---% Copyright (C) 2021-2023 Kale Ewasiuk
+--% 2024-02-29
+--% Copyright (C) 2021-2024 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
--% of this software and associated documentation files (the "Software"), to deal
@@ -143,8 +143,9 @@ function penlight.tex.wrth(s1, s2) -- helpful printing, makes it easy to debug,
end
wrt2('\n^^^^^\n')
end
+penlight.wrth = penlight.tex.wrth
+penlight.tex.help_wrt = penlight.tex.wrth
penlight.help_wrt = penlight.tex.wrth
-penlight.wrth = penlight.help_wrt
function penlight.tex.prt_array2d(t)
for _, r in ipairs(t) do
@@ -456,22 +457,18 @@ function str_mt.__index.subpar(s, r)
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
+function str_mt.__index.fmt(s, t, fmt) -- format a $1 and $k string with an array or table and formats
+ -- formats can be a luakeys string, or a table and are applied to table before string is formatted
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
+ t = penlight.tablex.fmt(t, fmt, true)
return s % t
end
-
-
+function str_mt.__index.parsekv(s, t) -- parsekv string
+ if type(t) ~= 'table' then t = penlight.luakeys.parse(t) end
+ return penlight.luakeys.parse(s, t)
+end
-- -- -- -- function stuff
@@ -532,6 +529,37 @@ function penlight.tablex.strinds(t) -- convert indices that are numbers to strin
end
+function penlight.tablex.listcontains(t, v)
+ return penlight.tablex.find(t, v) ~= nil
+end
+
+
+-- format contents of a table
+function penlight.tablex.fmt(t, fmt, strinds)
+ if fmt == nil then
+ return t
+ end
+ strinds = strinds or false -- if your fmt table should use string indexes
+ if type(fmt) == 'string' then
+ if not fmt:find('=') then -- if no = assume format all same
+ for k, v in pairs(t) do -- apply same format to all
+ if tonumber(v) ~= nil then -- only apply to numeric values
+ t[k] = string.format("%"..fmt, v)
+ end
+ end
+ return t
+ else
+ fmt = fmt:parsekv('naked_as_value') -- make fmt a table from keyval str
+ end
+ end
+ if strinds then fmt = penlight.tablex.strinds(fmt) end -- convert int inds to str inds
+ for k, f in pairs(fmt) do -- apply formatting to table
+ t[k] = string.format("%"..f, tostring(t[k]))
+ end
+ return t
+end
+
+
function penlight.tablex.map_slice(func, T, j1, j2)
if type(j1) == 'string' then
return penlight.array2d.map_slice(func, {T}, ','..j1)[1]
@@ -556,24 +584,25 @@ function penlight.tablex.filterstr(t, exp, case)
end
end
-
+--todo add doc
function penlight.utils.filterfiles(...)
-- f1 is a series of filtering patterns, or condition
-- f2 is a series of filtering patters, or condition
-- (f1_a or f2_...) and (f2 .. ) must match
local args = table.pack(...)
- -- todo -- check where boolean is for recursive or not, set starting argument
+ -- dir, recursive[bool], filt1, filt2 etc...
+ -- OR recursive[bool], filt1, filt2, etc..
+ -- OR filt1, filt2, filt3, etc..
-- this could allow one to omit dir
- -- todo if no boolean at all, assume dir = '.' and r = false
- -- if boolean given, assume dir = '.'
+ -- if boolean given ar arg 1, assume dir = '.'
local nstart = 3
- local r = args[2]
- local dir = args[1]
+ local r = args[2] -- recursive
+ local dir = args[1] -- start dir
if type(args[1]) == 'boolean' then
dir = '.'
r = args[1]
nstart = 2
- elseif type(args[2]) ~= 'boolean' then
+ elseif type(args[2]) ~= 'boolean' then -- if boolean given ar arg 1, assume dir = '.'
dir = '.'
r = false
nstart = 1
@@ -591,7 +620,6 @@ end
-
-- -- -- -- -- -- -- -- functions below extend the array2d module
@@ -808,6 +836,18 @@ function penlight.tex.split2items(s, d)
end
+function penlight.toggle_luaexpr(expr)
+ if expr then
+ tex.sprint('\\toggletrue{luaexpr}')
+ else
+ tex.sprint('\\togglefalse{luaexpr}')
+ end
+end
+
+
+
+
+
penlight.tbls = {}
penlight.rec_tbl = ''
@@ -820,6 +860,11 @@ function penlight.get_tbl_name(s)
return s
end
+function penlight.get_tbl(s)
+ s = penlight.get_tbl_name(s)
+ return penlight.tbls[s]
+end
+
function penlight.get_tbl_index(s)
local tbl = ''
local key = ''
@@ -830,6 +875,7 @@ function penlight.get_tbl_index(s)
elseif s:find('/') then
local tt = s:split('/')
tbl = tt[1]
+ if tbl == '' then tbl = penlight.rec_tbl end
key = tonumber(tonumber(tt[2]))
if key < 0 then key = #penlight.tbls[tbl]+1+key end
else
@@ -837,6 +883,7 @@ function penlight.get_tbl_index(s)
key = tonumber(s) or s
if type(key) == 'number' and key < 0 then key = #penlight.tbls[tbl]+1+key end
end
+ if tbl == '' then tbl = penlight.rec_tbl end
if penlight.tbls[tbl] == nil or penlight.tbls[tbl][key] == nil then
penlight.tex.pkgerror('penlightplus', 'Invalid index of tbl using: "'..s..'"')
end
@@ -881,10 +928,26 @@ function penlight.check_recent_tbl_undefault()
end
end
+function penlight.def_tbl(ind, def, g)
+ local _tbl, _key = penlight.get_tbl_index(ind)
+ if def == '' then def = 'dtbl'.._tbl.._key end
+ token.set_macro(def, tostring(penlight.tbls[_tbl][_key]), g)
+end
+
+function penlight.def_tbl_all(ind, def)
+ local _tbl = penlight.get_tbl_name(ind)
+ if def == '' then def = 'dtbl'.._tbl end
+ for k, v in pairs(penlight.tbls[_tbl]) do
+ token.set_macro(def..k, tostring(v))
+ end
+end
+
-- 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...
+function penlight.def_tbl_coords(ind, def)
+ local tbl, key = penlight.get_tbl_index(ind)
+ local str = penlight.tbls[tbl][key]
+ if def == '' then def = 'dtbl'..tbl..key end
local x, y = str:strip():splitv(penlight.tbl_xysep)
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)
@@ -894,7 +957,14 @@ function penlight.def_tbl_coords(str, def)
end
---
+
+
+
+
+
+
+
+-- global setting type stuff
function penlight.make_tex_global()
for k,v in pairs(penlight.tex) do -- make tex functions global
diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty
index f5ffc0f1767..ee7ff3ad11f 100644
--- a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty
+++ b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty
@@ -1,6 +1,6 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2023-12-08
-% Copyright (C) 2021-2023 Kale Ewasiuk
+% 2024-02-29
+% Copyright (C) 2021-2024 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +22,7 @@
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
% OR OTHER DEALINGS IN THE SOFTWARE.
-\ProvidesPackage{penlightplus}[2023-12-08]
+\ProvidesPackage{penlightplus}[2024-02-29]
\RequirePackage{luacode}
\RequirePackage{luakeys}
@@ -84,22 +84,16 @@
\newtoggle{luaexpr}\togglefalse{luaexpr}
\begin{luacode*}
- function toggle_luaexpr(expr)
- if expr then
- tex.sprint('\\toggletrue{luaexpr}')
- else
- tex.sprint('\\togglefalse{luaexpr}')
- end
- end
+
\end{luacode*}
-\NewDocumentCommand{\ifluax}{m m O{}}{%
- \luadirect{toggle_luaexpr(#1)}%
+\NewDocumentCommand{\ifluax}{m m O{}}{% if lua expression is true do {m} if not [o]
+ \luadirect{penlight.toggle_luaexpr(#1)}%
\iftoggle{luaexpr}{#2}{#3}%
\togglefalse{luaexpr}% safety set to false
}
-\NewDocumentCommand{\ifluaxv}{m m O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]}
+\NewDocumentCommand{\ifluaxv}{m m O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]}% if lua expression is truthy do {m} else [o]
@@ -116,6 +110,10 @@
penlight.rec_tbl = \luastring{#1}
}}
+\NewDocumentCommand{\tblfrkvCD}{m +m O{}}{\tblfrkv{#1}{#2}[#3]\tblkvundefcheck\tbldefall{}{}}
+%% tbl from key-vals, then check defaults, then define all keys using default format
+\NewDocumentCommand{\tblfrkvNCD}{m +m O{}}{\tblfrkvN{#1}{#2}[#3]\tblkvundefcheck\tbldefall{}{}}
+
\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)
@@ -124,9 +122,38 @@
\NewDocumentCommand{\tblfrcsv}{m +m O{}}{\tblfrkv{#1}{#2}[naked_as_value=true,#3]}
+\NewDocumentCommand{\tblfrcsvN}{m +m O{}}{\tblfrkvN{#1}{#2}[naked_as_value=true,#3]}
+
\NewDocumentCommand{\tblkvundefcheck}{}{\luadirect{penlight.check_recent_tbl_undefault()}}% check defaults list and throw error if foreign keys were used
+
+
+\NewDocumentCommand{\tblapp}{m m}{\luadirect{% append to a table (ie using integer index) with a value (second arg) # todo option for string or number
+ __tbl__ = penlight.get_tbl_name(\luastring{#1})
+ table.insert(penlight.tbls[__tbl__], \luastring{#2})
+}}
+
+\NewDocumentCommand{\tblcon}{m m}{\luadirect{% concatenate to a table (ie using integer index) with a list of comma separated values (second arg) #
+ __tbl__ = penlight.get_tbl_name(\luastring{#1})
+ for k, v in ipairs(penlight.luakeys.parse(string.subpar(\luastring{#2}), {naked_as_value=true})) do
+ table.insert(penlight.tbls[__tbl__], v)
+ end
+}}
+
+\NewDocumentCommand{\tbladd}{m m m}{\luadirect{% add a kv pair to a table
+ __tbl__ = penlight.get_tbl_name(\luastring{#1})
+ penlight.tbls[__tbl__][\luastring{#2}] = \luastring{#3}
+}}
+
+\NewDocumentCommand{\tbladdN}{m m m}{\luadirect{% add a kv pair to a table
+ __tbl__ = penlight.get_tbl_name(\luastring{#1})
+ penlight.tbls[__tbl__][\luastring{#2}] = \luastringN{#3}
+}}
+
+
+
+
\NewDocumentCommand{\tblchg}{ m }{\luadirect{% change recent table
penlight.rec_tbl = \luastring{#1}
}}
@@ -140,36 +167,21 @@
penlight.set_tbl_item(\luastring{#1}, \luastring{#2})
}}
-% 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{\tbldef}{ m m }{\luadirect{penlight.def_tbl(\luastring{#1}, \luastring{#2})}}
+% define a table, use * to make global definition
+\NewDocumentCommand{\tblgdef}{ m m }{\luadirect{penlight.def_tbl(\luastring{#1}, \luastring{#2}, 'global')}}
-\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{\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{\tbldefall}{ m m }{\luadirect{penlight.def_tbl_all(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tbldefxy}{ m m }{\luadirect{penlight.def_tbl_coords(\luastring{#1}, \luastring{#2})}}% define #2x and #2y from a space delimited x-y pair
\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]}
+\NewDocumentCommand{\tblprt}{m}{\luadirect{penlight.wrth(penlight.get_tbl(\luastring{#1}),'penlightplus table: '..\luastring{#1})}}
% legacy code, delete this
\let\kvtblundefcheck\tblkvundefcheck