I would like to use external packages for LuaLaTeX scripting (eg.penlight). I often test my scripts with texlua command without issues. However, I noticed when I compile the document with the lualatex command, an error is raised on require(). I am certain that package.path and package.cpath contain the directories where my external modules are stored. It seems like I can add modules by providing the absolute path to the external module, but this becomes an issue if the module relatively references another one.
So in summary, require() with relative paths is not working for lualatex, but works for texlua commands.
I know this is a related question, but it is 2011 and the solution is inelegant as I would have to manually change the require call for each external module. "Lua tree" (analogue of texmf tree)
Main.tex
\documentclass{scrartcl}
\directlua{dofile("FileInSameDirAsMainAndRequiresExternalModules.lua")}
\begin{document}
Hello World
\end{document}
FileInSameDirAsMainAndRequiresExternalModules.lua
_LUA_STUFF_DIR = 'C:/Program Files/MiKTeX 2.9/miktex/bin/x64' --just to be sure the path is there...
package.path = package.path..';'.._LUA_STUFF_DIR
package.cpath = package.cpath..';'.._LUA_STUFF_DIR --todo why does this not work for luatex but texlua
--Both calls below work with texlua command
pl = require('pl') -- this fails with lualatex as pl is not found
pl = require(_LUA_STUFF_DIR..'/pl/tablex') -- this also fails with lualatex, but differently
--it "gets" through to the pl.tablex module, but fails since tablex.lua had a require(pl.util) in it
Edit: Also tested this with the same issue
\documentclass{scrartcl}
\directlua{
LUASTUFFDIR = 'C:/Program Files/MiKTeX 2.9/miktex/bin/x64'
package.path = package.path..';'..LUASTUFFDIR
package.cpath = package.cpath..';'..LUASTUFFDIR
pl = require('pl')
}
\begin{document}
Hello
\end{document}
"./FileInSameDirAsMainAndRequiresExternalModules.lua"? – projetmbc Apr 17 '21 at 17:18"./FileInSameDirAsMainAndRequiresExternalModules.lua", it is because that.luafile fails on therequirecall is failing for relative paths--or perhapsrequireis not usingpackage.pathorpackage.cpathwhen searching. As I pointed out, I don't want to have to modify every module to point to an absolute path. – likethevegetable Apr 17 '21 at 17:21