Hi, Taco: In TeX's Packaging algorithm, TeX wraps lists into boxes. Knuth create two functions, hpack (p,w,m) and vpack (p,w,m)= vpackage(p,w,m,max_dimen) to solve this problem. In the LuaTeX manual, (4.1.3.13), only node.hpack is given. maybe we should also write something called node.vpack? I wrote one for LuaTeX since I need it in my document project. I think it will be useful to others too. The code is easy to write by following yours and here is the patch: yue@localhost ~/luatex $ svn diff Index: src/texk/web2c/luatexdir/lua/lnodelib.c =================================================================== --- src/texk/web2c/luatexdir/lua/lnodelib.c (revision 1985) +++ src/texk/web2c/luatexdir/lua/lnodelib.c (working copy) @@ -496,6 +496,32 @@ return 1; } +/* build a vbox */ + +static int lua_nodelib_vpack(lua_State * L) +{ + halfword n, p; + char *s; + integer w = 0; + int m = 1; + n = *(check_isnode(L, 1)); + if (lua_gettop(L) > 1) { + w = lua_tointeger(L, 2); + if (lua_gettop(L) > 2 && lua_type(L, 3) == LUA_TSTRING) { + s = (char *) lua_tostring(L, 3); + if (strcmp(s, "additional") == 0) { + m = 1; + } else { + m = lua_tonumber(L, 3); + } + } + } + p = vpackage(n, w, m, max_dimen); + lua_nodelib_push_fast(L, p); + return 1; +} + + /* create a hlist from a formula */ static int lua_nodelib_mlist_to_hlist(lua_State * L) @@ -3202,6 +3228,7 @@ {"copy", lua_nodelib_copy}, {"copy_list", lua_nodelib_copy_list}, {"hpack", lua_nodelib_hpack}, + {"vpack", lua_nodelib_vpack}, {"mlist_to_hlist", lua_nodelib_mlist_to_hlist}, {"family_font", lua_nodelib_mfont}, {"has_attribute", lua_nodelib_has_attribute}, btw, I think the original code buggy, shouldn't it be something like this? yue@localhost ~/luatex $ svn diff Index: src/texk/web2c/luatexdir/lua/lnodelib.c =================================================================== --- src/texk/web2c/luatexdir/lua/lnodelib.c (revision 1985) +++ src/texk/web2c/luatexdir/lua/lnodelib.c (working copy) @@ -482,13 +482,24 @@ n = *(check_isnode(L, 1)); if (lua_gettop(L) > 1) { w = lua_tointeger(L, 2); - if (lua_gettop(L) > 2 && lua_type(L, 3) == LUA_TSTRING) { - s = (char *) lua_tostring(L, 3); - if (strcmp(s, "additional") == 0) { - m = 1; - } else { + if (lua_gettop(L) > 2){ + if (lua_type(L, 3) == LUA_TSTRING) { + s = (char *) lua_tostring(L, 3); + if (strcmp(s, "additional") == 0) + m = 1; + else if (strcmp(s,"exactly") == 0) + m = 0; + else { + lua_pushstring(L, "3rd argument should be either additional or exactly"); + lua_error(L); + } + } + + else if (lua_type(L, 3) == LUA_TNUMBER) { m = lua_tonumber(L, 3); - } + }else{ + lua_pushstring(L, "incorrect 3rd argument"); + } } } p = hpack(n, w, m); @@ -496,6 +507,42 @@ return 1; } +/* build a vbox */ +static int lua_nodelib_vpack(lua_State * L) +{ + halfword n, p; + char *s; + integer w = 0; + int m = 1; + n = *(check_isnode(L, 1)); + if (lua_gettop(L) > 1) { + w = lua_tointeger(L, 2); + if (lua_gettop(L) > 2){ + if (lua_type(L, 3) == LUA_TSTRING) { + s = (char *) lua_tostring(L, 3); + if (strcmp(s, "additional") == 0) + m = 1; + else if (strcmp(s,"exactly") == 0) + m = 0; + else { + lua_pushstring(L, "3rd argument should be either additional or exactly"); + lua_error(L); + } + } + + else if (lua_type(L, 3) == LUA_TNUMBER) { + m = lua_tonumber(L, 3); + }else{ + lua_pushstring(L, "incorrect 3rd argument"); + } + } + } + p = vpackage(n, w, m, max_dimen); + lua_nodelib_push_fast(L, p); + return 1; +} + + /* create a hlist from a formula */ static int lua_nodelib_mlist_to_hlist(lua_State * L) @@ -3202,6 +3249,7 @@ {"copy", lua_nodelib_copy}, {"copy_list", lua_nodelib_copy_list}, {"hpack", lua_nodelib_hpack}, + {"vpack", lua_nodelib_vpack}, {"mlist_to_hlist", lua_nodelib_mlist_to_hlist}, {"family_font", lua_nodelib_mfont}, {"has_attribute", lua_nodelib_has_attribute}, yue@localhost ~/luatex $ Yue Wang
Yue Wang wrote:
Hi, Taco:
In TeX's Packaging algorithm, TeX wraps lists into boxes. Knuth create two functions, hpack (p,w,m) and vpack (p,w,m)= vpackage(p,w,m,max_dimen) to solve this problem. In the LuaTeX manual, (4.1.3.13), only node.hpack is given. maybe we should also write something called node.vpack?
I wrote one for LuaTeX since I need it in my document project. I think it will be useful to others too. The code is easy to write by following yours and here is the patch:
fyi: vpack is on the agenda for later (probably after the complete rewrite to cweb) quite certainly vpack will demand a rewrite of core code as it has to deal with quite some related things as well it's no problem of course to use your variant locally for a while, but be prepared for a different interface 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 -----------------------------------------------------------------
Hi, Hans:
but IMHO hpack is still buggy. see the second diff.
Yue Wang
On Wed, Mar 11, 2009 at 11:43 PM, Hans Hagen
Yue Wang wrote:
Hi, Taco:
In TeX's Packaging algorithm, TeX wraps lists into boxes. Knuth create two functions, hpack (p,w,m) and vpack (p,w,m)= vpackage(p,w,m,max_dimen) to solve this problem. In the LuaTeX manual, (4.1.3.13), only node.hpack is given. maybe we should also write something called node.vpack?
I wrote one for LuaTeX since I need it in my document project. I think it will be useful to others too. The code is easy to write by following yours and here is the patch:
fyi: vpack is on the agenda for later (probably after the complete rewrite to cweb)
quite certainly vpack will demand a rewrite of core code as it has to deal with quite some related things as well
it's no problem of course to use your variant locally for a while, but be prepared for a different interface
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 -----------------------------------------------------------------
Yue Wang wrote:
but IMHO hpack is still buggy. see the second diff.
currently not all callbacks do proper checks for all arguments or even return values; some might even change esp when a wider context might be handy while dealing with such a list so don't rely too much on the interfaces to be kept the same in that respect (although the general idea will not change) (ps. some variants might show up eventually) i'm sure taco will have a look at you hpack patch -) 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 -----------------------------------------------------------------
Hans Hagen wrote:
Yue Wang wrote:
but IMHO hpack is still buggy. see the second diff.
currently not all callbacks do proper checks for all arguments or even return values; some might even change esp when a wider context might be handy while dealing with such a list so don't rely too much on the interfaces to be kept the same in that respect (although the general idea will not change) (ps. some variants might show up eventually)
i'm sure taco will have a look at you hpack patch -)
Patch applied, including the vpack section. Be warned though (like Hans says) that the node.vpack and node.hpack syntax will probably change (it needs some extensions to deal with adjustments and marks and such). Best wishes, Taco
participants (3)
-
Hans Hagen
-
Taco Hoekwater
-
Yue Wang