How can I detect inside a TeX file which engine (pdftex/xetex/luatex) is used to compile the file? Is there a LaTeX package that provides this functionality?

5 Answers 5


Yes, there is — iftex. There are also ifxetex and ifluatex packages.

Internally these packages rely on checking if engine-specific primitives exist, such as \XeTeXversion.

  • 5
    At the time of writing this comment, the iftex package seems to have been revamped to work as a superset of sorts to the other ones mentioned (ifxetex and ifluatex). iftex also provides their checks (\ifxetex, \ifluatex) among others (\ifluahbtex, ...). My use case was to enforce LuaTeX usage and inform users, for which iftex already ships with a solution: \RequireLuaTeX (etc.).
    – Alex Povel
    Oct 29, 2020 at 11:52

Packages ifxetex, ifluatex, ifpdf. You can also look e.g. in hyperref to check how it detect which driver it should use.

  • 3
    ifpdf just detects pdf or dvi modes, you can not detect engine with it.
    – IRAN
    Mar 12, 2011 at 2:00

I am using the following code:

%% ================================================================== 
%% Macros specific for latex / pdflatex / xetex compilers 
    \typeout{^^J *** PDF mode *** } 
    \typeout{^^J *** DVI mode ***} 
    \typeout{ *** LuaLaTeX *** ^^J}
    % patch \typein
    % see http://tex.stackexchange.com/questions/12435/incompatibilities-between-lualatex-and-typein
        \read\@inputcheck to#1%
    % LuaLaTeX specific code
    \typeout{ *** XeLaTeX *** ^^J} 
    % XeLaTeX specific code
    \typeout{ *** LaTeX *** ^^J} 
\typein{} % pause to watch result
%% =====================================================================

LuaLaTeX can run both in DVI and PDF modes.


We can ask directly to primitives used in engines. We needn't any LaTeX package.

\ifx\numexpr\undefined\else        eTeX is activated\fi
\ifx\mubyte\undefined\else         encTeX is activated\fi
\ifx\pdftexversion\undefined\else  pdfTeX is working\fi
\ifx\XeTeXrevision\undefined\else  XeTeX is working\fi
\ifx\directlua\undefined\else      LuaTeX is working\fi

\newif\ifpdftex \newif\ifxetex \newif\ifluatex
\ifx\pdftexversion\undefined\else  \pdftextrue \fi
\ifx\XeTeXrevision\undefined\else  \xetextrue  \fi
\ifx\directlua\udefined\else       \luatextrue \fi

\ifluatex \else \chardef\outputmode=0 \fi
\ifpdftex \let\outputmode=\pdfoutput \fi
\ifxetex  \chardef\outputmode=1 \fi

\ifnum\outputmode>0 PDF is created\else DVI is created\fi
  • 1
    You’re forgetting pTeX and upTeX
    – egreg
    May 12, 2023 at 6:17
  • 1
    To be fair this is roughly how the packages are implemented anyway, so you don't really simplify anything doing this apart for academical purpose. (plus a few odd stuff.)
    – user202729
    May 12, 2023 at 6:30

In a sufficiently new version, expl3 is built into the LaTeX format, so commands such as \sys_if_engine_pdftex:TF etc. are available by default:

interface3.pdf snippet

There's no equivalent of \ifTUTeX for checking if the engine supports Unicode tokens as far as I can see, however.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .