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.

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

I want to check if my tex document is compiled with LuaTeX (or any other Lua TeX compiler).

The simple approach from the TeXbook is to check the \directlua macro against \@empty, like


If I'm running luatex, everything is fine. If I run tex, the compilation fails with my \errmessage -- fine. But if I run latex, my error does not occur, but the compilation fails because of the undefined \directlua environment. Which \ifx statement works for all TeX dialects? And why not the one which works fine with plain TeX, the one from above? Thanks in advance :)


An solution for this is very easy, but I don't know if it's causing any problems in the future.

  \errmessage{an error}\fi

works well with TeX and LaTeX. Is there a way which is more elegant and doesn't need any additional packages? Otherwise I will post this as answer.

share|improve this question
up vote 13 down vote accepted

\@empty is defined in LaTeX, so your test fails. Why don't you use ifluatex.sty? It will work with plainTeX too,

share|improve this answer
@Ulrike -- thanks for your advice. I read the manual of ifluatex, is it included in texlive standard distributions? We cannot rely on packages which must be installed separately... – Matten Dec 7 '10 at 14:29
I don't have TeXLive but ifluatex is part of the oberdiek bundle and e.g. hyperref and fontspec both load it so I'm pretty sure that is present in every current TeXLive. – Ulrike Fischer Dec 7 '10 at 15:12
In TeXlive 2009 it is included, but I have to check with the maker of TikZ if it's okay to rely on other packages as he wants to keep the dependencies as minimal as possible! Thanks for your advice – Matten Dec 7 '10 at 19:02
@Matten If you are assuming that people will be using new versions of PGF, I'd go so far as to say that you can be sure they'll have ifluatex.sty installed. – Will Robertson Dec 8 '10 at 2:16
@Matten I wouldn't use \undefined with LaTeX. \undefined is safe at the start of a format generation (context is using it there) but in a package it can fail as the probability that a user has defined it is quite high. Use a \veryunlikelythatsomeonewilldefineitcommand from the namespace of your package. – Ulrike Fischer Dec 10 '10 at 9:40

How about iftex? it works fine in plain, and gives you some other useful macros.

It is also included in TeXLive.

share|improve this answer

What about

\ifcsname directlua\endcsname
  Yes, I am running LuaTeX
 Oh no, I give up


I guess that everybody is running etex with \ifcsname these days... There must be a drawback. But which?

share|improve this answer
This wouldn't work if somebody had tested for the \directlua primitive using \@ifundefined because that defines the command while checking. The ifluatex package also does a few sanity checks to avoid issues with nonstandard catcodes, old LuaTeX versions, etc. – Philipp Dec 7 '10 at 23:42
Of course! Thanks for your comment. – topskip Dec 8 '10 at 7:07
For completeness, you can simply add \ifx\directlua\relax No give up. \else Yes!\fi to the true branch of your text. – Bruno Le Floch Oct 22 '11 at 1:57

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.