5

I found this question How does \fontsize{}{} work? while looking for an understanding of \selectfont, but I was disappointed to see that the term "work" was referring to its usage and not to its implementation i.e. how it actually works internally.

Where is \fontsize{}{}\selectfont documented? Is it wrong to think it should be included in source2e? If so, why?

1 Answers1

5

Here's the code:

2400 \DeclareRobustCommand\fontsize[2]
2401    {\set@fontsize\baselinestretch{#1}{#2}}

2697 \def\set@fontsize#1#2#3{%
2698     \@defaultunits\@tempdimb#2pt\relax\@nnil
2699     \edef\f@size{\strip@pt\@tempdimb}%
2700     \@defaultunits\@tempskipa#3pt\relax\@nnil
2701     \edef\f@baselineskip{\the\@tempskipa}%
2702     \edef\f@linespread{#1}%
2703     \let\baselinestretch\f@linespread
2704       \def\size@update{%
2705         \baselineskip\f@baselineskip\relax
2706         \baselineskip\f@linespread\baselineskip
2707         \normalbaselineskip\baselineskip
2708         \setbox\strutbox\hbox{%
2709           \vrule\@height.7\baselineskip
2710                 \@depth.3\baselineskip
2711                 \@width\z@}%
2712         \let\size@update\relax}%
2713   }
  1. \@defaultunits is responsible for adding pt to the argument if just a number appears, storing the value in either \@tempdimb (for the size argument) or in \@tempskipa (for the baseline skip argument)

  2. \f@size and \f@baselineskip are set to the value in points (no unit) from the two arguments to \fontsize

  3. \f@linespread is set from the first argument, that is, from \baselinestretch
  4. A temporary macro is defined for updating the values, which will be executed at the next \selectfont command; the macro \size@updatewill then redefine itself to be\relax`

Note that \size@update will also contain a redefinition of the \strutbox, so a \strut will always be fit to the current font size.

You can call \fontsize{3cm}{4cm} or \fontsize{15}{18} or any mixture with or without units; a unitless is implicitly assumed to be in points.

egreg
  • 1,121,712