summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-08-05 20:05:51 +0000
committerKarl Berry <karl@freefriends.org>2023-08-05 20:05:51 +0000
commit7c03b44ea77e3d2229670b903684e67db2f2edb0 (patch)
tree5efb74e664bb55e67e594a255e3999fb6284fa91 /Master/texmf-dist/tex/luatex
parent4ed81db47f3adbc7ed05df9fb4a3b91478c8d4b1 (diff)
addtoluatexpath (5aug23)
git-svn-id: svn://tug.org/texlive/trunk@67821 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty52
1 files changed, 52 insertions, 0 deletions
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}