15

fontspec defines the commands

\setmainfont{font name}[font features]
\setsansfont{font name}[font features]
\setmonofont{font name}[font features]

to set the document’s default fonts. However, if I use a sans-serif font as the main font, e. g. \setmainfont{Latin Modern Sans}, \rmfamily is redefined as Latin Modern Sans, so I lose the ability to specify a separate serif font. Of course, I could set the serif font with \setsansfont, but then I have the fonts all backwards.

Shouldn’t there also be a command \setseriffont? I don't think a “main” font should necessarily always be a serif font. If this is intended, what is the best way to have a sans-serif font as the default font, but still have a serif font defined as \rmfamily?

(This is unrelated to “What is the simplest way to typeset an entire document in sans-serif?”. I already explained that I could typeset the document in a sans-serif font by using \setmainfont. This question is about the semantics of the command \setmainfont, which doesn’t seem to imply any specific font characteristics from its name, compared to \setsansfont, \rmfamily and \sffamily – see also the comment by Will Robertson.)

Socob
  • 1,693
  • You could just use the \newfontfamily command; e.g., \newfontfamily\garamond[<options>]{EB Garamond}. – jon Nov 10 '14 at 02:38
  • Well, yes, from a practical point of view, but wouldn't that be an oversight in the design of the fontspec package? – Socob Nov 10 '14 at 02:40
  • I see what you're saying, but I'll let those responsible for the design weigh in. – jon Nov 10 '14 at 02:52
  • 6
    I have toyed in the past with renaming \setsansfont to \setaltfont (or similar) but never got around to it. \setromanfont became \setmainfont many many years ago because ‘roman’ isn't a good descriptor when you're writing Greek, e.g. Perhaps \setseriffont would have been a better idea, but I didn't think of it at the time :) – Will Robertson Nov 10 '14 at 05:19
  • 4
    That's the way LaTeX is designed. However, if you use a sans serif font as the main document font, no part of it should use a serif font. – egreg Nov 10 '14 at 07:54
  • @Socob Just to point out, now the syntax is \setsomefont{font name}[font features] with the features at the end. – Manuel Nov 10 '14 at 16:16
  • @HenriMenke I updated the question. – Socob Jan 13 '19 at 05:28
  • @Socob No, it's not unrelated, it's a duplicate. Compare the accepted answer here and over there. – Henri Menke Jan 13 '19 at 06:48
  • @HenriMenke Just because two questions can be solved with the same answer doesn’t mean that the questions themselves are the same. – Socob Jan 13 '19 at 16:17
  • @Socob No, you're just asking the wrong question. You think that switching the font of the whole document to sans-serif is somehow related to fontspec, when in fact it isn't. There is a generic way which is completely independent of the font or how you load it and that is answered in the duplicate. – Henri Menke Jan 13 '19 at 19:10
  • @HenriMenke Whatever. I see you’ve already made up your mind and are not interested in actual arguments. – Socob Jan 13 '19 at 22:52
  • @WillRobertson You could still rename it to \setseriffont and use \setmainfont as an alias for backwards-compatibility. – Henri Menke Jan 13 '19 at 23:16
  • @henri I think I’d rather re-advertise \setromanfont than add another alias. I’ll keep thinking about it as I do want to add a couple small things to fontspec this summer. (Australian time) – Will Robertson Jan 14 '19 at 02:26

2 Answers2

17
\renewcommand{\familydefault}{\sfdefault}

That is:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
  abc
  \textrm{abc}
  \textsf{abc}
\end{document}

sans and serif

cfr
  • 198,882
10

If it helps to keep everything clear, you can use the \setromanfont command instead of \setmainfont, although the fontspec manual doesn't mention it:

\documentclass{article}
\usepackage{fontspec}
\setromanfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
  abc
  \textrm{abc}
  \textsf{abc}
\end{document}
Andrew Dunning
  • 1,714
  • 13
  • 21