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

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

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