[Tex/LaTex] \@setfontsize vs. \fontsize

fontsize

What are the differences between \@setfontsize and \fontsize?

For example, in Martin Scharrer's answer to How to create a newcommand for fontsize? he says:

This is done by calling \@setfontsize which isn't usable in your case.

Why?

Best Answer

The command \@setfontsize has a @ in its name, which means it's a "low level" or, perhaps better, internal command. It shouldn't appear in a normal document apart perhaps in the preamble to make some particular definition.

The definition of \fontsize is

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

which means that the user level command \fontsize hands control to \set@fontsize. This is a common technique in LaTeX.

The internal command \@setfontsize has a different purpose from \fontsize:

% latex.ltx, line 3611:
\def\@setfontsize#1#2#3{\@nomath#1%
    \ifx\protect\@typeset@protect
      \let\@currsize#1%
    \fi
    \fontsize{#2}{#3}\selectfont}

It's typically found in "class option files" such as size10.clo, for instance

\renewcommand\normalsize{%
   \@setfontsize\normalsize\@xpt\@xiipt
   \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
   \abovedisplayshortskip \z@ \@plus3\p@
   \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}

Let's see what happens when \normalsize is called (most of the times implicitly); LaTeX does

\@setfontsize\normalsize\@xpt\@xiipt

that, in view of the definition above, becomes

\@nomath\normalsize
\ifx\protect\@typeset@protect\let\@currsize\normalsize\fi
\fontsize{\@xpt}{\@xiipt}\selectfont

The first line \normalsize tells LaTeX to disallow \normalsize in math mode; the second line sets \@currsize to be equivalent to \normalsize, but only during normal typesetting (it does nothing, for instance, in write operations). Finally the command \fontsize is called with font size 10pt and baselineskip 12pt, then the font is actually selected.

Thus you see that \@setfontsize is an internal utility and calling it in a document doesn't make sense.

What's the purpose of size10.clo? Classes such as article and report are usually written in a "size independent" way; a size option (that may be the default one) causes LaTeX to read size10.clo, size11.clo or size12.clo (it's bk10.clo, bk11.clo or bk12.clo for the book class). These files set up the font selections and the parameters for lists and many other things that depend on the main body font size.