# How can I test if a document is being compiled by XeLaTeX?

Is there a way to programatically test whether the current document is being compiled by (pdf)LaTeX or XeLaTeX?

-

\usepackage{ifxetex}
\ifxetex
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
\else
\usepackage{tgtermes}
\fi


There's also ifluatex. These packages define also \RequireXeTeX and \RequireLuaTeX respectively, that throw an error if the corresponding engine is not used.

As Martin remarks, the iftex package does the work of both defining different conditionals. This package is automatically loaded with bidi.

-
There is also the general iftex package: "which works both for Plain TeX and for LaTeX, defines the \ifPDFTeX, \ifXeTeX, and \ifLuaTeX conditionals for testing which engine is being used for typesetting. The package also provides the \RequirePDFTeX, \RequireXeTeX, and \RequireLuaTeX commands which throw an error if pdfTeX, XeTeX or LuaTeX (respectively) is not the engine in use." (Thanks goes to Andrey Vihrov for pointing this out to me recently) –  Martin Scharrer Jul 14 '11 at 10:50
@egreg: This only works if we assume there are only two engines (xetex and pdftex). –  user9783 Jul 16 '11 at 7:40