19

I have a lua file that I would use in many of my TeX's documents, loading it with dofile().

I thought it was ok if I simply put it in the (local) texmf tree*, but this doesn't work. Instead I have the following error message :

LuaTeX error cannot open the mycode.lua: No such file or directory

Is there any nice solution ?

  • I try to save the file in ~/Library/texmf, in ~/Library/texmf/tex, ~/Library/texmf/tex/latex and even in ~/Library/texmf/lua (I had to create the directory).
6
  • 1
    Where precisely did you save the file?
    – egreg
    Commented Oct 4, 2011 at 13:43
  • How do you load the file? require()? dofile()?
    – topskip
    Commented Oct 4, 2011 at 13:45
  • Placing file.lua in the same folder and loading with dofile("file.lua") works, but I'd also be interested in a more general solution (especially since dofile("/path/to/file.lua") doesn't seem to work).
    – scallops
    Commented Oct 4, 2011 at 13:51
  • @scallops of course it works, but it isn't a nice and general solution at all. So we have to wait for the gurus :)
    – PHL
    Commented Oct 4, 2011 at 13:53
  • 2
    require() should normally use kpse. E.g. require("fontspec.lua") finds fontspec.lua in tex\latex\fontspec. Commented Oct 4, 2011 at 14:12

3 Answers 3

13

dofile() expects full path (or path relative to current directory). You have to either use require() which will search TEXMF tree, or use kpse.find_file() and pass the returned path to dofile(). kpsewhich -show-path=lua should show the search path for lua files.

0
12

require() searches (TeXlive2011, LuaLaTeX) in these texmf subdirectories:

scripts/lualatex/lua/
scripts/luatex/lua
scripts/lua
scripts/lualatex
scripts/luatex
scripts
tex/lualatex
tex/latex
tex/luatex
tex/generic
tex
4
  • Where do you get this list from? Commented May 15, 2019 at 23:09
  • 1
    @FaheemMitha I don't remember. I believe it was something like KPATHSEA_DEBUG=-1 lualatex ... and parsed the output.
    – topskip
    Commented May 16, 2019 at 7:40
  • Oh. I thought maybe it was the output of some environmental variable. Commented May 16, 2019 at 8:35
  • See also tex.stackexchange.com/q/218855/250119 for explanation on how require() works.
    – user202729
    Commented Apr 2, 2022 at 6:57
11

require() should normally use kpse. E.g. require("fontspec.lua") finds fontspec.lua in tex\latex\fontspec.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .