TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 23 down vote accepted
   \setmainfont[Ligatures=TeX]{TeX Gyre Termes}

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
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
Very similar: tex.stackexchange.com/a/13175/8666 – Ioannis Filippidis Jul 31 '15 at 8:32

Your Answer


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.