17

Background

I have seen Increase badness based on distance between float and reference which was closed as a duplicate of our generic How to influence the position of float environments like figure and table in LaTeX?, but I'm still curious about if and/or how penalties might be used to assist the float placement algorithm.

It seems to me that a penalty could be inserted at each page break for each float in the deferred float "holding queue" to provide a greater incentive for the algorithm to place a float as the distance from the insertion point grows.

With the current "greedy" algorithm, this might not have much effect, since deferred floats are placed essentially as soon as they fit in the specified float position(s), but I think it might make a difference for full-width floats in two-column documents and it could also interact with any \clubpenalty, \widowpenalty, and other penalties involving page-breaking locations.


Question

Is such an approach used in the current float placement algorithm? egreg's answer to What are penalties and which ones are defined? mentions a \@floatpenalty:

\@floatpenalty used for the float mechanism (in a quite involved way)

but doesn't have any more details, and this penalty is mentioned in neither David Carlisle's accepted answer to the penalty question nor Frank Mittelbach's accepted answer to How to influence the position of float environments like figure and table in LaTeX?


Follow-up Question

Penalty-enhanced approach to float placement in LaTeX3

  • Really think the 'bonus' here should be a separate question. What if you get a stellar 2e answer and an outstanding response from on of the 3 developers? (And the authors are not identical with each other, which is obviously possible.) Though the answer to the first might be 'read the TeX book', of course... – cfr Jan 31 '15 at 4:25
  • @cfr I considered that, but I didn't want my question to be closed as a duplicate of the general float-placement question just as the other one has been. – Paul Gessler Jan 31 '15 at 7:10
  • @cfr done; let me know if you have further suggestions. – Paul Gessler Jan 31 '15 at 7:25
15

Short answer no.

The timing of when the current float placement considers adding floats and the timing that things like \widowpenalty are constructed are completely different.

I suppose I could have mentioned \@floatpenalty but it is not really used as other penalties as a conditional hint in a scale of -10000 to 10000, and it is just a count register it is never used to set TeX primitive penalties like widowpenalty or \interlinepenalty it is always used to force a page break and just has conventional values such as -10001, -10002, -10003 which force an (internal) page break to trigger the output routine.

So \penalty-10003 for example forces at the primitive TeX level a page break which the latex output routine then sees was triggered by -10003 which tells it that it is from \marginpar or float so it does not ship out a page at all, it uses the material in the output routine to measure where on the page you are, adds the marginpar if necessary then rebuilds a list to return to the main vertical list to collect more material.

It would of course be possible to record in the float placement algorithm how many times each float has been deferred and basically force a float page at the next page break to avoid floats travelling more than a given number of pages. Actually that would probably be a relatively simple addition. It is unlikely to involve penalties in the sense of TeX primitive penalty nodes though.

  • Thanks David. So if I understand correctly, \@floatpenalty is really just used as a signalling mechanism to tell the OR that something special has to happen at that spot, correct? – Paul Gessler Jan 31 '15 at 12:40
  • 1
    @PaulGessler yes it has value 0 except when it has value -10002 which signals a float or marginpar in horizontal mode or -10003 which signals a float or marginpar in vertical mode. Any other value is likely to make latex get confused. The \@floatpenalty register itself is just used to save the needed value from the start of the float (where the test for hmode needs to be) to after the float content is saved (where the penalty is added) – David Carlisle Jan 31 '15 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.