3

In the following MCE, the default font is sans serif, as it is by default the case e.g. with the beamer class. And the "main" font (declared by \setmainfont) is not the same as the "default" ("normal") one, but rather is the "roman" font.

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}

\setmainfont{Punk Nova}[Color=red]
\setsansfont{QTAgateType}
\setmonofont{QTArabian}[Color=blue]

\renewcommand*\familydefault{\sfdefault}

\begin{document}
\begin{description}
\item[Default:] Test
\item[Roman:] \textrm{Test}
\item[Sans serif:] \textsf{Test}
\item[Monospace:] \texttt{Test}
\end{description}
\end{document}

So:

  • What is the purpose of "main" in \setmainfont?
  • Isn't the purpose of \setmainfont rather to declare the roman font and, if so, why isn't this command rather called \setromanfont?
1
  • 2
    I'm setting a wedding invitation, and I want it to be Fraktur. \setromanfont would make absolutely no sense. Oct 18, 2021 at 20:10

1 Answer 1

5

It sets the default font (but only until you reset it)

If you modify your eaxmple

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}

\normalfont \showthe\font
\setmainfont{Punk Nova}[Color=red]
\normalfont \showthe\font
\setsansfont{QTAgateType}
\setmonofont{QTArabian}[Color=blue]

\renewcommand*\familydefault{\sfdefault}

\begin{document}
\begin{description}


\item[Default:] Test
\item[Roman:] \textrm{Test}
\item[Sans serif:] \textsf{Test}

\item[Monospace:] \texttt{Test}
\end{description}
\end{document}

You get

> \TU/lmr/m/n/10 .
<recently read> \font 
      
l.5 \normalfont \showthe\font

The default font is still latin modern roman at this point

Then you get

> \TU/PunkNova(0)/m/n/10 .
<recently read> \font 
      
l.7 \normalfont \showthe\font

showing the effect of \setmainfont

Then you do

\renewcommand*\familydefault{\sfdefault}

which will make the default font pick up whatever you have specified for Sans serif. (beamer does something similar at begin document as well)

4
  • OK but don't you think it would have been less confusing to name this command \setromanfont? Oct 18, 2021 at 14:12
  • 3
    @DenisBitouzé that would be confusing, if the font you use isn't Roman for example It does literally what it says it sets the default font, if you redefine \rmfamily or \familydefault afterwards you would see the same thing. the issue isn't related to sans serif or beamer Oct 18, 2021 at 14:21
  • 3
    @DenisBitouzé In some older versions of fontspec, it was \setromanfont. You’d have to ask Will Robertson why he named the commands that way. But, to me \setmainfont doesn’t imply “Set the main font, and also prevent authors from changing it.”
    – Davislor
    Oct 18, 2021 at 17:29
  • @DavidCarlisle That would not be more confusing than e.g. \setsansfont if the font you use isn't sans serif, for example \setsansfont{KpRoman}. Oct 18, 2021 at 18:25

You must log in to answer this question.

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