fontspec \setmainfont overrides other font families

It seems that the use of fontspec's \setmainfont is overriding other font families. Is that the expected behavior?

Should I use instead \renewcommand{\familydefault}{\sfdefault}?

A MWE follows below:

\documentclass{article}
\usepackage{fontspec}
\usepackage{lipsum}

\setromanfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
\setmainfont{Arial}
%\renewcommand{\familydefault}{\sfdefault}

\begin{document}

\section{Introduction}

\lipsum[1]

\section{Font list}

\begin{itemize}
\item Main font:  \expandafter\texttt\expandafter{\fontname\font}
\item {\rmfamily Roman font: \expandafter\texttt\expandafter{\fontname\font}}
\item {\sffamily Sans font: \expandafter\texttt\expandafter{\fontname\font}}
\item {\ttfamily TT font: \expandafter\texttt\expandafter{\fontname\font}}
\end{itemize}

\end{document}


This is the way it is designed to work. \setmainfont essentially just sets the \rmfamily. So if you are explicitly setting the Roman font, there's no need to use \setmainfont at all. So in your example, you first set the \rmfamily to Times New Roman, and then with \setmainfont you set it to Arial.

So if you want Times, Arial and Courier as your fonts you can just use:

\setromanfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}


Or

\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}


There is really no practical distinction between \setmainfont and \setromanfont.

• and after that how do I set the default family to Sans Serif? Should I use \renewcommand{\familydefault}{\sfdefault}? – Lin Jun 11 at 0:54
• @AlanMunn \show\familydefault .... – David Carlisle Jun 11 at 7:03
• @Lin set \familydefault as you show in your question. – David Carlisle Jun 11 at 7:04