[Tex/LaTex] the difference between \fontsize{…}{some length} and \linespread{some length}

fontsizeline-spacing

I notice that the second argument to \fontsize and the first argument to \linespread both seem to change the spacing between lines of text. What is the difference between these? Is there one I should favor using?

Best Answer

The argument to \linespread is a real number (not a length), while both arguments to \fontsize are lengths.

\fontsize{<size>}{<baselineskip>} sets the font <size> and <baselineskip>, while \linespread{<factor>} is used as a multiple for the \baselineskip. In fact, the latter is virtually equivalent to

\renewcommand{\baselinestretch}{<factor>}

It's your choice which to use. However, both require a font selection on order to be activated. Read more on this peculiarity in the UK TeX FAQ entry Why doesn’t \linespread work?

In the LaTeX kernel, \fontsize and \linespread is defined as

\DeclareRobustCommand\linespread[1]
   {\set@fontsize{#1}\f@size\f@baselineskip}
\DeclareRobustCommand\fontsize[2]
   {\set@fontsize\baselinestretch{#1}{#2}}

Note that both utilize \set@fontsize{<factor>}{<size>}{<baselineskip>}. The reason for separating the two allows you to use a fix the one while manipulating the other. Once \set@fontsize is called, it creates \size@update that sets \baselineskip as a \baselinestretch multiple of itself and stores this result in \normalbaselineskip for other uses (amongst other things). A call to \selectfont "uses" these settings. For the wild at heart, here's the nitty gritty (with some comments):

\def\set@fontsize#1#2#3{%
    \@defaultunits\@tempdimb#2pt\relax\@nnil
    \edef\f@size{\strip@pt\@tempdimb}% <-- extracts font size
    \@defaultunits\@tempskipa#3pt\relax\@nnil
    \edef\f@baselineskip{\the\@tempskipa}% <-- extracts baseline skip
    \edef\f@linespread{#1}% <-- extracts baseline stretch
    \let\baselinestretch\f@linespread% <-- stores baseline stretch
      \def\size@update{%
        \baselineskip\f@baselineskip\relax% <-- stores baseline skip in \baselineskip
        \baselineskip\f@linespread\baselineskip% <-- multiplies \baselineskip by \baselinestretch
        \normalbaselineskip\baselineskip% <-- stores \normalbaselineskip
        \setbox\strutbox\hbox{%
          \vrule\@height.7\baselineskip
                \@depth.3\baselineskip
                \@width\z@}%
        \let\size@update\relax}%
  }

All these intricacies are meant to be simplified through setspace for consistency.

Related Question