you can use the builder callbacks to implement a before_display handler so there is no need to add something (like expanding a token list)
Amazing things can by done within lua node processing. I could find these places and remove the empty lines and edit the skips. But lua processing will cost more time than primitives. And it will be easy to trace the tex side. "before_display" seems to be hooked some where at \everydisplay place because the lastskip is already gone. Check the example: \documentclass{article} \directlua{ local function fix_display_glue(extrainfo) if extrainfo == "before_display" then print ("lastskip", tex.lastskip.width) end end luatexbase.add_to_callback('buildpage_filter', fix_display_glue, 'fix display glue') } \begin{document} \showthe\lastskip \directlua{print ("lastskip", tex.lastskip.width)} $$ equation+\$ $$ \showthe\lastskip \directlua{print ("lastskip", tex.lastskip.width)} $$ equation+\$ $$ \end{document} output is:
0.0pt. lastskip 0 lastskip 0 ..... ..... 6.0pt plus 3.0pt minus 3.0pt. lastskip 393216 lastskip 0