Testing the changing dimensions of boxes (in cycles) via Lua
Hello ConTeXist and Lua experts. In a my Lua project I need to determine the changing dimensions of the TeX \vbox through Lua. In ConTeXt cycle, it works fine, but in the Lua cycle does not change the dimensions of the box. What am I doing wrong? Thank you. Jaroslav Hajtmar Here is my minimal example: -------------------------------------------------------------------- \newdimen\lsize \def\contentofvbox{\input ward } \def\setmybox{\setbox0=\vbox{\hsize=\lsize \contentofvbox}} \starttext Height of box via ConTeXt (works fine): \setmybox \lsize=5cm \dorecurse{3}{% \lsize=\dimexpr(\lsize+7mm) \setmybox height of box: \the\ht0\par width of box: \the\wd0\par \box0\par } \page ... and Height of box via Lua (do not working): \setmybox \ctxlua{ tex.dimen.lsize=5*72.27*65536/25.4 for i=1, 3 do tex.dimen.lsize=tex.dimen.lsize+7*72.27*65536/25.4 context([[\setmybox]]) local heightbox=tex.box[0].height local widthbox=tex.box[0].width heightbox=(heightbox*2.84527559067*25.4)/(72.27*65536) widthbox=(widthbox*2.84527559067*25.4)/(72.27*65536) context([[height of box:]]..heightbox.."pt\\par") context([[width of box:]]..widthbox.."pt\\par") context([[\box0\par]]) end } \stoptext
On Thu, Jun 14, 2012 at 10:17 PM, Jaroslav Hajtmar
Hello ConTeXist and Lua experts.
In a my Lua project I need to determine the changing dimensions of the TeX \vbox through Lua. In ConTeXt cycle, it works fine, but in the Lua cycle does not change the dimensions of the box. What am I doing wrong?
Thank you.
Jaroslav Hajtmar
Here is my minimal example: -------------------------------------------------------------------- \newdimen\lsize
\def\contentofvbox{\input ward }
\def\setmybox{\setbox0=\vbox{\hsize=\lsize \contentofvbox}}
\starttext
Height of box via ConTeXt (works fine):
\setmybox
\lsize=5cm \dorecurse{3}{% \lsize=\dimexpr(\lsize+7mm) \setmybox height of box: \the\ht0\par width of box: \the\wd0\par \box0\par }
\page
... and Height of box via Lua (do not working):
\setmybox
\ctxlua{ tex.dimen.lsize=5*72.27*65536/25.4
for i=1, 3 do tex.dimen.lsize=tex.dimen.lsize+7*72.27*65536/25.4 context([[\setmybox]]) local heightbox=tex.box[0].height local widthbox=tex.box[0].width heightbox=(heightbox*2.84527559067*25.4)/(72.27*65536) widthbox=(widthbox*2.84527559067*25.4)/(72.27*65536) context([[height of box:]]..heightbox.."pt\\par") context([[width of box:]]..widthbox.."pt\\par") context([[\box0\par]]) end }
\stoptext
Try this one: \def\setmybox{\setbox0=\vbox{\hsize=\lsize\input knuth \par}} \newdimen\lsize \lsize=5cm \starttext Height of box via ConTeXt (works fine): \setmybox \lsize=5cm \dorecurse{3}{% \lsize=\dimexpr(\lsize+7mm) \setmybox height of box: \the\ht0\par width of box: \the\wd0\par \box0\par } \page ... and Height of box via Lua (does it work ?): \setmybox \ctxlua{tex.dimen.lsize=5*72.27*65536/25.4;i=0} \dorecurse{3}{% \ctxlua{ --[=[ for i=1, 3 do ]=] i=i+1 tex.dimen.lsize=tex.dimen.lsize+7*72.27*65536/25.4 context([[\setmybox]]) } \ctxlua{ local heightbox=tex.box[0].height local widthbox=tex.box[0].width heightbox=(heightbox*2.84527559067*25.4)/(72.27*65536) widthbox=(widthbox*2.84527559067*25.4)/(72.27*65536) context(i..[[ height of box:]]..heightbox.."pt : "..(tex.box[0].height/2^16).."pt\\par") context(i..[[ width of box:]]..widthbox.."pt : "..(tex.box[0].width/2^16).."pt\\par") context([[\box0\par]]) --[=[ end ]=] } } \stoptext -- luigi
Thanks very much to Luigi. Your solution really works. Can you please explain why you doing this? My point is that if I have the LUA code in a separate lua file (loaded with the Contex via \directlua{dofile("filename.lua")}) (for example as a separate Lua function), so I'm probably not so to do (how you did it in your example). Or perhaps in this case there is any way? Thanks Jaroslav Dne 15.6.2012 9:41, luigi scarso napsal(a):
\def\setmybox{\setbox0=\vbox{\hsize=\lsize\input knuth \par}} \newdimen\lsize \lsize=5cm \starttext
Height of box via ConTeXt (works fine):
\setmybox
\lsize=5cm \dorecurse{3}{% \lsize=\dimexpr(\lsize+7mm) \setmybox height of box: \the\ht0\par width of box: \the\wd0\par \box0\par }
\page
... and Height of box via Lua (does it work ?):
\setmybox \ctxlua{tex.dimen.lsize=5*72.27*65536/25.4;i=0} \dorecurse{3}{% \ctxlua{ --[=[ for i=1, 3 do ]=] i=i+1 tex.dimen.lsize=tex.dimen.lsize+7*72.27*65536/25.4 context([[\setmybox]]) } \ctxlua{ local heightbox=tex.box[0].height local widthbox=tex.box[0].width heightbox=(heightbox*2.84527559067*25.4)/(72.27*65536) widthbox=(widthbox*2.84527559067*25.4)/(72.27*65536) context(i..[[ height of box:]]..heightbox.."pt : "..(tex.box[0].height/216).."pt\\par") context(i..[[ width of box:]]..widthbox.."pt : "..(tex.box[0].width/216).."pt\\par") context([[\box0\par]]) --[=[ end ]=] } } \stoptext
participants (2)
-
Jaroslav Hajtmar
-
luigi scarso