1

I would like to set the exact size, in points, of a font in my TeX document. Perusing through the fontspec documentation, I did not find a lot of information related to setting the font size. So I turned to google. Several posts suggest using \fontsize combined with \selectfont, including:

My question is twofold:

  • Why does fontspec not handle this?
  • Where do \fontsize and \selectfont come from? Are the LaTeX primitives? Are they part of a library?
5
  • 1
    why should fontspec do something here? \fontsize and \selectfont are the right commands for this and they are already defined by LaTeX. Commented Aug 16, 2021 at 10:32
  • 2
    “Font size” is not a well-defined quantity. Times at 10pt is quite different in size from, say, Lucida at 10pt.
    – egreg
    Commented Aug 16, 2021 at 10:45
  • Do texdoc latex2e for the documentation for the font commands, especially section 4 "Fonts". fontspec package deals with handling font features (face, weight, shape, scale, script, language, faces for specific sizes, OTF font feature switches, etc) and being able to use system fonts. unicode-math package builds on top of that for math, and polyglossia (for example) builds on top of that for multi/poly-lingual typesetting purposes. And so on.
    – Cicada
    Commented Aug 16, 2021 at 11:35
  • @UlrikeFischer could you please tell me more about \fontsize and selectfont? Which library do they belong to? Are they native commands?
    – user32882
    Commented Aug 16, 2021 at 11:48
  • I already wrote: LaTeX defines them, that means the format. Commented Aug 16, 2021 at 11:49

1 Answer 1

3

You asked, "Where do \fontsize and \selectfont come from? Are the[y] LaTeX primitives? Are they part of a library?"

  • Both macros are defined by the LaTeX2e kernel, or format. The term "primitive" [command] has a special meaning in TeX and LaTeX circles, so it's not wise to call \fontsize and \selectfont "primitives".

  • Just as the original "Plain TeX" format consists of a set of primitives (frequently, but not universally, referred to as "Knuth TeX") and a set of macros that build on these primitives (both the primitives and the aforementioned macros are explained in full detail in the TeXbook), the LaTeX2e format consists of a set of primitives (which these days come from eTeX, not Knuth TeX) and a set of macros defined in the LaTeX2e kernel. The LaTeX kernel may be found in the file latex.ltx.

  • In the current version of latex.ltx ("LaTeX2e <2021-06-01> patch level 1"), the macro \fontsize is defined on lines 7036 and 7037 of the file, as follows:

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

    The macro \set@fontsize is defined on lines 7985 thru 8002 as follows:

    \def\set@fontsize#1#2#3{%
        \@defaultunits\@tempdimb#2pt\relax\@nnil
        \edef\f@size{\strip@pt\@tempdimb}%
        \@defaultunits\@tempskipa#3pt\relax\@nnil
        \edef\f@baselineskip{\the\@tempskipa}%
        \edef\f@linespread{#1}%
        \let\baselinestretch\f@linespread
          \def\size@update{%
            \baselineskip\f@baselineskip\relax
            \baselineskip\f@linespread\baselineskip
            \normalbaselineskip\baselineskip
            \setbox\strutbox\hbox{%
              \vrule\@height.7\baselineskip
                    \@depth.3\baselineskip
                    \@width\z@}%
            \let\size@update\relax}%
      }
    
  • The macro \selectfont, in turn, is defined on lines 7954 thru 7985 as follows:

    \DeclareRobustCommand\selectfont
            {%
        \ifx\f@linespread\baselinestretch \else
          \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
        \ifx\delayed@f@adjustment\@empty
        \else
          \let\f@shape@saved\f@shape
          \let\f@series@saved\f@series
          \delayed@f@adjustment
          \maybe@load@fontshape
          \ifcsname \f@encoding/\f@family/\f@series/\f@shape \endcsname
          \else
            \let\f@shape\f@shape@saved
            \let\f@series\f@series@saved
            \let\delayed@merge@font@shape\merge@font@shape
            \let\delayed@merge@font@series\merge@font@series
            \delayed@f@adjustment
            \let\delayed@merge@font@shape\merge@font@shape@without@substitution
            \let\delayed@merge@font@series\merge@font@series@without@substitution
          \fi
          \let\delayed@f@adjustment\@empty
        \fi
        \@forced@seriesfalse
        \xdef\font@name{%
          \csname\curr@fontshape/\f@size\endcsname}%
        \pickup@font
        \font@name
        \UseHook{selectfont}%
        \size@update
        \enc@update
        }
    \NewHook{selectfont}
    
  • As the code demonstrates, both macros are quite complex and rely on a sizable number of subsidiary macros to get much of their work done.

  • You also asked, "Why does fontspec not handle this?" As @UlrikeFischer and @Cicada have already pointed out in comments, there's no need or justifiable reason for making fontspec perform tasks that are handled perfectly well by the existing LaTeX macros \fontsize and \selectfont.

1
  • This is already beyond my current level of understanding by I do see myself returning to your valuable answer in the near future and understanding more of it as my abilities in LaTeX improve. I trust it is complete and therefore accept it.
    – user32882
    Commented Aug 16, 2021 at 13:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .