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