35

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?

35

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.

14

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 '11 at 2:00
11

I am using the following code:

%% ================================================================== 
%% 
%% Macros specific for latex / pdflatex / xetex compilers 
%% 
\usepackage{ifpdf,ifxetex,ifluatex} 
\ifpdf
    \typeout{^^J *** PDF mode *** } 
\else
    \typeout{^^J *** DVI mode ***} 
\fi 
\ifluatex
    \typeout{ *** LuaLaTeX *** ^^J}
    % patch \typein
    % see http://tex.stackexchange.com/questions/12435/incompatibilities-between-lualatex-and-typein
    \makeatletter
    \def\@xtypein[#1]#2{%
        \typeout{#2}%
        \@tempcnta\endlinechar
        \endlinechar\m@ne
        \read\@inputcheck to#1%
        \endlinechar\@tempcnta
        \@typein}
    \makeatother 
    % LuaLaTeX specific code
\else\ifxetex
    \typeout{ *** XeLaTeX *** ^^J} 
    % XeLaTeX specific code
\else
    \typeout{ *** LaTeX *** ^^J} 
\fi\fi 
\typein{} % pause to watch result
%% =====================================================================

LuaLaTeX can run both in DVI and PDF modes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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