summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-03-16 03:02:08 +0000
committerNorbert Preining <norbert@preining.info>2024-03-16 03:02:08 +0000
commit966f9ba332e49c29e961cb86e08f97d70eda51f6 (patch)
treee111edb864721bb0dac9db16b4e41a8a489ea456 /macros/luatex
parent12679ab7d3c2a210f4123163671b532b8b55d5f9 (diff)
CTAN sync 202403160302
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/generic/addtoluatexpath/README.md10
-rw-r--r--macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty22
-rw-r--r--macros/luatex/generic/penlightplus/penlightplus.lua41
-rw-r--r--macros/luatex/generic/penlightplus/penlightplus.pdfbin80983 -> 81225 bytes
-rw-r--r--macros/luatex/generic/penlightplus/penlightplus.sty28
-rw-r--r--macros/luatex/generic/penlightplus/penlightplus.tex4
6 files changed, 78 insertions, 27 deletions
diff --git a/macros/luatex/generic/addtoluatexpath/README.md b/macros/luatex/generic/addtoluatexpath/README.md
index eedfdf2fc8..da97dfa4a3 100644
--- a/macros/luatex/generic/addtoluatexpath/README.md
+++ b/macros/luatex/generic/addtoluatexpath/README.md
@@ -2,7 +2,7 @@
The `addtoluatexpath` package provides a convenient way to add input and Lua package paths in your document.
-You may want this package, for example, if a `.cls` or `.sty` file is located a network or cloud storage drive.
+You may want this package, for example, if a `.cls` or `.sty` file is located on a network or cloud storage drive.
## Usage
* You can either pass the comma-separated paths via package options like `\RequirePackage[path1,path2]{addtoluatexpath}` in pre-amble,
@@ -13,6 +13,12 @@ You may want this package, for example, if a `.cls` or `.sty` file is located a
* If you want to add to Lua path (`package.path`) only, include `notex=true` in the argument.
* If you want to add to tex input path only, include `nolua=true` in the argument.
eg. `\RequirePackage[nolua=true, C:/Users/me/Desktop/*, /**]{addtoluatexpath}`
+* The lua functions below are globally defined:
+* `atlp_main(paths_str)` is the main function that runs
+* `atlp_paths = {}` is a table containing all paths added by this package
+* `atlp_find_file(file_str)` is a function that returns the full path of a file, it searches through all paths that were input to this package and returns the first valid. If no paths are found, an error is issed
+
+
## Note
This package appends to the `package.path` Lua variable and the `\input@path` command (it first uses `\providecommand` to intialize it).
@@ -33,7 +39,7 @@ However, if `\graphicspath{}` is used after paths are added by this package, gra
## License
-Copyright (C) 2023 Kale Ewasiuk
+Copyright (C) 2023-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
diff --git a/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty b/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty
index cea0cc1eb2..140a3ac208 100644
--- a/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty
+++ b/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty
@@ -1,11 +1,26 @@
-\ProvidesPackage{addtoluatexpath}[2023-08-04]
+\ProvidesPackage{addtoluatexpath}[2024-03-14]
\RequirePackage{luacode}
\providecommand{\input@path}{} % initialize input@path if not defined yet
\begin{luacode*}
-
+
+ atlp_paths = {"."} -- global table containing paths added by this package
+
+ function atlp_find_file(f) -- find a path in list of atlp_paths
+ for i, k in pairs(atlp_paths) do
+ local fp = kpse.find_file(k ..'/'.. f)
+ if (fp) then
+ return fp
+ end
+ end -- if nothing returned, issue a package error
+ texio.write_nl('addtoluatexpath searched for file: '..f)
+ texio.write_nl('addtoluatexpath searched paths were: '..token.get_macro('input@path'))
+ tex.sprint('\\PackageError{addtoluatexpath}{a file was not found}{}')
+ tex.sprint('\\stop')
+ end
+
function atlp_main(atlp_raw) -- add to path from raw string
local atlp_tbl = require'luakeys'().parse(atlp_raw, {naked_as_value=true}) -- paths as table
@@ -19,9 +34,10 @@
end
for __, p in ipairs(atlp_tbl) do
- if p:find('*') == nil then -- add paths without *, continue loop after
+ if p:find('*') == nil then -- add paths without *, and continue the loop after
if not atlp_no_lua then package.path = package.path .. ';'..p..'/?.lua;' end
if not atlp_no_tex then token.set_macro('input@path', token.get_macro('input@path')..'{'..p..'/}', 'global') end
+ atlp_paths[#atlp_paths + 1] = p -- append the added path to global list
goto continue
end
diff --git a/macros/luatex/generic/penlightplus/penlightplus.lua b/macros/luatex/generic/penlightplus/penlightplus.lua
index a831c6721d..e51b01c14b 100644
--- a/macros/luatex/generic/penlightplus/penlightplus.lua
+++ b/macros/luatex/generic/penlightplus/penlightplus.lua
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje@gmail.com)
---% 2024-02-29
+--% 2024-03-14
--% Copyright (C) 2021-2024 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -32,10 +32,15 @@ __PL_SKIP_TEX__ = __PL_SKIP_TEX__ or false --if declared true before here, it wi
__PL_GLOBALS__ = __PL_GLOBALS__ or false
__PL_NO_HYPERREF__ = __PL_NO_HYPERREF__ or false
-
penlight.luakeys = require'luakeys'()
-penlight.COMP = require'pl.comprehension'.new() -- for comprehensions
+penlight.debug_available = false -- check if penlight debug package is available
+if debug ~= nil then
+ if type(debug.getinfo) == 'function' then
+ penlight.debug_available = true
+ end
+end
+
-- http://lua-users.org/wiki/SplitJoin -- todo read me!!
@@ -719,17 +724,22 @@ function penlight.array2d.parse_numpy2d_str(s)
end
-local _parse_range = penlight.clone_function(penlight.array2d.parse_range)
-function penlight.array2d.parse_range(s) -- edit parse range to do numpy string if no letter passed
- penlight.utils.assert_arg(1,s,'string')
- if not s:find'%a' then
- return penlight.array2d.parse_numpy2d_str(s)
- end
- return _parse_range(s)
-end
+if not penlight.debug_available then
+ penlight.tex.pkgwarn('penlight', 'lua debug library is not available, recommend re-compiling with the --luadebug option')
+else
+ penlight.COMP = require'pl.comprehension'.new() -- for comprehensions
+ local _parse_range = penlight.clone_function(penlight.array2d.parse_range)
+ function penlight.array2d.parse_range(s) -- edit parse range to do numpy string if no letter passed
+ penlight.utils.assert_arg(1,s,'string')
+ if not s:find'%a' then
+ return penlight.array2d.parse_numpy2d_str(s)
+ end
+ return _parse_range(s)
+ end
+end
@@ -865,9 +875,11 @@ function penlight.get_tbl(s)
return penlight.tbls[s]
end
-function penlight.get_tbl_index(s)
+function penlight.get_tbl_index(s, undec)
+ undec = undec or false -- flag for allowing undeclared indexing
local tbl = ''
local key = ''
+ local s_raw = s
if s:find('%.') then
local tt = s:split('.')
tbl = tt[1]
@@ -884,8 +896,9 @@ function penlight.get_tbl_index(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..'"')
+
+ if (penlight.tbls[tbl] == nil) or ((not undec) and (penlight.tbls[tbl][key] == nil)) then
+ penlight.tex.pkgerror('penlightplus', 'Invalid tbl index attempt using: "'..s_raw..'". We tried to use tbl: "' ..tbl..'" and key: "'..key..'"')
end
return tbl, key
end
diff --git a/macros/luatex/generic/penlightplus/penlightplus.pdf b/macros/luatex/generic/penlightplus/penlightplus.pdf
index 8f4fcb9717..2e37875101 100644
--- a/macros/luatex/generic/penlightplus/penlightplus.pdf
+++ b/macros/luatex/generic/penlightplus/penlightplus.pdf
Binary files differ
diff --git a/macros/luatex/generic/penlightplus/penlightplus.sty b/macros/luatex/generic/penlightplus/penlightplus.sty
index ee7ff3ad11..3c411d227a 100644
--- a/macros/luatex/generic/penlightplus/penlightplus.sty
+++ b/macros/luatex/generic/penlightplus/penlightplus.sty
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2024-02-29
+% 2024-03-14
% 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-02-29]
+\ProvidesPackage{penlightplus}[2024-03-14]
\RequirePackage{luacode}
\RequirePackage{luakeys}
@@ -141,14 +141,14 @@
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{\tbladd}{m m}{\luadirect{% add a kv pair to a table
+ __tbl__, __key__ = penlight.get_tbl_index(\luastring{#1}, true)
+ penlight.tbls[__tbl__][__key__] = \luastring{#2}
}}
\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}
+ __tbl__, __key__ = penlight.get_tbl_index(\luastring{#1}, true)
+ penlight.tbls[__tbl__][__key__] = \luastringN{#2}
}}
@@ -183,8 +183,22 @@
\NewDocumentCommand{\tblprt}{m}{\luadirect{penlight.wrth(penlight.get_tbl(\luastring{#1}),'penlightplus table: '..\luastring{#1})}}
+
+
+
% legacy code, delete this
\let\kvtblundefcheck\tblkvundefcheck
+
+\NewDocumentCommand{\tbladdo}{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{\tbladdNo}{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}
+}}
+
\let\chgtbl\tblchg
\let\newtbl\tblnew
\let\gettbl\tblget
diff --git a/macros/luatex/generic/penlightplus/penlightplus.tex b/macros/luatex/generic/penlightplus/penlightplus.tex
index 53488619bf..015dac98ef 100644
--- a/macros/luatex/generic/penlightplus/penlightplus.tex
+++ b/macros/luatex/generic/penlightplus/penlightplus.tex
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2024-02-29
+% 2024-03-14
% Copyright (C) 2021-2024 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -279,6 +279,8 @@ or simply use \cmd{ind} without the table name, where the assumed table is the l
\tblget{a}\\
\tblget{my.x}\\
\tblget{.x}\\
+\tbladd{my.newkey}{val}\tblget{newkey}\\
+\tbladd{nk}{VAL}\tblget{nk}\\
\tblif{n}{tr}[fa]\\
\tblifv{n}{TR}[FA]\\
\tblif{my.y}{Tr}[Fa]\\