I want to move all .lua files into the subdirectory code to avoid polluting the main directory with them. However, I cannot get lualatex to find them there.
Given this project layout:
main.tex
main.lua
code/
test.lua
test2.lua
main.tex
\documentclass{article}
\directlua{package.path = './code/?.lua;' .. package.path}
\directlua{print(package.path)}
\directlua{require('test')}
\directlua{require('code/test')}
\begin{document}
\end{document}
main.lua
package.path = './code/?.lua;' .. package.path
print(package.path)
require('test')
require('code/test')
code/test.lua
require('test2')
code/test2.lua
print('success')
When I run lualatex main.tex I get the output:
This is LuaTeX, Version beta-0.79.1 (TeX Live 2014/Arch Linux) (rev 4971)
restricted \write18 enabled.
(./main.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 79 languages loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))./code/?.lua;/usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua
! LuaTeX error [\directlua]:1: module 'test' not found:
no field package.preload['test']
[kpse lua searcher] file not found: 'test'
[kpse C searcher] file not found: 'test'
stack traceback:
[C]: in function 'require'
[\directlua]:1: in main chunk.
l.5 \directlua{require('test')}
? q
OK, entering \batchmode
The problem seems to be that lualatex does not find the files in the subdirectory although I altered the package.path (which is also printed correctly!).
When I runt the same code via lua main.lua the output is
./code/?.lua;/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;/usr/lib/lua/5.2/?.lua;/usr/lib/lua/5.2/?/init.lua;./?.lua
success
as expected.
For some reason lualatex seems not to take package.path into account.
Using require('code/test.lua') is not an option because then the dependency between test.lua and test2.lua is not picked up correctly.
What do I need to do to make lualatex find my .lua files in the code directory?
I already followed this question to this answer but I don't see how this solves the problem (or does it state that we cannot change the package search path in lualatex?). Also, the scenario seems to be another one as I don't want to "install a systemwide" module but some scripts for this project only.
kpselibrary which searches intexmftree abd current directory. but it is possible to modify package loader to support package oath, see http://tex.stackexchange.com/a/219228/2891 – michal.h21 Jan 06 '15 at 14:20require('code/test')should berequire('code.test'). but it probably will not find submodules anyway – michal.h21 Jan 06 '15 at 14:54require('code.test')it should work. – yannisl Jan 06 '15 at 15:00require(code/test)works as well asrequire(code.test)the problem occurs with the dependency incode/test.luatocode/test2.luawhich in both cases does not work because therequiredoes not search incode. – Nobody moving away from SE Jan 06 '15 at 15:25