[Tex/LaTex] How to use a system font together with latex fonts

fontsfontspecxetex

I am trying to use a display font for special headers — it is Anton in truetype format, but to continue to use normal Latex fonts for the rest of the document. I thought this would be achieved by

\usepackage{droid}
\usepackage{ifxetex}
\ifxetex
  \usepackage{fontspec}
  \defaultfontfeatures{Ligatures=TeX} % To support LaTeX quoting style
  \newfontfamily\headerfont{Anton}
\else
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\fi

but if this is compiled by xelatex, the droid package is ignored, and if by pdflatex, the Anton font is not available. Is there a way round this problem?

Best Answer

\ifxetex detects whether you are compiling with XeTeX or not. If you are, it executes the if bit. If not, it executes the else bit. Moreover, you cannot use inputenc with XeTeX (so it is good, really, that that code is never read).

You can use 'normal LaTeX fonts' for the rest of the document, though. Just use the three lines of code from \usepackage{fontspec} and put \usepackage{droid} configuration afterwards, as loading fontspec sets the default families to Latin Modern.

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX} % To support LaTeX quoting style
\newfontfamily\headerfont{Quintessential}
\usepackage[T1]{fontenc}
\usepackage{droid}
\begin{document}
Some text.
\end{document}

However, you may prefer to use the Droid fonts in opentype/truetype format to take full advantage of XeTeX.

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX} % To support LaTeX quoting style
\newfontfamily\headerfont{Quintessential}
\setmainfont{Droid Serif}
\setsansfont{Droid Sans}
\setmonofont{Droid Sans Mono}
\begin{document}
  Some text. Serif. \textsf{Sans}. \texttt{Mono}.
\end{document}

Droid truetype

Note that I changed the value of \headerfont to prevent XeLaTeX hanging forever since I don't have the font you are using.