summaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-08-06 03:00:50 +0000
committerNorbert Preining <norbert@preining.info>2023-08-06 03:00:50 +0000
commitb8344986f0b0553f4794a39ae9b63c6b206cd48d (patch)
treeba663cf1a125a0d446475f2a04b748ddf8136931 /macros
parentd40e7963c06e1302f226c67f32c143dcc5fa958a (diff)
CTAN sync 202308060300
Diffstat (limited to 'macros')
-rw-r--r--macros/luatex/generic/addtoluatexpath/README.md57
-rw-r--r--macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty52
2 files changed, 109 insertions, 0 deletions
diff --git a/macros/luatex/generic/addtoluatexpath/README.md b/macros/luatex/generic/addtoluatexpath/README.md
new file mode 100644
index 0000000000..eedfdf2fc8
--- /dev/null
+++ b/macros/luatex/generic/addtoluatexpath/README.md
@@ -0,0 +1,57 @@
+# addtoluatexpath
+
+
+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.
+
+## Usage
+* You can either pass the comma-separated paths via package options like `\RequirePackage[path1,path2]{addtoluatexpath}` in pre-amble,
+ or by using the macro `\addtoluatexpath{path1,path2}` after the package has been loaded.
+* If you wish to include first-level sub-directories as well as a path, inlcude a `/*` at the end of the path.
+ eg. `\RequirePackage[C:/Users/me/Desktop/*]{addtoluatexpath}` adds your Desktop and all folders in the desktop to path.
+* If you wish to include all nested sub-directories of all levels, include a `/**` at the end of the path.
+* 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}`
+
+## Note
+This package appends to the `package.path` Lua variable and the `\input@path` command (it first uses `\providecommand` to intialize it).
+Lua files in the added paths can then added via `require'fileinpath1'`; however `loadfile` and `dofile` still require the full path.
+`graphicx` internally uses `\input@path` as a default list of the paths;
+therefore, paths specified by this package will also include graphics if the `graphicx` package is loaded after paths are set.
+However, if `\graphicspath{}` is used after paths are added by this package, graphics search paths will not use `\input@path`, omitting the paths you added with this package.
+
+## Dependencies
+`luacode`, `luakeys`, `penlight` (only if using `*` in paths)
+
+## Repo & Contact
+
+* <https://github.com/kalekje/addtoluatexpath>
+
+* [kalekje@gmail.com](mailto:kalekje@gmail.com)
+
+
+## License
+
+Copyright (C) 2023 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
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty b/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty
new file mode 100644
index 0000000000..cea0cc1eb2
--- /dev/null
+++ b/macros/luatex/generic/addtoluatexpath/addtoluatexpath.sty
@@ -0,0 +1,52 @@
+\ProvidesPackage{addtoluatexpath}[2023-08-04]
+
+\RequirePackage{luacode}
+
+\providecommand{\input@path}{} % initialize input@path if not defined yet
+
+\begin{luacode*}
+
+ 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
+
+ local atlp_no_lua = atlp_tbl['nolua'] or false -- check and set nolua=true
+ local atlp_no_tex = atlp_tbl['notex'] or false -- check and set notex=true
+
+ if atlp_raw:find('*') ~= nil then -- if *, must use penlight to expand subdirectories
+ penlight = require'penlight'
+ atlp_tbl = penlight.List(atlp_tbl) -- convert to pl.List for easy manipulation
+ end
+
+ for __, p in ipairs(atlp_tbl) do
+ if p:find('*') == nil then -- add paths without *, continue 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
+ goto continue
+ end
+
+ local p, c = p:gsub('*','') -- if * added, include subdirectories
+ local atlp_subdirs = penlight.List(penlight.dir.getdirectories(p))
+ -- troubleshooting --texio.write_nl(penlight.pretty.write(atlp_subdirs))
+ if c == 2 then
+ atlp_subdirs = atlp_subdirs:map(function(s) return s ..'/**' end) -- add ** to subdirs for recursive inclusion
+ end
+ atlp_tbl:append(p) -- make sure p (current path without *) is still added!
+ atlp_tbl:extend(atlp_subdirs) -- extend path to include additional subdirs; the for loop is lengthened
+
+ ::continue::
+ end
+
+ -- -- troubleshooting: show all paths
+ --texio.write_nl('Lua Paths >>> \n'..package.path:gsub(';','\n'))
+ --texio.write_nl('TeX Paths >>> \n'..token.get_macro('input@path'):gsub('}{','\n'))
+
+ end
+
+ atlp_main(token.get_macro('@raw@opt@addtoluatexpath.sty'))
+
+\end{luacode*}
+
+\NewDocumentCommand{\addtoluatexpath}{m}{\luadirect{atlp_main(\luastring{#1})}} % a command
+
+\AtEndOfPackage{\let\@unprocessedoptions\relax}