[luatex] Interfere with page breaking to balance pages

Patrick Bergner mail at patrickbergner.de
Thu Oct 18 14:04:54 CEST 2012

Thank you all for your comments, advises and explanations.

The tex.box.AtBeginShipoutBox approach is nice, although I'm a bit
ashamed I did not come up with it myself. The shipout cancellation also
works (the back slash had to be escaped though).

For the record, my \AtBeginShipout hook now reads something like

balancepages = function( page )
  if page < 2 then return end
  if page % 2 == 0 then
    tex.setbox( 'global', 142, node.copy_list( tex.box.AtBeginShipoutBox ) )
    tex.print( '\\AtBeginShipoutDiscard' )
    tex.setbox( 'global', 143, node.copy_list( tex.box.AtBeginShipoutBox ) )
    tex.print( '\\AtBeginShipoutDiscard' )
    -- page balancing to be done here
    tex.shipout( 142 )
    tex.shipout( 143 )

Now let's see how far I get with the actual page balancing.


On general page breaking callbacks: I'm with Paul in that something like
a pre_shipout_filter with the possibility to cancel/delay shipout would
be desirable. Basically what pre_linebreak_filter does on paragraph level.


Am 18.10.2012 10:11, schrieb Taco Hoekwater:
> On the original problem: TeX's page breaking is more than a little
> tricky to get 'into' from the Lua end because there are a bunch
> of interwoven C functions that mutually depend on each other's
> calculations. In fact, that is why the current interface is so
> weird: it closely follows what the internals do.
> When we exposed the current situation, it was not at all
> clear what a 'good' interface would look like (and personally, I
> am still not sure). So, any constructive thoughts on that would
> be welcome.
> A better, cleaner solution would be nice to have, but whatever
> form it takes, it will require some digging and a bit of a rewrite in
> the internal code. And to make sure at the same time that something
> important does not break is tricky, which is also part of why it has
> not been done yet.
> Best wishes,
> Taco

More information about the luatex mailing list