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?

4
  • 2
    \fontsize and \set@fontsize is documented in source2e.pdf. Didn't you found it? Commented Apr 21, 2017 at 8:44
  • 1
    No. I will use my eyes next time. I am not sure whether I should close this question in shame or leave it open for the next nincompoop. Commented Apr 21, 2017 at 8:46
  • For code of \selectfont see latex.ltx around line 2708. Commented Apr 21, 2017 at 8:48
  • 1
    There are other nincompoops (e.g., me) here who might find it useful, haha. Commented Apr 21, 2017 at 9:27

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.