I'm working on a \graphicspath like feature for GregorioTeX and having some problems making \input@path work with our Lua code. Basically, while \input@path works for \input statements, before we input the file our Lua code first locates the file using kpse.find_file so that it can be checked to see if it is up to date (and regenerate it from the appropriate source file if not). The problem is that kpse.find_file does not seem to be aware of the definition of \input@path.

So my question is what do I need to do to pass the definition of \input@path over to Lua so that kpse.find_file will search those additional paths for the file it's looking for? Alternatively, is there another way of locating the file in the Lua code that is aware of \input@path?

Since this involves accessing multiple files, I've posted my MWE as a zip file with the appropriate directory structure.

  • The kpse environment variables (in your case TEXINPUTS, probably), are set up when luatex is started. I'm not sure whether the Lua kpse library can change the values on the fly. – egreg Jun 6 '19 at 15:05

\input@path is a very trivial system it just loops over the list until it finds something so if the list is aa/,bb/,cc/ and you are looking for file.foo then you want to do

kpse.find_file ("file.foo") or
kpse.find_file ("aaa/" .. "file.foo") or
kpse.find_file ("bbb/" .. "file.foo") or
kpse.find_file ("ccc/" .. "file.foo")

so all you need to do is pass in \input@path split it up to a Lua table then iterate through the table until you find the file

So... if the subdirectory zzz has a file test.foo we can find it using TeX or Lua via:


input_path = {""\expandafter\maketabl\input@path\relax}


\IfFileExists{test.foo}{\typeout{FILE is \@filef@und\space (TeX)}}

for i,k in pairs(input_path) do
fp=kpse.find_file(k .. f)
if (fp) then
print("FILE is " .. fp .. " (Lua)")


which makes the terminal output

FILE is zzz/test.foo  (TeX)
FILE is ./zzz/test.foo (Lua)
  • the number of z are back to normal ... – Ulrike Fischer Jun 6 '19 at 16:19
  • @UlrikeFischer one day I'll buy you a UK keyboard, then you too will be able to find z. – David Carlisle Jun 6 '19 at 16:20
  • but I wouldn't dare to use them, they are yours ;-) – Ulrike Fischer Jun 6 '19 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.