dofile, require and kpathsea
Hello, during the weekend, I wrote a little bit of code using external Lua files (since \directlua requires matching braces in the Lua code). I loaded this code using dofile or require. This worked perfectly when the .lua file was in the same directory as the .tex file, otherwise it was not found (even though kpsewhich could find it). I know that Lua's require uses its own search path, and I assume from my results that LuaTeX does not change this behaviour to use kpathsea. I now wonder if there are plans to change that. IMO this should be done, since LuaTeX embeds Lua in a very specific environment which searches for files using kpathsea, not a simple path set as an environment variable. What do you think? Jonathan
Jonathan Sauer wrote:
I now wonder if there are plans to change that. IMO this should be done, since LuaTeX embeds Lua in a very specific environment which searches for files using kpathsea, not a simple path set as an environment variable.
What do you think?
This should work: dofile(kpse.find_file('myfile.lua')) Best wishes, Taco
Jonathan Sauer wrote:
Hello,
during the weekend, I wrote a little bit of code using external Lua files (since \directlua requires matching braces in the Lua code). I loaded this code using dofile or require.
This worked perfectly when the .lua file was in the same directory as the .tex file, otherwise it was not found (even though kpsewhich could find it).
I know that Lua's require uses its own search path, and I assume from my results that LuaTeX does not change this behaviour to use kpathsea.
I now wonder if there are plans to change that. IMO this should be done, since LuaTeX embeds Lua in a very specific environment which searches for files using kpathsea, not a simple path set as an environment variable.
What do you think?
there will be a LUAINPUTS variable in texmf.cnf and then you can use that to specify paths since those lua files are tex relates, you can just put 'm in the tex path and use the tex related kpse lookup "dofile" etc will not be adapted to kpse based loading since in principle this is pure lua, but you can easily write a wrapper, say "doluatexfile" that first locates the file (using kpse) and then does it. ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hello,
[...] "dofile" etc will not be adapted to kpse based loading since in principle this is pure lua, but you can easily write a wrapper, say "doluatexfile" that first locates the file (using kpse) and then does it.
I disagree about this being the correct way: IMO, TeX uses some kind of virtual file system: All files, as far as TeX The Program is concerned, are in the same directory, and kpathsea is simply a way of mapping real directories onto this virtual one. When I say "\input myfile", TeX simply tries to open this file by calling a system-specific routine -- in web2c one that first uses kpathsea to resolve the real file name and path, in OzTeX one which uses a config file directly etc. You can "escape" this virtual file system by specifying a full path name, or partially by specifying a partial path name (IIRC, I am not quite sure if the latter is correct). Still, normally you are inside the virtual file system TeX uses to find and read files -- all files, .tex files as well as fonts, graphics etc. Now, Lua resides inside TeX, and therefore I think it should use this same virtual file system when accessing files, meaning kpathsea. Otherwise, two parts of LuaTeX behave differently. So IMO changing dofile to use kpathsea would not change its "pure Lua" status, but simply adapt it to the host environment. Jonathan
Jonathan Sauer wrote:
Hello,
[...] "dofile" etc will not be adapted to kpse based loading since in principle this is pure lua, but you can easily write a wrapper, say "doluatexfile" that first locates the file (using kpse) and then does it.
I disagree about this being the correct way: IMO, TeX uses some kind of virtual file system: All files, as far as TeX The Program is concerned, are in the same directory, and kpathsea is simply a way of mapping real directories onto this virtual one. When I say "\input myfile", TeX simply tries to open this file by calling a system-specific routine -- in web2c one that first uses kpathsea to resolve the real file name and path, in OzTeX one which uses a config file directly etc.
You can "escape" this virtual file system by specifying a full path name, or partially by specifying a partial path name (IIRC, I am not quite sure if the latter is correct).
Still, normally you are inside the virtual file system TeX uses to find and read files -- all files, .tex files as well as fonts, graphics etc. Now, Lua resides inside TeX, and therefore I think it should use this same virtual file system when accessing files, meaning kpathsea. Otherwise, two parts of LuaTeX behave differently.
So IMO changing dofile to use kpathsea would not change its "pure Lua" status, but simply adapt it to the host environment.
the tex part of luatex should behave as tex (tex manual), the lua part as lua (lua manual) and glue between them (luatex manual) this is what callbacks are for: that way you can define your own preferences; actually, you can redefine dofile originaldofile = dofile function dofile(name) return originaldofile(kpse.find_file(name)) end or whatever you like. This is the whole idea behind luatex ... users and macro writers can implement their own solutions which prevents endless discussions about what should be implemented how/when ... each can implement his/her own preferences on top of core functionality. I ca even imagine that someone does *not* want to look into the places where tex files are -) (btw, the same is true for reading from zip files ... the tools are there but you need to wrote you rown glue code) actually, this virtual file system is indeed virtual in the sense that one can replace it completely by another one and in such a situation dofile may be reimplemented differently btw, lua files can live in areas that are not considered tex input, for instance in texmf/scripts/<program>/lua or whatsoever I suppose that macro packages will behave consistently and define some rules for writers of extensions. (At least this what i do for context). Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Jonathan Sauer
-
Taco Hoekwater