8

This question already has an answer here:

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.)

marked as duplicate by Henri Menke, Mensch, Stefan Pinnow, Bobyandbob, TeXnician Jan 13 at 14:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You could just use the \newfontfamily command; e.g., \newfontfamily\garamond[<options>]{EB Garamond}. – jon Nov 10 '14 at 2: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 2:40
  • I see what you're saying, but I'll let those responsible for the design weigh in. – jon Nov 10 '14 at 2:52
  • 5
    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 5:19
  • 3
    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 7:54
13
\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

5

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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.