I'm currently experimenting with the linebreak_filter
of luatex and when using it to change/replace the linebreaking algorithm the \lastnodetype
command stopped working.
A MWE is the following:
\def\partest{%
\directlua{%
function hpackparagraph (head)
return node.hpack(head)
end
callback.register("linebreak_filter", hpackparagraph)
}%
\par
}
\setbox0\vbox{ABC\par
{\tracingonline1\showboxbreadth\maxdimen\showboxdepth\maxdimen\showlists}%
\showthe\lastnodetype
}
\setbox0\vbox{ABC\partest
{\tracingonline1\showboxbreadth\maxdimen\showboxdepth\maxdimen\showlists}%
\showthe\lastnodetype
}
In a nutshell the \partest
command changes the paragraph breaking algorithm to simply pack the unbroken paragraph into an hbox and return that hbox unchanged to the vertical list (not useful standalone, but this is the shortest version that shows my problem).
So if you run this you get:
This is LuaTeX, Version beta-0.70.1-2011061421 (rev 4277)
restricted \write18 enabled.
(./lua-bug.tex
### internal vertical mode entered at line 13
\hbox(6.83331+0.0)x469.75499, glue set 427.9494fil, direction TLT
.\whatsit
..\localinterlinepenalty=0
..\localbrokenpenalty=0
..\localleftbox=null
..\localrightbox=null
.\hbox(0.0+0.0)x20.0, direction TLT
.\tenrm A
.\tenrm B
.\tenrm C
.\penalty 10000
.\glue(\parfillskip) 0.0 plus 1.0fil
.\glue(\rightskip) 0.0
prevdepth 0.0, prevgraf 1 line
### vertical mode entered at line 0
prevdepth ignored
! OK.
l.14 ...h\maxdimen\showboxdepth\maxdimen\showlists
}%
?
> 1.
l.15 \showthe\lastnodetype
?
### internal vertical mode entered at line 18
\hbox(6.83331+0.0)x41.8056, direction TLT
.\whatsit
..\localinterlinepenalty=0
..\localbrokenpenalty=0
..\localleftbox=null
..\localrightbox=null
.\hbox(0.0+0.0)x20.0, direction TLT
.\tenrm A
.\tenrm B
.\tenrm C
.\penalty 10000
.\glue(\parfillskip) 0.0 plus 1.0fil
prevdepth ignored
### vertical mode entered at line 0
prevdepth ignored
! OK.
l.19 ...h\maxdimen\showboxdepth\maxdimen\showlists
}%
?
> -1.
l.20 \showthe\lastnodetype
As you can see the \lastnodetype
for the first test is 1
(hbox) as expected. But for the second it is -1
which means current list has no nodes.
This of course is not correct as it does have an hbox inside the one returned by my primitive linebreak_filter
. The only difference between the two lists that one can observe is that in the first one the hbox is 469pt wide while in the second one it is at its natural width, but this is expected as it was packed this way.
My guess is that the node list that is placed by the standard paragraph builder is updating the data structure for \lastnodetype
but that doesn't happen is such a filter is applied which feels like a bug. Or am I missing something fundamental here?
Update
Consistent with the problem the command \lastbox
also returns a void box in the case where the linebreak_filter
is applied, i.e., \setbox0\lastbox \showbox0
fails to return the last object in the current list.