[luatex] prev field in discretionary nodes

Taco Hoekwater taco at elvenkind.com
Mon Jan 20 11:37:15 CET 2014

On 19 Jan 2014, at 23:11, Stephan Hennig <mailing_list at arcor.de> wrote:

> After some tinkering, I eventually refrained from reusing the cut node
> list and used node.insert_before to insert the final discretionary node
> instead of the hand-weaving, applying both changes at once.  That
> worked, but let the original problem in the dark for me.  This leads me
> to another question:
>  What are best practices for node list manipulation?

insert_before and insert_after, definitely. 

> Is reusing node lists in general safe?  

Assuming you are certain that there are no internal TeX references
to that node list left after your manipulation. Otherwise no. And you have
to be aware of the fact  that during paragraph line breaking and page 
building internal references to node ids are kept in auxiliary arrays 
outside of your control.

> When does one better operate on node list copies?

See above, but in case of doubt, I would always make a copy. Leaking
a few nodes at the end of the run is better than crashing :)

> Can nodes be linked manually by manipulating next and
> prev fields?  

In principle, yes.

> Why do you better use node.insert_before/after even when
> not changing head?  …

Because it is easy to forget a prev or next, but also because 
insert_before / insert_after actually check that prev and next
are valid (active) nodes.

Best wishes,

More information about the luatex mailing list