[luatex] Behavior of node lists.

Hans Hagen pragma at wxs.nl
Fri Nov 9 21:44:48 CET 2012

On 11/9/2012 8:48 PM, Stephan Hennig wrote:
> Am 08.11.2012 23:09, schrieb Hans Hagen:
>> On 11/8/2012 10:21 PM, Stephan Hennig wrote:
>>> That is, the first argument <head> is actually never needed.  Though, on
>> maybe in your code, but in mine it's needed in most cases
> Interesting, could you please give a use-case?  Mine is to insert
> whatsit nodes to store additional information in a node list.  And I'm
> inserting that only behind valid nodes.  Then I was puzzled seeing head
> is needed to insert a node, which is (now was) not available at that point.

if you insert in a node list that represents a paragraph then you're 
normally doing things after the head node (being a par whatsit) but if 
you want to insert your whatsit in front of a head of an hbox list then 
you insert before head and need to set the new head of that box to point 
to your whatsit.

concerning 'valid' ... in principle each node had better be a valid one

> | The return values are the (potentially mutated) head and the node
> | new, set up to be part of the list (with correct next field).
> Does that mean, after calling insert_after, head and new can be
> different nodes that that given as argument to the function?  If only
> fields in the original nodes are updated, what's the purpose of
> returning the nodes again?

after and before have a consistent similar interface so you can make 
'generic' functions that get insert_before or insert_after passed, so 
it's mostly about consistency in interfaces

the advantage of passing head to insert_after is that when head is nil 
at the start of whatever you do, you get a head back:

-- head can have a value or can be nil, maybe because the head
-- node was deletes as part of an earlier action

head, n = node.insert_after(head,n,somenewnode)

it saves you an

if not head then
   head = n


> Second, when inserting nodes into a deeply nested node list, is the head
> argument to insert_after the head of the current branch (latest hlist or
> vlist head) or the top-level head of the node list?

always the head of the 'current' list


                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl

More information about the luatex mailing list