Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 17 down vote accepted
\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.

share|improve this answer
13  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.