From 7c03b44ea77e3d2229670b903684e67db2f2edb0 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 5 Aug 2023 20:05:51 +0000 Subject: addtoluatexpath (5aug23) git-svn-id: svn://tug.org/texlive/trunk@67821 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/luatex/addtoluatexpath/README.md | 57 ++++++++++++++++++++++ .../tex/luatex/addtoluatexpath/addtoluatexpath.sty | 52 ++++++++++++++++++++ Master/tlpkg/bin/tlpkg-ctan-check | 3 +- Master/tlpkg/tlpsrc/addtoluatexpath.tlpsrc | 0 Master/tlpkg/tlpsrc/collection-luatex.tlpsrc | 1 + 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Master/texmf-dist/doc/luatex/addtoluatexpath/README.md create mode 100644 Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty create mode 100644 Master/tlpkg/tlpsrc/addtoluatexpath.tlpsrc diff --git a/Master/texmf-dist/doc/luatex/addtoluatexpath/README.md b/Master/texmf-dist/doc/luatex/addtoluatexpath/README.md new file mode 100644 index 00000000000..eedfdf2fc80 --- /dev/null +++ b/Master/texmf-dist/doc/luatex/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 + +* + +* [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/Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty b/Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty new file mode 100644 index 00000000000..cea0cc1eb29 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/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} diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check index e9f94a2ce1a..014f0f7c281 100755 --- a/Master/tlpkg/bin/tlpkg-ctan-check +++ b/Master/tlpkg/bin/tlpkg-ctan-check @@ -26,7 +26,8 @@ my @TLP_working = qw( academicons accanthis accents accessibility accfonts accsupp achemso acmart acmconf acro acronym acroterm active-conf actuarialangle actuarialsymbol - addfont addliga addlines adfathesis adforn adhocfilelist adigraph + addfont addliga addlines addtoluatexpath + adfathesis adforn adhocfilelist adigraph adjmulticol adfsymbols adjustbox adobemapping adrconv adtrees advdate ae aeguill aesupp afparticle afthesis diff --git a/Master/tlpkg/tlpsrc/addtoluatexpath.tlpsrc b/Master/tlpkg/tlpsrc/addtoluatexpath.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc index a85adbd51cf..f9a732575de 100644 --- a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc @@ -8,6 +8,7 @@ longdesc The LuaTeX engine itself (and plain formats) are in collection-basic. depend collection-basic # depend addliga +depend addtoluatexpath depend auto-pst-pdf-lua depend barracuda depend bezierplot -- cgit v1.2.3