texlive[73424] Master/texmf-dist: addtoluatexpath (11jan25)

commits+karl at tug.org commits+karl at tug.org
Sat Jan 11 21:50:19 CET 2025


Revision: 73424
          https://tug.org/svn/texlive?view=revision&revision=73424
Author:   karl
Date:     2025-01-11 21:50:19 +0100 (Sat, 11 Jan 2025)
Log Message:
-----------
addtoluatexpath (11jan25)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/luatex/addtoluatexpath/README.md
    trunk/Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty

Modified: trunk/Master/texmf-dist/doc/luatex/addtoluatexpath/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/addtoluatexpath/README.md	2025-01-11 20:50:11 UTC (rev 73423)
+++ trunk/Master/texmf-dist/doc/luatex/addtoluatexpath/README.md	2025-01-11 20:50:19 UTC (rev 73424)
@@ -1,8 +1,8 @@
 # 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 on a network or cloud storage drive.
+The `addtoluatexpath` package provides a convenient way to add input and Lua package paths to your document.
+You may want this package if `.cls` or `.sty` files are located outside of your tex directories (like a network drive or cloud storage drive).
 
 ## Usage
 * You can either pass the comma-separated paths via package options like `\RequirePackage[path1,path2]{addtoluatexpath}` in pre-amble,
@@ -11,24 +11,25 @@
    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}`
-* 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
+* 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}`.
+* If you want to supress a package error that comes up if a directory you try to add does not exist, set `noerror=true`.
+* The lua table `addtoluatexpath` is globally defined with the following attributes: 
+* `.main(paths_str)` is the main function that runs, `paths_str` is the argument to `\addtoluatexpath` or the package options.
+* `.paths = {'.', ...}` is a table containing all paths added by this package
+* `.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 issued.
+* `.prt_paths()` prints the paths to the log file.
 
 
 
-## Note
-This package appends to the `package.path` Lua variable and the `\input at 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.
+## Notes
+This package appends to the `package.path` Lua variable and the `\input at path` command sequence (it first uses `\providecommand` to initialize it).
+Lua files in the added paths can then be added via `require'fileinpath1'`; however `loadfile` and `dofile` still require the full path. Caveat: 
 `graphicx` internally uses `\input at 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 at path`, omitting the paths you added with this package.
+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 at path`, therefore not using the paths you added with this package.
 
 ## Dependencies
-`luacode`, `luakeys`, `penlight` (only if using `*` in paths)
+`luacode`, `luakeys`, `penlight`
 
 ## Repo & Contact
 
@@ -39,7 +40,7 @@
 
 ## License
 
-Copyright (C) 2023-2024 Kale Ewasiuk
+Copyright (C) 2023-2025 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

Modified: trunk/Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty	2025-01-11 20:50:11 UTC (rev 73423)
+++ trunk/Master/texmf-dist/tex/luatex/addtoluatexpath/addtoluatexpath.sty	2025-01-11 20:50:19 UTC (rev 73424)
@@ -1,15 +1,39 @@
-\ProvidesPackage{addtoluatexpath}[2024-03-14]
+% Copyright (C) 2023-2025 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.
 
+
+\ProvidesPackage{addtoluatexpath}[2025-01-11]
+
 \RequirePackage{luacode}
 
 \providecommand{\input at path}{} % initialize input at path if not defined yet
 
 \begin{luacode*}
+  addtoluatexpath = {}
   
-  atlp_paths = {"."} -- global table containing paths added by this package
+  addtoluatexpath.paths = {"."} --  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
+  function addtoluatexpath.find_file(f) -- find a path in list of addtoluatexpath.paths
+    for i, k in pairs(addtoluatexpath.paths) do
       local fp = kpse.find_file(k ..'/'.. f)
       if (fp) then
         return fp
@@ -17,52 +41,54 @@
     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 at path'))
-    tex.sprint('\\PackageError{addtoluatexpath}{a file was not found}{}')
+    tex.sprint('\\PackageError{addtoluatexpath}{a file was not found, see log.}{}')
     tex.sprint('\\stop')
   end
   
-  function atlp_main(atlp_raw) -- add to path from raw string
-
+  function addtoluatexpath.main(atlp_raw) -- add to path from raw string
+    local penlight = require'penlight'
+    
     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
+    local atlp_no_error = atlp_tbl['noerror'] or false  -- check and set noerror=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
+    atlp_tbl = penlight.List(atlp_tbl) -- convert to pl.List for easy manipulation
 
     for __, p in ipairs(atlp_tbl) do
       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 at path', token.get_macro('input at path')..'{'..p..'/}', 'global') end
-        atlp_paths[#atlp_paths + 1] = p -- append the added path to global list
-        goto continue
+        if (not atlp_no_error) and (not penlight.path.exists(p)) then
+              tex.sprint('\\PackageError{addtoluatexpath}{directory "'..p..'" was not found}{}')
+        end
+        addtoluatexpath.paths[#addtoluatexpath.paths + 1] = p -- append the added path to global list
+      else
+        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
       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 at path'):gsub('}{','\n'))
-
   end
-
-  atlp_main(token.get_macro('@raw at opt@addtoluatexpath.sty'))
-
+    
+  
+  function addtoluatexpath.prt_paths()
+    texio.write_nl('Lua Paths >>> \n'..package.path:gsub(';','\n'))
+    texio.write_nl('\nTeX Paths >>> \n'..token.get_macro('input at path'):gsub('}{','\n'))
+  end
+  
+  ---- ---- ---- add paths passed as package options
+  addtoluatexpath.main(token.get_macro('@raw at opt@addtoluatexpath.sty'))
+  ---- ---- ----
+  
 \end{luacode*}
 
-\NewDocumentCommand{\addtoluatexpath}{m}{\luadirect{atlp_main(\luastring{#1})}}  % a command
+\NewDocumentCommand{\addtoluatexpath}{m}{\luadirect{addtoluatexpath.main(\luastring{#1})}}  % a command
 
 \AtEndOfPackage{\let\@unprocessedoptions\relax}



More information about the tex-live-commits mailing list.