[luatex] Putting an image in a box

Michael Talbot-Wilson mtw at view.net.au
Sun Nov 11 08:46:20 CET 2012


I'm trying to learn how to use luatex but not getting far.  I guess
for everyone else it's obvious how to do this but I can't see it.

I'd like to read a PDF image file and put it in a TeX box, just like

\pdfximage {myimage.pdf}
\setbox8\hbox{\pdfrefximage \pdflastximage}

But I'd like lua to look up the file name, e.g. assign it to the
variable the_name, then use something like

a = img.new()
a.filename = the_name
n = img.node(a)
tex.setbox(8, n)

But the last triggers an error:

This is LuaTeX, Version beta-0.70.2-2012062812 (TeX Live 2012)
  \write18 enabled.
(./b7904.tex
! LuaTeX error <\directlua >:1: setbox: incompatible node type
(pdf_refximage)

stack traceback:
         [C]: in function 'setbox'
         <\directlua >:1: in main chunk.
l.76 }

Can it be done with pdf.obj instead?

n = pdf.obj("file", the_name)

But all I can see then is pdf.refobj(n) "so the object will be written
out".  I don't want it written out, I want it in box8.

I'd hope that pdf.refobj() could do something like the second pdftex
line above.

Even more I'd hope that obj.setbox() would work with a pdf_refximage
node, just as \hbox{\pdfrefximage \pdflastximage}, if I understand
rightly, as the code seems to say, works with a pdf_refximage.

Given such a node, how do you put it in a box?

Okay, forget nodes.  Given a lua variable containing a PDF filename,
how do you put the contents of that file in a TeX box?


More information about the luatex mailing list