[Tex/LaTex] What’s the difference between \hfil and \hskip0cm plus 1fil

glueprimitivestex-coretex-history

What's the difference between \hfil and \hskip0cm plus 1fil? In both cases, a glue token is created that skips by zero, but with 1fil of stretchability. If you use \hbox spread 4cm{\hfil test \hskip0cm plus 1fil}, you'll get an hbox with "test" in the middle and 2cm on either side of empty space (showing that the two glues are sharing the space equally). In all the cases I've tested, the two have been exactly the same (including variants of \hfil like \hfill and \vfil).

What's the difference between the two, and if there is none, why is \hfil a primitive instead of a macro for \hskip0cm plus 1fil? Is \hfil always interchangeable with \hskip0cm plus 1fil?

Best Answer

\hfil and \hskip0cm plus 1fil make identical glue items so tests such as your box example will be identical in the same way that \hskip0cm plus 1fil is the same as \hskip 0 pt plus 1fil, However they differ as tokens and the way they are scanned.

Notably of course, after

\def\zzA{\hfil}

and

\def\zzB{\hskip0cm plus 1fil}

Then

\zzA look and \zzB look

show different behaviour, and similarly after

\def\gobble#1{}


\expandafter\gobble\zzA  and \expandafter\gobble\ZZB