It's often useful to know whether your macros are operating within PDFTeX or within ("normal") TeX; getting the right answer is surprisingly tricky.
Suppose you need to test whether your output will be PDF or
DVI. The natural thing is to check whether you have access to
some PDFTeX-only primitive; a good one to try (not least because it
was present in the very first releases of PDFTeX) is
\
pdfoutput
. So you try
Except that neither branch of this conditional is rock-solid. The first branch can be misleading, since the "awkward" user could have written:\ifx\pdfoutput\undefined <not running PDFTeX> \else <running PDFTeX> \fi
so that your test will falsely choose the first alternative. While this is a theoretical problem, it is unlikely to be a major one.\let\pdfoutput\undefined
More important is the user who loads a package that uses LaTeX-style testing for the command name's existence (for example, the LaTeX graphics package, which is useful even to the Plain TeX user). Such a package may have gone ahead of you, so the test may need to be elaborated:
If you only want to know whether some PDFTeX extension (such as marginal kerning) is present, you can stop at this point: you know as much as you need.\ifx\pdfoutput\undefined <not running PDFTeX> \else \ifx\pdfoutput\relax <not running PDFTeX> \else <running PDFTeX> \fi \fi
However, if you need to know whether you're creating PDF
output, you also need to know about the value of \
pdfoutput
:
The above is, in essence, what Heiko Oberdiek's ifpdf package does; the reasoning is the FAQ's interpretation of Heiko's explanation.\ifx\pdfoutput\undefined <not running PDFTeX> \else \ifx\pdfoutput\relax <not running PDFTeX> \else <running PDFTeX, with...> \ifnum\pdfoutput>0 <...PDF output> \else <...DVI output> \fi \fi \fi
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ifpdf