Matthijs Kooijman wrote:
Hi all,

I'm wondering if there is any way to get the width of some TeX (or rather,
ConTeXt) expression inside lua, to do some math with it and output it again.

I've found the tex macro \setwidthof, which served me well at first, but I
need to do some more complex things with this widths (like taking the maximum
value of a bunch of widths and using that again in some other places).

\startluacode
function document.step_one(str)
    tex.sprint("\\setbox0\\hbox{",str,"}")
    tex.sprint("\\ctxlua{document.step_two(0)}")
end
function document.step_two(n)
    tex.sprint("width: ",tex.wd[0])
end
\stopluacode

\starttext

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

\box0

\stoptext


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

Reply via email to