6

How does the mechanism for floats work internally in LaTeX (or are they TeX? as someone who never really learned TeX without LaTeX, I have no idea)? I understand how to produce them and that sort of thing, but I'd like to understand how the content in the float actually gets moved to later in the document. For example, do the macros in a float environment get evaluated immediately or somehow delayed. If they are evaluated immediately, how do they end up further down in the final document. If they are evaluated later, how does LaTeX know the size that is needed for the float?

Sorry if this question has already been asked/answered somewhere; I spent quite a while looking and only turned up things about how to change behavior of floats, rather than explanations of how they work.

5
  • Probably related: tex.stackexchange.com/questions/39017/… Commented Apr 29, 2016 at 19:31
  • As far as I am concerned there is no simple explanation. For all the gory details read the code via "texdoc classes". Commented Apr 29, 2016 at 19:41
  • @TorbjørnT. that question has a really nice answer about how the mechanics of the float placement algorithm work, but I'm less interested in float placement than in how macros are dealt with I guess?
    – arcticmac
    Commented Apr 29, 2016 at 19:42
  • a float environment is like \savebox all macros are resolved at the point the environment is met and the content typeset into a box register. Commented Apr 29, 2016 at 19:48
  • @DavidCarlisle I think that nicely answers my question.
    – arcticmac
    Commented Apr 29, 2016 at 19:54

1 Answer 1

6

A float environment is like \savebox all macros are resolved at the point the environment is met and the content typeset into a box register.

LaTeX maintains lists of (numbers of) box registers starting with a "free list", as each float is encountered a box is taken from the free list and filled with typeset the environment contents.

At a page break LaTeX considers the various float areas in turn, and for example when considering the top area runs through the "defer list" of pending floats and tests whether each one may be moved to the "top list" by considering the box size and the parameters such as topnumber that control how many floats may be added to each area.

If a float is added to a page the box is emptied, and returned to the free list to be used for a later float.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .