diff options
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf | bin | 63923 -> 65123 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex | 85 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua | 19 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty | 56 |
4 files changed, 108 insertions, 52 deletions
diff --git a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf Binary files differindex 0f35dbf75ad..7e273cb6c13 100644 --- a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf +++ b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf diff --git a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex index fbc4ec32d59..169364847c4 100644 --- a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex +++ b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex @@ -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 @@ -157,7 +157,7 @@ The user can specify \cmd{n}, \cmd{o}, \cmd{t}, and \cmd{f} (case insensitve) if no, once, twice, or full expansion. For example, we can control the expansion of args 2 and 3 with arg 1: \begin{verbatim} - \NewDocumentCommand{\splitToComma}{ O{nn} m m }{% + \NewDocumentCommand{\splittocomma}{ O{nn} m m }{% \MakeluastringCommands[nn]{#1}% \luadirect{penlight.tex.split2comma(\plluastringA{#2},\plluastringB{#3})}% } @@ -199,17 +199,19 @@ no, once, twice, or full expansion. For example, we can control the expansion of \cmd{penlight.tbls} table. -\cmd{\newtbl{t}} declares a new table with name \cmd{t}\\ -\cmd{\chgtbl{t}} changes the 'recent' table\\ +\cmd{\tblnew{t}} declares a new table with name \cmd{t}\\ +\cmd{\tblchg{t}} changes the 'recent' table\\ \cmd{\tblfrkv{t}{key-val string}[luakeys opts]} new table from key-vals using \cmd{luakeys} \\ +\cmd{\tblfrkvN{t}{key-val string}[luakeys opts]} does not expand key-val string \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{\tblset{i}{v}} sets a value of the table/index \cmd{i} to \cmd{v}\\ +\cmd{\tblget{i}} gets the value and \cmd{tex.sprint()}'s it\\ +\cmd{\tbldef{i}{d}} pushes the value to a \cmd{cs} named \cmd{d}\\ +\cmd{\tblgdef{i}{d}} pushes the value to a global\\ +\cmd{\tbldefxy{i}{d}} splits the value of item by spaces creates two definitions \cmd{\dx} and \cmd{\dy}. Useful for pasing tikz coordinates like \cmd{xy=0 5}\\ \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 +\cmd{\tblkvundefcheck} 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). @@ -220,53 +222,68 @@ or simply use \cmd{ind} without the table name, where the assumed table is the l \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]\\ +\tblget{my.a}\\ +\tblset{a}{tRuE!!} +\tblget{a}\\ +\tblget{my.x}\\ +\tblif{n}{tr}[fa]\\ +\tblifv{n}{TR}[FA]\\ +\tblif{my.y}{Tr}[Fa]\\ +\tblifv{y}{tR}[fA]\\ %% \kvtblundefcheck % would throw error -\deftbl{my.first}{mydef} \mydef\\ -{\deftbl{last}{mydef} \mydef} \mydef\\ -{\gdeftbl{last}{mydef}} \mydef\\ +\tbldef{my.first}{mydef} \mydef\\ +{\tbldef{last}{mydef} \mydef} \mydef\\ +{\tblgdef{last}{mydef}} \mydef\\ + +\tblset{my.a}{12 36} +\tbldefxy{my.a}{coord} (\coordx,\coordy) \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 +\tblget{me/1},\tblget{2}\\ +\tblget{3}\\ +\tblset{me/4}{D}\tblget{me/4}\\ +\tblset{5}{E}\tblget{5}\\ +\tblget{-2},\tblget{me/-1}\\ +%% \tblget{k} % would throw error \end{LTXexample} +\tblfrcsv{me}{ +Hello=world, + + +Bonjour=terre, +} +\tblget{Hello} +\tblget{Bonjour} +Note: for thisf versions: all latex tbl commands are now prefixed with \cmd{tbl}, eg., \cmd{tblget}, \cmd{tblset}. +Old-style commands eg. \cmd{gettbl} will be kept as aliases for a few more releases then removed. \subsection*{Splitting strings} Splitting text (or a cmd) into oxford comma format via: -\cmd{\splitToComma[expansion level]{text}{text to split on}}: +\cmd{\splittocomma[expansion level]{text}{text to split on}}: \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}-\\ --\splitToComma{ j doe \and s else \and a per \and f guy}{\and}- +-\splittocomma{ j doe }{\and}-\\ +-\splittocomma{ j doe \and s else }{\and}-\\ +-\splittocomma{ j doe \and s else \and a per }{\and}-\\ +-\splittocomma{ j doe \and s else \and a per \and f guy}{\and}- \def\authors{j doe \and s else \and a per \and f guy} -\splitToComma[o]{\authors}{\and} +\splittocomma[o]{\authors}{\and} \end{LTXexample} The expansion level is up to two characters, \cmd{n|o|t|f}, to control the expansion of each argument. -You can do a similar string split but to \cmd{\item} instead of commas with \cmd{\splitToItems} +You can do a similar string split but to \cmd{\item} instead of commas with \cmd{\splittoitems} \begin{LTXexample} \begin{itemize} - \splitToItems{kale\and john}{\and} - \splitToItems{kale -john -someone else}{-} - \splitToItems{1,2,3,4}{,} + \splittoitems{kale\and john}{\and} + \splittoitems{kale -john -someone else}{-} + \splittoitems{1,2,3,4}{,} \end{itemize} \end{LTXexample} 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 |