[Dev-luatex] How to insert at start of hlist/vlist?

Hans Hagen pragma at wxs.nl
Sun Dec 9 00:11:39 CET 2007

Hi Heiko

> On Sat, Dec 08, 2007 at 12:31:59AM +0100, Hans Hagen wrote:
>> Heiko Oberdiek wrote:
>>> Hello,
>>> I have some trouble to insert something at the start
>>> of a list.
>> weird message indeed; this works
>>    do
>>      local hlist = tex.box[0]
>>      local pdf_literal = node.new(8,8)% \pdfliteral
>>      pdf_literal.mode = 2 % direct
>>      pdf_literal.data = "1 0 0 rg 1 0 0 RG"
>>      pdf_literal.next = hlist.list
>>      hlist.list = pdf_literal
>>    end
> Thanks.
> What about "prev"?
> * insert_before seems to set this entry, too.
> * I have seen, the head of the list (variable "hlist/tex.box[0]") has
>   a node "prev" with id "temp" in the example (I have also
>   seen "attribute_list", "if_stack" and the expected "nil").
>   Is this a bug not being "nil"?
>   Or must the new head node inherit the prev entry from the
>   old head node?

at the tex end double linked lists are not needed, but at the lua end it 
can be handy and the insertion functions assume it; a handy helper is ...

tail = node.slide(head)

sliding == make a list double linked

> What about global/local box contents?

always global, same for registers; lua calls have no grouping

so, when using boxes with lua, reserve dedicated ones

> Or is the copy strategy more safe, if two box registers are used?
>   \begingroup
>     \setbox1=\box1
>   \endgroup
>   % box 1 is void and takes the result
>   \setbox0=\hbox{XY}
>   \directlua0{
>     do
>       local hlist = node.copy(tex.box[0])
>       % manipulating hlist
>       tex.box[1] = hlist
>     end
>   }%
>   \setbox0=\box1

copying indeed, or using a dedicated set for lua manipulations

> But insert_before also don't work on the copied list.

because of a bug -)

> And I would want to avoid copying the whole list, because
> it would mean copying the whole document:

assigning the page box to a private (for lua) box is fast

btw, in practice pages do not have that many nodes and the node.copy and 
  access calls (node.next and such) are quite optimized by now

> I am experimenting with color support based on an attribute.
> At some time the shipout material needs transforming to add
> pdf_literals with color setting. BTW, I haven't found a
> direct callback function for this (page shipout/xform generation).

next year callnbacks for shipout and backend related things will be 
added (after mplib, so after februari)

the vpack calbacks, in addition to head, get additional information 
passed so sometimes that can be used to determine what to do

> The way via a box register requires catching the shipout box
> at TeX level (package atbegshi). But \pdfxform can't catched
> in an easy and reliable way.

pdf backend functions will be implemented next year


                                           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

More information about the dev-luatex mailing list