gucci-on-fleek / lua-widow-control

(Lua)TeX package to automatically remove widows and orphans from any document
15 stars 1 forks source link

Inserts don't get moved when lua-widow-control moves the last line #27

Closed gucci-on-fleek closed 2 years ago

gucci-on-fleek commented 2 years ago

Lua-widow-control begins processing the page after it has already been broken, but before the output routine¹. This is after the inserts for the page have already been processed². If the last line has a footnote, the "footnote mark" will be moved, but the "footnote text" will remain on the previous page.

To fix this, we need to traverse through the last line and find the class and index of any ins nodes. Then we can iterate through tex.getbox(<insert class>), pull any boxes with a matching index, and put them back into tex.lists.page_ins_head.

The problem here is that so much of this information is removed after the page is broken. I'm pretty sure that all of the ins nodes are already gone, and the contents of \box<insert class> aren't labeled with the insert index. I might need to hook into build_page_insert to mark some boxes with a lua-widow-control attribute. This is a tricky one.

Reported in #26 by @hpvd.

¹ Lua callback: pre_output_filter ² TeXbook p. 123

Todo