From b9f74458189966b3c057257c4d333ffe69435d57 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 26 Nov 2023 21:05:12 +0000 Subject: penlightplus (26nov23) git-svn-id: svn://tug.org/texlive/trunk@68973 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/luatex/penlightplus/penlightplus.lua | 19 +++++++- .../tex/luatex/penlightplus/penlightplus.sty | 56 +++++++++++++++------- 2 files changed, 57 insertions(+), 18 deletions(-) (limited to 'Master/texmf-dist/tex/luatex') diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua index 1f74d45777a..84cd2094ff0 100644 --- a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua +++ b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2023-09-04 +--% 2023-11-25 --% Copyright (C) 2021-2023 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -449,6 +449,10 @@ function str_mt.__index.trimfl(str) return str:sub(2,-2) end +function str_mt.__index.subpar(s, r) + r = r or ' ' + return (s:gsub('\\par', r)) +end -- -- -- -- function stuff @@ -802,6 +806,7 @@ function penlight.get_tbl_index(s) return tbl, key end + function penlight.get_tbl_item(s, p) -- get item with string, p means print value p = p or false local tbl, key = penlight.get_tbl_index(s) @@ -840,6 +845,18 @@ function penlight.check_recent_tbl_undefault() end +penlight.tbl_xysep = '%s+' -- spaces separate x-y coords +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 + token.set_macro(def..'x', tostring(x)) + token.set_macro(def..'y', tostring(y)) +end + + if penlight.hasval(__PL_GLOBALS__) then -- iterators kpairs = penlight.utils.kpairs diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty index 01b0aafc167..97083c6bffe 100644 --- a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty +++ b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2023-09-04 +% 2023-11-25 % 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-09-04] +\ProvidesPackage{penlightplus}[2023-11-25] \RequirePackage{luacode} \RequirePackage{luakeys} @@ -62,12 +62,12 @@ \luadirect{penlight.tex.aliasluastring(\luastring{#2},\luastring{#1})}% } -\NewDocumentCommand{\splitToComma}{ O{nn} m m }{% +\NewDocumentCommand{\splittocomma}{ O{nn} m m }{% \MakeluastringCommands[nn]{#1}% \luadirect{penlight.tex.split2comma(\plluastringA{#2},\plluastringB{#3})}% } -\NewDocumentCommand{\splitToItems}{ O{NN} m m }{% +\NewDocumentCommand{\splittoitems}{ O{NN} m m }{% \MakeluastringCommands[nn]{#1}% \luadirect{penlight.tex.split2items(\plluastringA{#2},\plluastringB{#3})}% } @@ -103,45 +103,67 @@ -%%% +%%% tbls below -\NewDocumentCommand{\newtbl}{m}{\luadirect{ +\NewDocumentCommand{\tblnew}{m}{\luadirect{% initialize a tbl penlight.tbls[\luastring{#1}] = {} penlight.rec_tbl = \luastring{#1} }} -\NewDocumentCommand{\tblfrkv}{m m O{}}{ \luadirect{ +\NewDocumentCommand{\tblfrkv}{m +m O{}}{\luadirect{% penlight.rec_tbl_opts = penlight.luakeys.parse(\luastring{#3}) - penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(\luastring{#2}, penlight.rec_tbl_opts) + penlight.wrth(\luastring{#2}, '??') + penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(string.subpar(\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{\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) + 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{\tblkvundefcheck}{}{\luadirect{penlight.check_recent_tbl_undefault()}}% check defaults list and throw error if foreign keys were used -\NewDocumentCommand{\chgtbl}{ m }{ \luadirect{ +\NewDocumentCommand{\tblchg}{ m }{\luadirect{% change recent table penlight.rec_tbl = \luastring{#1} }} -\NewDocumentCommand{\gettbl}{m}{\luadirect{ + +\NewDocumentCommand{\tblget}{m}{\luadirect{% get an item penlight.get_tbl_item(\luastring{#1}, true) }} -\NewDocumentCommand{\settbl}{m m}{\luadirect{ +\NewDocumentCommand{\tblset}{m m}{\luadirect{% set item with {value} penlight.set_tbl_item(\luastring{#1}, \luastring{#2}) }} -\NewDocumentCommand{\deftbl}{ m m }{\luadirect{% define a table, use * to make definition +\NewDocumentCommand{\tbldef}{ m m }{\luadirect{% define a table, use * to make definition token.set_macro(\luastring{#2}, tostring(penlight.get_tbl_item(\luastring{#1}))) }} -\NewDocumentCommand{\gdeftbl}{ m m }{\luadirect{% define a table, use * to make global definition +\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{\iftbl}{m m O{}}{\ifluax{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]} +\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{\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{\iftblv}{m m O{}}{\ifluaxv{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]} +% legacy code, delete this +\let\kvtblundefcheck\tblkvundefcheck +\let\chgtbl\tblchg +\let\newtbl\tblnew +\let\gettbl\tblget +\let\settbl\tblset +\let\deftbl\tbldef +\let\gdeftbl\tblgdef +\let\iftbl\tblif +\let\iftblv\tblifv \ No newline at end of file -- cgit v1.2.3