# Switching back to Computer Modern within XeLaTeX

Until I select a font using \fontspec{ ... }, XeLaTeX uses the default of Computer Modern. Once I select some font, I have no idea how to re-select Computer Modern. Can anyone help?

XeLaTeX (via fontspec) actually uses the Latin Modern version of Computer Modern. So to change back to it you can do two things:

1. Install the Latin Modern Fonts into your system and load the font using \newfontfamily
2. Use the standard \fontfamily...\selectfont method.

% !TEX TS-program = XeLaTeX

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
%\newfontfamily\lmodern{Latin Modern Roman} % If font exists on your system
% Optical sizes need to be set up manually using the [SizeFeatures] option
% or select the font using the regular font selection methods
\newcommand{\lmr}{\fontfamily{lmr}\selectfont} % Latin Modern Roman
\newcommand{\lmss}{\fontfamily{lmss}\selectfont} % Latin Modern Sans
\newcommand{\lmss}{\fontfamily{lmtt}\selectfont} % Latin Modern Mono
\begin{document}
Some text in Linux Libertine.
{\lmr Some text in Latin Modern}
\end{document}


Alternatively, if you are mainly using Computer Modern in your document, you can use \newfontfamily to define the alternative font.

As noted by Andrey Vihrov, the second solution is probably to be preferred, since the optical sizes of Latin Modern are set up when the font is loaded in the regular way. With the first solution, you would need to add the optical size information using the [SizeFeatures] option when declaring the \newfontfamily.

If you want to restore the defaults completely (rather than just have access to the Latin Modern fonts with a command) you can redefine \rmdefault, \sfdefault and \ttdefault instead (as suggested by Ulrike Fischer). This will override the \setmainfont settings.

\renewcommand\rmdefault{lmr}
\renewcommand\sfdefault{lmss}
\renewcommand\ttdefault{lmtt}


Edit note: Please note that the current version of this answer has been reorganized to reflect the discussion in the comments. Thanks.

• This doesn't work for me: I get a message that Latin Modern Roman cannot be found (even when I copy your example). Still, I know I do have computer modern, because when I don't switch fonts, I stay with it! Aug 5, 2011 at 17:11
• Unfortunately, XeTeX on (Linux?) TeX Live does not find fonts in the system texmf tree by name. Aug 5, 2011 at 17:15
• But somehow xelatex does know how to find CM when it starts! There should be some way to save that font somewhere. [I'm using MacTeX] Aug 5, 2011 at 17:19
• It's hard for me to test this, since it works on my system (a Mac). But try the following then: \newcommand{\lmodern}{\fontfamily{lmr}\selectfont} instead of the \newfontfamily command. Aug 5, 2011 at 17:24
• Note that the first solution is not very desirable, because it does not restore Latin Modern's setup for optical font sizes. Aug 5, 2011 at 18:16

As a default fontspec doesn't use computer modern but the latin modern font. To get back exactly the default setup set the font family to lmr, lmss, lmtt. Either localy or by redefining the defaults:

\documentclass{scrartcl}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Cambria}
\begin{document}
rm \texttt{tt} \textsf{sf}

{\fontfamily{lmr}\selectfont rm
\fontfamily{lmss}\selectfont sf
\fontfamily{lmtt}\selectfont tt}

\renewcommand\rmdefault{lmr}
\renewcommand\sfdefault{lmss}
\renewcommand\ttdefault{lmtt}
\normalfont
rm \textsf{sf} \texttt{tt}
\end{document}


Old fontspec had a cm-default option. Now it is obsolete.

However, you can still switch back to OT1 or T1 font encoding with CM families. For example:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily\xits{XITS}
\newfontfamily\cursor{TeX Gyre Cursor}
\usepackage[OT1]{fontenc}
\renewcommand\rmdefault{cmr}
\renewcommand\sfdefault{cmss}
\renewcommand\ttdefault{cmtt}
\begin{document}
This is Computer Modern Roman.

\textsf{This is Computer Modern Sans.}

\texttt{This is Computer Modern Typewriter.}

{\xits This is Times-like XITS font.}

{\cursor This is Courier-like TeX Gyre Cursor.}
\end{document}


This is obtained by pdffonts utility:

name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
DQLQYU+CMR10                         Type 1C           yes yes no       4  0
ZSODJO+CMSS10                        Type 1C           yes yes no       5  0
YLHYBL+CMTT10                        Type 1C           yes yes no       6  0
EKZHDP+XITS-Identity-H               CID Type 0C       yes yes yes      8  0
PMNGJM+TeXGyreCursor-Regular-Identity-H CID Type 0C       yes yes yes     10  0


It's OK if you want to use EU1 (i.e. Unicode in XeTeX) as default font encoding. You can switch to OT1 encoding whenever you want:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage[OT1,EU1]{fontenc}
\begin{document}
This is Linux Libertine O.

{\fontencoding{OT1}\fontfamily{cmr}\selectfont
This is Computer Modern Roman.}
\end{document}


name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
BLJUZB+LinLibertineO-Identity-H      CID Type 0C       yes yes yes      5  0
ANBDAK+CMR10                         Type 1C           yes yes no       6  0

• Although this works, I'm not sure why anyone would really want to use the OT1 encoding. (Since I don't think that Mayer literally requires Computer Modern; he just wants the same default font that fontspec uses when no main font is set, which is Latin Modern (with the EU1 encoding)). Aug 5, 2011 at 18:00
• @Alan: Well, the OP may not really want the actual Computer Modern families. But the answer provides them for those who are interested. Usually, default Latin Modern families in EU1 encoding are very well (or even better than CM), and nothing is to be worried. BTW, except Latin Modern, there are also Computer Modern Unicode (CMU) families. Aug 5, 2011 at 18:06
• @Alan: Indeed, CM in OT1 or T1 may be not attractive when LM and CMU are available. However, there are still many Type1 fonts in old font encoding distributed with TeX. When some one want to use those fonts (e.g. Iwona, Kurier, URW Bookman), this technique will be useful. Aug 5, 2011 at 18:19

I used the example when wondering how to use selnolig in the context of lualatex at How to use selnolig package together with default lualalatex font?.

By a comment of @mico this is a straight-forward solution working on TeXLive 2017:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\begin{document}
Some text in Linux Libertine.

\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\setmonofont{Latin Modern Mono}

Some text in Latin Modern.
\end{document}