[luatex] How to pass a box from TeX to lua
Paul Isambert
zappathustra at free.fr
Fri Jan 13 08:40:11 CET 2012
Andreas Matthias <andreas.matthias at gmail.com> a écrit:
>
> \directlua {%
> function out(t)
> x = node.vpack(t)
> node.write(x)
> end
> }
>
> \def\foo{%
> \directlua {%
> s = node.new(node.id('glyph'))
> s.char = 97
> s.font = 1
> out(node.hpack(s))
> }}
> \foo
>
>
> This code creates an hbox that is passed to function `out' which
> then packs everything into a vbox. Fine. But now I would like
> to do the first part (creation of the hbox) in TeX and the second
> part (creation of the vbox) in lua. The following code doesn't
> work but it might show what I'm trying to do.
>
>
> \def\bar#1{%
> \directlua {
> out(#1)
> }}
> \bar{\hbox{a}}
>
>
> How can this be done?
Use a box register, assign your box to it, and retrieve it in Lua:
\newbox\mybox
\def\bar#1{%
\setbox\mybox=#1%
\directlua {
out(tex.box.mybox)
}}
\bar{\hbox{a}}
If you \mybox doesn't have any other use, or is considered a scratch box
anyway, you don't need grouping.
Best,
Paul
More information about the luatex
mailing list