As package author, I want to write a Lua module which can be found by both lualatex
and context
.
The lualatex
prototype works reasonably and I am convinced that this will also be true if I release the package.
However, the context
prototype does not find my files, but I can force it to find my files by specifying a suitable LUAINPUTS
environment variable (which points to the directory from which my files can be found directly).
However, I do not understand if (or how) my package will work in the "wild" where this environment variable is not set as in my development environment.
The question is essentially: where should I place my files such that context
can require
it?
Here is what I believe to be a minimal working example:
Let us assume that my package resides in /tmp/luamodule/texmf/tex/generic/pgfplots/libs/foo/bar/xyz.lua
. This resembles my vague idea that texmf
will be the global texmf
entry point, then I have my package (directories tex/generic/pgfplots/libs
) and then I have a sub-directory structure resembling my Lua package (foo/bar/xyz.lua
).
The package file xyz.lua
contains the advanced package
io.write("\nFOUND IT!\n")
Then I have a file containing
\documentclass{standalone}
\directlua{require('foo.bar.xyz')}
\begin{document}
OK.
\end{document}
Processing this with
export LUAINPUTS="/tmp/luamodule/texmf/tex/generic/pgfplots//:"
lualatex xyz.tex
works: I see "FOUND IT" in the console output.
Next, I retry the same with context
and write a file xyzcontext.tex
containing
\directlua{require('foo.bar.xyz')}
\starttext
OK.
\stoptext
Translating this with
export LUAINPUTS="/tmp/luamodule/texmf/tex/generic/pgfplots//:"
context xyzcontext
fails because it cannot find the Lua file.
However, it works if I write
export LUAINPUTS="/tmp/luamodule/texmf/tex/generic/pgfplots/libs/:"
context xyzcontext
The difference is that my first LUAINPUTS path contains a recursive include (//
) whereas the second one contains the precise root directory.
I have learned already that context
does things differently compared to lualatex
(does not use kpse
during require
and handles periods differently). But this issue lets we wonder: lualatex
appears to work with recursively defined lua file paths. Judging from the texmf.cnf configs shipped with tex live, I would expect that my directory naming scheme will work. But what with context!? Will it find my files if I do not set such a root path? It seems that this kind of naming scheme works will with PGF's graph drawing lib (in both lualatex
and context
), but I don't really see why.
I even tried to copy my .lua
files into the TL 2014 global texmf
tree (followed by texhash
) -- without success.
Thus, my question: where should I place my .lua
files such that both lualatex
and context
can find them?
related: Best Practices for Lua Modules
mtxrun --generate
to recreate the filename database? That should make files in the TEXMF available to Context’s lookup routines.require()
to load packages, usually only for external, non-TeX libs. Instead it’s more idiomatic to useenvironment.loadluafile()
at the Lua end, and\registerctxluafile
from TeX.mtxrun --generate
. I ran it right now without any apparent difference (i.e. it still does not find the file).texmf-local
works just fine.