Inspired by some recent experiments on the subject, I'm trying to use texlua to automate the installation, done by multiple users, of a complex environment (multiple packages, classes and formats) on multiple computers running different OS and different distribution (TeXLive, MikTeX and MacTeX). LuaTeX appears to be the only program I can rely on to work in such conditions.

I need to copy some files somewhere in the $TEXMFHOME directory. So, I tried the following to print the local $TEXMFHOME path:

-- this is file texlua-file.lua
local kpse = require('kpse')

Run with texlua from /home/christophe/sandbox/lua, it gives me the following:

warning: kpathsea: configuration file texmf.cnf not found in these directories: /home/christophe/sandbox/lua:/home/christophe/sandbox/lua/share/texmf-local/web2c:/home/christophe/sandbox/lua/share/texmf-dist/web2c:/home/christophe/sandbox/lua/share/texmf/web2c:/home/christophe/sandbox/lua/texmf-local/web2c:/home/christophe/sandbox/lua/texmf-dist/web2c:/home/christophe/sandbox/lua/texmf/web2c:/home/christophe/sandbox:/home/christophe/sandbox/share/texmf-local/web2c:/home/christophe/sandbox/share/texmf-dist/web2c:/home/christophe/sandbox/share/texmf/web2c:/home/christophe/sandbox/texmf-local/web2c:/home/christophe/sandbox/texmf-dist/web2c:/home/christophe/sandbox/texmf/web2c:/home/christophe/../texmf-local/web2c:/home/christophe:/home/christophe/share/texmf-local/web2c:/home/christophe/share/texmf-dist/web2c:/home/christophe/share/texmf/web2c:/home/christophe/texmf-local/web2c:/home/christophe/texmf-dist/web2c:/home/christophe/texmf/web2c.

Besides I don't understand the need stated in the LuaTeX documentation for the line


how can I tell kpse where to look for the texmf.cnf file without knowing the actual settings of the local TeX distribution?

  • kpse.set_program_name('texlua')
    – egreg
    Commented Jun 9, 2014 at 14:18
  • @egreg It works! Thanks. I really don't understand that part of the doc: "Second, in TEXLUA mode, the initialization has to be done explicitly via the kpse.set_program_name function, which sets the KPATHSEA executable (and optionally program) name." So the KPATHSEA executable is texlua? BTW, can you turn your comment to an answer to that I can accept it?
    – cjorssen
    Commented Jun 9, 2014 at 14:21

1 Answer 1


Kpse variables such as TEXMFHOME or TEXINPUTS are not usually set in the environment, but are assigned a value at runtime, based on reading the configuration files named texmf.cnf with a certain order (see kpathsea documentation).

However, the Lua system embedded in LuaTeX doesn't use the library by default (the TeX part does). It can, however, load the kpse Lua library for querying kpse. This must however be initialized with some engine as argument to kpse.set_program_name because the kpse variables can be assigned different values according to the engine used; for instance, running texlua on

local kpse = require('kpse')

produces, on my system,


while changing pdftex into pdflatex outputs


Thus one can adapt the usage of kpse.expand_var() to different engines.

Note: I produced the output running a shell where the development version of TeX Live is used, which explains the 2014 bits.

You must log in to answer this question.

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