What is the exact purpose of \ftype@<TYPE>?

Just to expand a bit on what egreg wrote.

LaTeX needs to construct an efficient way of storing flags for both type of float identifiers as well as placement identifiers. So the LaTeX Team combined them into one bit string. The first 5 bits are reserved for the specifiers and the rest for the floats.

     Position  76543210
     Value     0010010   

Bit      Meaning
---      -----------
0       1 if the float may go where it appears in the text
1       1 if the float maytop of page
2       1 if the float may go on bottom of page
3       1  if the float may go on float page
4       1 umless the placement includes a  !
5       float type figures
6       float type tables

In order to add a different float type, one needs to move by one position to the left. A left arithmetic shift by n is equivalent to multiplying by 2^n and hence in this case is in powers of two.

Type 1=2^0 is a figures, type 2=2^1 tables, type 4=2^2 code, type 8=2^3 something else etc...

Oberdiek's flags macros, now called bitset, might be useful if you are going to be tinkering with this sort of thing. PDF's use similar flags for pdf objects to set properties.

Since TeX’s number limit of 2^31-1 and the first 5 bits are taken by the float identifiers there remain 26 available float types for the adventurous.


Each floating box is stored in a box register \bx@A, \bx@B and so on. To each of these box registers there corresponds a counter that is loaded with a number that represents the float type and the position specifiers. So for each float LaTeX can know what were the position specifiers (h, t, b, p or !) and decide what to do with them according to the constraints imposed by the page to output. The first five bits are reserved for the specifiers, then comes the type.

For example, with

\begin{figure}
a
\end{figure}
\begin{figure}[h]
b
\end{figure}
\begin{table}
c
\end{table}

we get

\count\bx@A=62
\count\bx@B=49
\count\bx@C=94

In binary form 62 is 111110, 49 is 110001, 94 is 1011110.

In the first we see that h is not specified, while tbp are (the default for article): h is bit 0, t is bit 1, b is bit 2 and p is bit 3. The ! subtracts 16 and indeed \begin{figure}[!htbp] gives 41, that is 101111. So, a zero in bit 4 means "relax the constraints".

By the way, \bx@A is 252, \bx@B is 251, and so on. The insertion classes 254 and 253 are, respectively, \@mpfootins and \footins.


I'm fairly sure that there is a lot of improvement possible in the LaTeX2e source documentation. However, the statement given in the question that there isn't any useful information about the float type number is not quite true. The documentation section on floats (in ltfloats.dtx) starts of with

% \section{Floats}
%
%  The different types of floats are identified by a \meta{type} name,
%  which is the name of the counter for that kind of float.  For
%  example, figures are of type `figure' and tables are of type `table'.
%  Each \meta{type} has associated a positive \meta{type number}, which
%  is a power of two.  E.g.,\\
%  figures might be have type number~1, tables type number~2, programs
%  type number~4, etc.

So it is clearly stated that the type has to be a power of 2 even if there is no reason given or an explicit documentation at this point how the algorithm makes use of this number.

There is also (quite technical :-) documentation in the pseudo code by Leslie on the original algorithm, e.g.,

%  \@bitor\NUM\LIST : Globally sets switch @test to the disjunction for
%         all I of bit  log2 \NUM of the float specifiers of all the
%         floats in \LIST.
%         I.e., @test is set to true iff there is at least one
%         float in \LIST having bit  log2 \NUM  of its float specifier
%         equal to 1.
%
%  Note: log2 [(\count I)/32] is the bit number corresponding to the
%  type of float I.  To see if there is any float in \LIST having
%  the same type as float I, you run \@bitor with
%    \NUM = [(\count I)/32] * 32.

Now my position here is that this wasn't forseen as an area where anybody was (and is) supposed to hook in on a low-level and that such technical parts therefore do not need further explanation other than providing info that one has to provide 4 interface macros with a certain characteristics per type of float, e.g.,

\def\fps@table{tbp}
\def\ftype@table{2}
\def\ext@table{lot}
\def\fnum@table{\tablename\nobreakspace\thetable}

The other 5 people in the the world that were expected to look in detail into the algorithm are those that write a package like floats and given that the technical aspect of the algorithm is actually not that badly documented.

And now the answers by @egreg and @Yiannis on this site give a very good technical summary what is happening in LaTeX2.09 and LaTeX2e.