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

The ifpdf package is supposed to detect if pdfTeX is running:

This package looks for pdfTeX in pdf mode and implements and sets the switch \ifpdf.

(from the ifpdf documentation)

However, when I compile the following MWE with LuaLaTeX, my document reads

This is pdfTeX.



    This is pdfTeX.
    This is not pdfTeX.

Is this expected and intended behavior? How do I set up a conditional that only detects pdfTeX? (The MWE works as expected for XeTeX.)

share|improve this question
Looks OK to me: LuaLaTeX makes PDF files, not DVI. – Joseph Wright Oct 6 '12 at 18:33
@JosephWright Reading the name of the switch literally, yes. But then again, XeTeX produces pdf as well, and the switch returns false for that. Also, the abstract talks about pdfTeX, not pdf output. – doncherry Oct 6 '12 at 18:35
XeTeX always works via the .xdv (extended DVI) format, and the PDF is actually made by xdvipdfmx which is normally as part of the XeTeX run. \ifpdf is about the driver, and in the pdfTeX and LuaTeX cases the 'driver' is direct PDF output. – Joseph Wright Oct 6 '12 at 18:36
use the package ifluatex instead with \ifluatex ... \else ... \fi – Herbert Oct 6 '12 at 18:37
up vote 8 down vote accepted

LuaTeX comes from pdfTeX, it also knows the same modes for PDF and DVI and provides nearly all PDF features of pdfTeX. It knows even \pdftexversion and \pdftexrevision. Thus \ifpdf has the same semantics here.

The test \ifpdf is not for testing for an engine. Even if \ifpdf is false, then you can have pdfTeX, but pdfTeX in DVI mode. Usually TeX Live and MiKTeX are also using pdfTeX for the command latex, but generating DVI with pdfTeX in DVI mode.

If you want to know, if pdfTeX and not LuaTeX is running, then you can exclude luatex by \ifluatex of package ifluatex and then testing for \pdftexversion, for example:

  \typeout{This is LuaTeX}%
  \expandafter\ifx\csname pdftexversion\endcsname\relax
    \typeout{This is neither LuaTeX nor pdfTeX}%
    \typeout{This is pdfTeX in \ifpdf PDF \else DVI \fi mode}%

Testing for package driver options and …

Some TeX engines and modes can be detected at TeX macro level and the packages (or its configuration files) are automatically loading the right drivers, e.g.:

  • pdfTeX and LuaTeX in PDF mode
  • XeTeX

DVI drivers are different. The DVI driver program is running after the TeX run, thus there is no way of knowing the future. The default is often dvips.

Therefore in many cases you won't need complicate switch structures to differentiate between the different TeX compilers, just loading the package is enough:


In case of package fontspec you need to test for the Unicode aware TeX compilers, for example:

  % other LuaTeX setup
    % other XeTeX setup
    % other font setup
share|improve this answer
using package ifxetex is also possible – Herbert Oct 6 '12 at 18:52
Great, thanks! Eventually, I'm looking for a way to have one template that I can use with pdfTeX, luaTeX, or XeTeX, and that loads the packages necessary for each one automatically. My approach after this question is \ifxetex XeTeX \else\ifluatex LuaTeX \else\ifpdf pdfTeX \else something else \fi\fi\fi. Not sure if I should've asked that directly in a question? – doncherry Oct 6 '12 at 18:56
I have added some more cases in the answer, but feel free to ask a new question. – Heiko Oberdiek Oct 6 '12 at 20:05

use the package ifluatex instead with \ifluatex ... \else ... \fi

share|improve this answer

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.