[Dev-luatex] \lastnodetype not working as expected in LuaTeX
patrick at gundla.ch
Sun Jun 10 23:44:09 CEST 2012
(More from Frank Mittelbach on this subject - he is not subscribed yet but will be ASAP)
I'm now fairly certain this this is a bug in the current implementation of linebreak_filter. What seems to happen is the following: when TeX builds a list (in this case a vertical list) it keeps track of it through a pointer to the head and to the tail of that list. Now when a paragraph is broken into lines those lines get appended to the current vertical list by the linebreaking algorithm and the tail pointer is updated to point to the new end of this list. However, if thelinebreak_filter replaces TeX's algorithm the material from that filter is appended to the list but the tail pointer is not changed. Thus in my example it still points to the node before the paragraph (which happens to be nil as the paragraph starts the vbox).
Fortunately this tail pointer is accessible and modifiable from Lua code, so there is a way to fix this. We can't do this in linebreak_filter, however, because the current luatex code that calls the filter expects the tail in precisely this wrong as it does some final checkup and changes.
But what we can do is to use the followup file post_linebreak_filter to do the work for us, because by then all these things have happened. So the workaround looks like this:
function hpack_paragraph (head)
h = node.hpack(head)
function fix_nest_tail (head)
tex.nest[tex.nest.ptr].tail = node.tail(head)
The second filter simply updates TeX's tail pointer in the current semantic nest to become the tail of the result produced from the line breaking. A bit nasty, but at least it allows to use thelinebreak_filter in the current implementation.
If you wonder what this this code does: without anything further it changes the output so that every paragraph is returned as a single line (and indentations like from itemize or similar environments are dropped) and inserts like footnotes or \vadjusts stay within those hboxes. So it needs a little more to become useful, but let your imagination run.
More information about the dev-luatex