ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Testing the changing dimensions of boxes (in cycles) via Lua
@ 2012-06-14 20:17 Jaroslav Hajtmar
  2012-06-15  7:41 ` luigi scarso
  0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Hajtmar @ 2012-06-14 20:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Testing the changing dimensions of boxes (in cycles) via Lua
  2012-06-14 20:17 Testing the changing dimensions of boxes (in cycles) via Lua Jaroslav Hajtmar
@ 2012-06-15  7:41 ` luigi scarso
  2012-06-15  8:04   ` Jaroslav Hajtmar
  0 siblings, 1 reply; 3+ messages in thread
From: luigi scarso @ 2012-06-15  7:41 UTC (permalink / raw)
  To: hajtmar, mailing list for ConTeXt users

On Thu, Jun 14, 2012 at 10:17 PM, Jaroslav Hajtmar <hajtmar@gyza.cz> wrote:
> 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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Testing the changing dimensions of boxes (in cycles) via Lua
  2012-06-15  7:41 ` luigi scarso
@ 2012-06-15  8:04   ` Jaroslav Hajtmar
  0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Hajtmar @ 2012-06-15  8:04 UTC (permalink / raw)
  To: luigi scarso; +Cc: mailing list for ConTeXt users

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
>    

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-15  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-14 20:17 Testing the changing dimensions of boxes (in cycles) via Lua Jaroslav Hajtmar
2012-06-15  7:41 ` luigi scarso
2012-06-15  8:04   ` Jaroslav Hajtmar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).