9

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

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Say OL
  • 1,793

2 Answers2

13

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

  • 1
    But using T1 encoding with xelatex is naturally not recommended. One should better use fontspec and search for suitable open type replacements. – Ulrike Fischer Apr 13 '18 at 07:00
  • @UlrikeFischer the usage is scoped here to enumerate environment –  Apr 13 '18 at 07:28
  • 1
    But only in the example. The OP probably plan to use these fonts in a full document and then switching to T1-encoding is not the right thing to do. – Ulrike Fischer Apr 13 '18 at 07:33
  • The OP will have been warned ! ;-) –  Apr 13 '18 at 07:57
  • @UlrikeFischer: Yes, I plan to them in a full document but I tried to minimize it for posting question only. – Say OL Apr 13 '18 at 09:19
  • @jfbu: I am not familiar with font select of pdfLaTeX and XeLaTeX. It works in your answer. However, in practice, I may need to other font with complex script language, Khmer, in the document. – Say OL Apr 13 '18 at 09:23
  • There is no impossibility into using both types of fonts. Just switch back to your font for Khmer with \normalfont for example, if you had \usepackage{fontspec}\setmainfont{<whatever>} in preamble. See updated example. –  Apr 13 '18 at 11:53
3

The short names are required for 8 letter file systems last century. Using xelatex you can refer to your system fonts via their font names, so for example

enter image description here

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Bitstream Vera Sans}
\begin{document}
\begin{enumerate}
 \item Hello World
\end{enumerate}
\end{document}
David Carlisle
  • 757,742
  • 1
    Helpful! Changing font encoding from time to time assist me to use those 8-bit fonts. Anyway, I am still doubtful if it it harmful to use fontspec package and T1 encoding. – Say OL Apr 13 '18 at 14:10
  • 2
    @SayOL in xelatex as currently built it on;y has hyphenation patterns for TU encoding so if you use T1 encoding hyphenation is likely to be wrong, if you just use it for a small section to access a font then that is probably OK, although there are very few fonts that are only available in classic 8bit tex font encodings and not available as unicode based fonts – David Carlisle Apr 13 '18 at 15:23