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.

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?

share|improve this question
add comment

3 Answers 3

up vote 20 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
1  
ifpdf just detects pdf or dvi modes, you can not detect engine with it. –  IRAN Mar 12 '11 at 2:00
add comment

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.

share|improve this answer
add comment

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.