[Tex/LaTex] \fontfamily{…}\selectfont does not work with XeLaTeX engine

fontfamilyxetex

The following MWE works fine with pdfLaTeX engine but does not with XeLaXeX engine. Does \fontfamily{...}\selectfont work only with some font family when using XeLaTeX engine? Is there an appropriate way to use all of these font family in one document?

\documentclass{article}
\begin{document}
\begin{enumerate}
    \fontfamily{pag}\selectfont \item Avant Garde
    \fontfamily{fvs}\selectfont \item Bitstream Vera Sans
    \fontfamily{pbk}\selectfont \item Bookman
    \fontfamily{bch}\selectfont \item Charter
    \fontfamily{ccr}\selectfont \item Computer Concrete
    \fontfamily{cmr}\selectfont \item Computer Modern
    \fontfamily{pcr}\selectfont \item Courier
    \fontfamily{phv}\selectfont \item Helvetica
    \fontfamily{fi4}\selectfont \item Inconsolata
    \fontfamily{lmr}\selectfont \item Latin Modern
    \fontfamily{lmss}\selectfont\item  Latin Modern Sans
    \fontfamily{lmtt}\selectfont\item  Latin Modern Typewriter
    \fontfamily{pnc}\selectfont \item New Century Schoolbook
    \fontfamily{ppl}\selectfont \item Palatino
    \fontfamily{ptm}\selectfont \item Times
    \fontfamily{uncl}\selectfont\item  Uncial
    \fontfamily{put}\selectfont \item Utopia
    \fontfamily{pzc}\selectfont \item Zapf Chancery
\end{enumerate}
\end{document}

PDFLaTeX

XeLaTeX

Best Answer

You need to specify explicitly the font encoding, because by default TU is used which is a way to coerce LaTeX classic font selection system into working with OpenType fonts.

\documentclass{article}
\begin{document}
\begin{enumerate}\fontencoding{T1}
    \fontfamily{pag}\selectfont \item Avant Garde
    \fontfamily{fvs}\selectfont \item Bitstream Vera Sans
    \fontfamily{pbk}\selectfont \item Bookman
    \fontfamily{bch}\selectfont \item Charter
    \fontfamily{ccr}\selectfont \item Computer Concrete
    \fontfamily{cmr}\selectfont \item Computer Modern
    \fontfamily{pcr}\selectfont \item Courier
    \fontfamily{phv}\selectfont \item Helvetica
    \fontfamily{fi4}\selectfont \item Inconsolata
    \fontfamily{lmr}\selectfont \item Latin Modern
    \fontfamily{lmss}\selectfont\item  Latin Modern Sans
    \fontfamily{lmtt}\selectfont\item  Latin Modern Typewriter
    \fontfamily{pnc}\selectfont \item New Century Schoolbook
    \fontfamily{ppl}\selectfont \item Palatino
    \fontfamily{ptm}\selectfont \item Times
    \fontfamily{uncl}\selectfont\item  Uncial
    \fontfamily{put}\selectfont \item Utopia
    \fontfamily{pzc}\selectfont \item Zapf Chancery
\end{enumerate}
\end{document}

enter image description here

You can switch back and forth, although it is advisable to use only OpenType fonts with XeTeX/LuaTeX.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\begin{document}
Now using Times New Roman.

\fontencoding{T1}\fontfamily{cmr}\selectfont
Now using Computer Modern classic 8bit font files.

\normalfont
Now using again Times New Roman.

\fontencoding{T1}\fontfamily{pzc}\selectfont
Now using Zapf Chancery classic 8bit font files.

\normalfont
Now using again Times New Roman.

\fontencoding{T1}\fontfamily{pnc}\selectfont
Now using New Century Schoolbook classic 8bit font files.

\normalfont
Now using again Times New Roman.
\end{document}

enter image description here