Re: [NTG-context] Getting the width of an expression inside lua

2009-11-02 Thread Matthijs Kooijman
Hi Hans,

thanks for the instant reply :-) I haven't tried your suggestion yet, but I've
got a few questions first.

 \startluacode
 function document.step_one(str)
 tex.sprint(\\setbox0\\hbox{,str,})
Would there be any danger of overwriting an existing box by doing this? I'm
not quite sure how this boxing thing works...

 tex.sprint(\\ctxlua{document.step_two(0)})
I guess this indirection is needed to force the \setbox command to be
expanded? I guess tex.sprint doesn't expand its arguments immediately, so just
putting document.step_two(0) instead of the entire tex.sprint(\\ctxlua...
won't work...

I'm using this from inside a pretty printer, so I'd have to think a bit about
how to set this up so things run inside the right context and stuff, but I
guess that should work out. Still slightly more complicated that a direct How
wide is this thing function, though.

 function document.step_two(n)
 tex.sprint(width: ,tex.wd[0])
 end
I gues you mean tex.wd[n] here, but whatever :-)

 \ctxlua{document.step_one(test {\\bf test} test)}
 
 \box0
Why is this \box0 needed? Just to show the test test test output? AFAICS, the
width of the box will be displayed always, even without this?

Gr.

Matthijs


signature.asc
Description: Digital signature
___
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
___


Re: [NTG-context] Getting the width of an expression inside lua

2009-11-02 Thread Hans Hagen

Matthijs Kooijman wrote:

Hi Hans,

thanks for the instant reply :-) I haven't tried your suggestion yet, but I've
got a few questions first.


\startluacode
function document.step_one(str)
tex.sprint(\\setbox0\\hbox{,str,})

Would there be any danger of overwriting an existing box by doing this? I'm
not quite sure how this boxing thing works...


well, you can allocate a box for that purpose


tex.sprint(\\ctxlua{document.step_two(0)})

I guess this indirection is needed to force the \setbox command to be
expanded? I guess tex.sprint doesn't expand its arguments immediately, so just
putting document.step_two(0) instead of the entire tex.sprint(\\ctxlua...
won't work...

I'm using this from inside a pretty printer, so I'd have to think a bit about
how to set this up so things run inside the right context and stuff, but I
guess that should work out. Still slightly more complicated that a direct How
wide is this thing function, though.


function document.step_two(n)
tex.sprint(width: ,tex.wd[0])
end

I gues you mean tex.wd[n] here, but whatever :-)


\ctxlua{document.step_one(test {\\bf test} test)}

\box0

Why is this \box0 needed? Just to show the test test test output? AFAICS, the
width of the box will be displayed always, even without this?


just try ..

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
-
___
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
___