michal-h21 / luatex-harfbuzz-shaper

Experimental text shaping in LuaTeX using Harfbuzz library
10 stars 0 forks source link

Is it strictly required to generate and require hb_paths.lua #15

Closed deepakjois closed 8 years ago

deepakjois commented 8 years ago

I am looking into the package searching mechanism in Lua and LuaTeX (See references below).

I have these two files:

doc.lua:

-- Print out the package path
texio.write('\n\n')
texio.write_nl("Initial package.path:"..package.path)
texio.write_nl("Initial package.cpath:"..package.cpath)
texio.write_nl("No. of searchers: "..#package.searchers)
texio.write_nl('\n\n')

doc.tex:

\directlua { tex.enableprimitives('',tex.extraprimitives()) }
\directlua { dofile('doc.lua') }

The output that I get on OS X is:

This is LuaTeX, Version beta-0.80.1 (TeX Live 2015) (rev 5253)  (format=luatex 2015.12.12)  24 DEC 2015 12:48

…

Initial package.path: /usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?
/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua

Initial package.cpath: /usr/local/lib/lua/5.2/?.so;/usr/local/lib/lua/5.2/loada
ll.so;./?.so
No. of searchers: 4

…

So in short, the package.path and package.cpath values are already set to the correct value. It seems we don’t need to do the awkward step make make_paths and then require 'hb_paths'. We can just modify the package.searchers table to use a custom loading function that uses the existing package.path and package.cpath.

References:

  1. http://www.lua.org/manual/5.2/manual.html#pdf-package.searchers
  2. LuaTeX Manual, Section 2.2, Lua behavior
michal-h21 commented 8 years ago

I've got the same output on Fedora, the problem is that it is incorrect, these directories doesn't exist here. Correct directories are listed with luarocks path. Because we can't call arbitrary commands from luatex without -shell-escape option, it needs to be saved, which is done with make_paths at install time.

The other problem is that luatex uses kpse library for locating Lua files, we fix that in hb_lualoader.lua and add loader which also search in package.path and package.cpath

deepakjois commented 8 years ago

On Thu, Dec 24, 2015 at 3:45 PM, Michal Hoftich notifications@github.com wrote:

I've got the same output on Fedora, the problem is that it is incorrect, these directories doesn't exist here. Correct directories are listed with luarocks path. Because we can't call arbitrary commands from luatex without -shell-escape option, it needs to be saved, which is done with make_paths at install time.

I don’t understand when you say it is ‘incorrect’. Maybe on Fedora things are different. But on the Mac for example, I can find harfbuzz.lua in /usr/local/share/lua/5.2/ and luaharfbuzz.so in /usr/local/lib/lua/5.2/. These are the same paths that are set by default, and also reported by luarocks path.

The other problem is that luatex uses kpse library for locating Lua files, we fix that in hb_lualoader.lua and add loader which also search in package.path and package.cpath

Yes, I understand that part. I was just trying to find a way to avoid the awkward make make_paths step.

michal-h21 commented 8 years ago

I don’t understand when you say it is ‘incorrect’. Maybe on Fedora things are different. But on the Mac for example, I can find harfbuzz.lua in /usr/local/share/lua/5.2/ and luaharfbuzz.so in /usr/local/lib/lua/5.2/. These are the same paths that are set by default, and also reported by luarocks path.

it is incorrect in Fedora TeX Live. When I modify doc.lua to run under normal Lua:

print("Initial package.path:"..package.path)
print("Initial package.cpath:"..package.cpath)
print("No. of searchers: "..#package.searchers)

then the output with lua is:

Initial package.path:/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;/usr/lib64  /lua/5.2/?.lua;/usr/lib64/lua/5.2/?/init.lua;./?.lua
Initial package.cpath:/usr/lib64/lua/5.2/?.so;/usr/lib64/lua/5.2/loadall.so;./?.so
No. of searchers: 4

and with luatex:

Initial package.path:/usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua
Initial package.cpath:/usr/local/lib/lua/5.2/?.so;/usr/local/lib/lua/5.2/loadall.so;./?.so
No. of searchers: 4

the problem is that directories /usr/local/share/lua/ and /usr/local/lib/lua/ don't exist, the correct values are these used in lua. But even normal Lua paths aren't enough, as Luarocks may use local directory in user's home dir. luarocks path:

export LUA_PATH='/home/michal/.luarocks/share/lua/5.2/?.lua;/home/michal/.luarocks/share/lua/5.2/?/init.lua;/usr/share/lua/5.2/?.lua;/usr/share/lua/5.2/?/init.lua;/usr/lib64/lua/5.2/?.lua;/usr/lib64/lua/5.2/?/init.lua;./?.lua'
export LUA_CPATH='/home/michal/.luarocks/lib/lua/5.2/?.so;/usr/lib/lua/5.2/?.so;/usr/lib64/lua/5.2/?.so;/usr/lib64/lua/5.2/loadall.so;./?.so'
deepakjois commented 8 years ago

Ok, I understand now. Thanks. I will close the issue.