16

I've done all of the searching that I can, and I think I've read the right answer, but am too dumb to know that I read it.

I can't seem to figure out the magic tricks to get Lua modules, installed by luarocks or by any other means, to show up in LuaLaTeX. So here is a minimal:

%!TEX TS-program = lualatex
\documentclass{article}
\usepackage{luatexbase}
\usepackage{luacode}
\begin{document}

    \directlua{package.path = "~/.luarocks/share/lua/5.1/?.lua;~/.luarocks/share/lua/5.1/?/init.lua;" .. package.path }

    \directlua{require('pl')}
    \directlua{require('htk')}

    \directlua{tex.sprint(package.path)}

    the standard approximation $\pi = \directlua{tex.sprint(math.pi)}$

\end{document}

In installed htk using luarocks with the command luarocks --local install HTK . The Penlight module was installed the same way, except with penlight. Penlight uses the "pl/submodulename" scheme and htk uses just "htk.lua" in the ~/.luarocks/share/lua/5.1 directory.

The log output is:

./luamoduleload.tex:9: LuaTeX error <\directlua >:1: module 'pl' not found:
    no field package.preload['pl']
    [luatexbase.loader] Search failed
    [kpse lua searcher] file not found: 'pl'
    [kpse C searcher] file not found: 'pl'
stack traceback:
    [C]: in function 'require'
    <\directlua >:1: in main chunk.
l.9     \directlua{require('pl')}

The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.

./luamoduleload.tex:10: LuaTeX error <\directlua >:1: module 'htk' not found:
    no field package.preload['htk']
    [luatexbase.loader] Search failed
    [kpse lua searcher] file not found: 'htk'
    [kpse C searcher] file not found: 'htk'
stack traceback:
    [C]: in function 'require'
    <\directlua >:1: in main chunk.
l.10    \directlua{require('htk')}

The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.

Would more of the log file be helpful?

In truth, if i just knew where to instal the lua modules that I want to use, I'd be a happy camper, especially if I don't need to do any magic tricks to get stand-alone lua scripts to work outside of LuaLaTeX.

Please let me know if I can be any clearer or if I'm not reading the right fine manuals. :)

-Andrew

  • Have you tried the CLUAINPUTS path? texmf.cnf says: % Lua needs to look for binary lua libraries distributed with packages. CLUAINPUTS = .;$SELFAUTOLOC/lib/{$progname,$engine,}/lua//. Perhaps you can add the location where luarocks adds libraries to CLUAINPUTS. – Aditya Mar 27 '11 at 20:34
  • So now that line looks like CLUAINPUTS = .;$SELFAUTOLOC/lib/{$progname,$engine,}/lua//;~/.luarocks/share/lua/5.1// and it appears to have no effect... Cry ;) – Andrew Starks Mar 28 '11 at 04:55
  • How about adding the .so file in the current directory to see if dynamic loading works at all. – Aditya Mar 28 '11 at 13:12
  • It does. If I drop the file into the project's directory it seems to work. – Andrew Starks Mar 28 '11 at 13:27
  • Could you please tell a bit more about this "pl"? What is the exact name (the extension) of the module? Where do you want to store it? A small complete example with a simple \directlua{require('pl')} and the log-file would be useful too. E.g. I can't understand where the reference to oberdiek.luatex.kpse_module_loader comes from. – Ulrike Fischer Mar 28 '11 at 14:34
  • Thanks Ulrike. Do the above edits work? – Andrew Starks Mar 28 '11 at 22:44
  • I just realized that your luarocks folder is in your home directory. I have not seen ~ in texmf.cnf files. Does it work if you replace ~ with $HOME or the complete path? – Aditya Mar 28 '11 at 23:13
  • yeah. That didn't work. Seems to have the same issue with the same error in the log file. I should also explicitly mention that the standard Lua interpreter seems to find everything, just fine. :P I wonder, should I give up and just install everything within the project's tree? That seems like a crappy way to do it. :P I wonder if anyone has the "best practices way" that I should just use. I don't mind bending my methods toward a standard. – Andrew Starks Mar 29 '11 at 13:42
  • Within the .tex file, if I edit package.path to use \$HOME, I get TeX capacity exceeded, sorry [input size=5000]. – Andrew Starks Mar 29 '11 at 13:49
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). – Martin Schröder Jan 26 '12 at 23:22
  • 5

2 Answers2

2

This line:

 \directlua{package.path = "~/.luarocks/share/lua/5.1/?.lua;~/.luarocks/share/lua/5.1/?/init.lua;" .. package.path }

looks suspicious. I think you need to have \noexpands before the tilde characters, otherwise the expansion of the ~ macro ends up as part of package.path.

\directlua{package.path = "\noexpand~/.luarocks/share/lua/5.1/?.lua;\noexpand~/.luarocks/share/lua/5.1/?/init.lua;" .. package.path }
Taco Hoekwater
  • 13,724
  • 43
  • 67
  • While this is true, it doesn't matter as LuaLaTeX doesn't use package.path (or package.cpath) at all. See https://tex.stackexchange.com/a/30444/250119 – user202729 Nov 01 '21 at 13:30
1

I know this is a very old question, but for completeness..

\usepackage{luapackageloader}

and place your Lua packages in you texmf directory (I put mine with the executable files), might have to refresh the filename database.

Eg: C:\Users\PERSON\AppData\Local\Programs\MiKTeX\miktex\bin\x64\youPackagesHere

  • This solution is also already mentioned in https://tex.stackexchange.com/a/372134/250119 (which also explains what the package do as well as its documentation/ctan package), and also handle C package correctly. – user202729 Nov 01 '21 at 13:36