[tex-live] Making lua modules findable

Reinhard Kotucha reinhard.kotucha at web.de
Fri Jan 5 22:25:02 CET 2018

On 2018-01-05 at 12:28:32 +0100, Ralf Meyer wrote:

 > Dear texlive developers,
 > with luatex it becomes possible to embed lua modules in luatex
 > documents.  Many such modules are listed at luarocks.org, and quite
 > a few can be useful in luatex.  For normal users, this is too
 > complicated in texlive 2017 because of search path differences.  I
 > suggest to change the configuration of kpathsea in a new release of
 > texlive so that luatex searches lua modules also in the standard
 > folders for lua modules.  This is currently not the case, which
 > creates an extra hurdle to use general-purpose lua modules in
 > luatex documents.  On my ubuntu system, luarocks installs modules
 > in /usr/local/share/lua and /usr/local/lib/lua. And lua -e
 > "print(package.path)" and lua -e "print(package.cpath)" shows
 > several more paths.  Or maybe you know an even better way to make
 > lua modules in these folders findable by luatex as automatically as
 > possible.

Hi Ralf,

in this case kpathsea isn't involved at all.  kpathsea looks for Lua
libraries in $TEXMF _additionally_.  From texmf-dist/web2c/texmf.cnf:

  % Lua needs to look for binary lua libraries distributed with packages.
  CLUAINPUTS = .;$SELFAUTOLOC/lib/{$progname,$engine,}/lua//

You could add other search path there but this is probaly not what you

The variables package.path and package.cpath you have in mind are
compiled into the luatex binary.  And variables can be changed at any

Since luatex is currently based on Lua 5.2, the appropriate
directories are /usr/local/{lib,share}/lua/5.2/... .  If it's too
difficult to tell luarocks to install libraries there, the best
solution is to add paths to package.path and package.cpath in your lua
scripts before any package is loaded.   
The attached script hopefully does what you need:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: testluapaths.gz
Type: application/x-gzip
Size: 527 bytes
Desc: not available
URL: <http://tug.org/pipermail/tex-live/attachments/20180105/71d4ce19/attachment.bin>
-------------- next part --------------


  gunzip testluapaths.gz
  chmod 755 testluapaths
  ./testluapaths | tr \; \\n

At a first glance the function looks a bit complex but simply
appending the new paths is not a good solution.

Instead of

the new search order is


Does this solve your problem?

I suppose that the fuction works on Windows too (\ is recognized as a
path separator as well) but I expect severe problems with drive
letters because not everybody is willing to install everything on
drive "C:".


Reinhard Kotucha                            Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                    mailto:reinhard.kotucha at web.de

More information about the tex-live mailing list