[OS X TeX] Testing for fontspec package

Bruno Voisin bvoisin at mac.com
Tue Sep 4 10:18:54 EDT 2007


Le 4 sept. 07 à 15:59, firstian at rcn.com a écrit :

> I have a tex file that needs to be compiled for both xelatex and  
> regular latex (both
> use pdflatex to generate pdf directly).

LaTeX does use the pdfTeX engine by default, but XeLaTeX doesn't:  
instead, XeLaTeX uses (and requires) the XeTeX engine.

> The tex file currently uses fontspec, which
> the regular latex doesn't like. Is there a way to test for whether  
> fontspec is installed
> in the tex file itself, so it can work for both without modifications?

fontspec cannot work outside XeTeX. It won't work with pdfTeX.

What you can do is load the ifxetex package and use it. Something like:

\usepackage{ifxetex}
\ifxetex
   \usepackage{fontspec,xunicode,xltxtra}
   <fontspec-specific font calls>
\else
   <alternative font calls>
\fi

For example a document of mine used:

\ifxetex
   \usepackage[cm-default]{fontspec}
   \usepackage{xunicode,xltxtra}
   \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
   \setmainfont{Verdana}
\else
   \usepackage[T1]{fontenc}
   \usepackage{textcomp}
   \usepackage{mathptmx}
   \usepackage[scaled=0.92]{helvet}
   \usepackage{courier}
   \renewcommand{\familydefault}{\sfdefault}
\fi

Bruno Voisin
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the MacOSX-TeX mailing list