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'm experiencing a problem similar to this one: Package ifpdf Error

After upgrading to a more recent version of TeX Live, my pre-existing documents stopped compiling, with complaints that \ifpdf was already defined. My project is large and pulls in a lot of packages, so I don't know which one is defining \ifpdf. Using \let\ifpdf\relax after the \documentclass, as suggested in the answers to the other question, fixes the problem on the newer TeX Live. However, this breaks the document on older versions of TeX Live, where I still need it to compile for various reasons. (I think I'm getting malformed PDFs from pdfTeX 3.1415926-2.4-1.40.13, but that's another topic.)

Is there any simple, straightforward way of finding out which package is defining \ifpdf when it shouldn't be? I could presumably figure it out by trial and error, by bisection, but this is a large, complicated project, and that would be a lot of work. If that worked, would knowing this allow me to make my file compile on both versions of TeX Live?

Is there some other way of making a more robust fix? Can I somehow test somewhere to see whether \ifpdf has been defined, and then define it conditionally at that point?

[EDIT] I figured out the problem. It wasn't another package, it was some code in my own .cls file, which I'd cut and pasted from somewhere probably 15 years ago:

\pdffalse % we are not running PDFLaTeX
\pdfoutput=1 % we are running PDFLaTeX


I was able to make it run on both (modern) versions of texlive by shortening this to the following:


This probably breaks compatibility with dvi-flavored tex, but I don't care about that.

share|improve this question

closed as too localized by egreg, David Carlisle, Torbjørn T., Martin Schröder, Stefan Kottwitz Jun 1 '13 at 22:45

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

You could try using a condition: \ifx\ifpdf\undefined\else\let\ifpdf\relax\fi – Werner Jan 30 '13 at 4:06
@Werner: Thanks for the suggestion, but that caused an error on the old texlive, where \ifpdf wasn't being defined and needed to be. I edited the question to show the solution I found that actually worked. – Ben Crowell Jan 30 '13 at 6:37

\ifpdf is defined by package ifpdf. Thus you can replace your code by \RequirePackage{ifpdf}.

The package/class that defines \ifpdf can be found by testing, whether \ifpdf is undefined or already defined. This can be done by

  • \show\ifpdf stops the compilation and prints the meaning of \ifpdf on the console, examples for the result:

    > \ifpdf=undefined.
    l.1 \show\ifpdf


    > \ifpdf=\iftrue.
    l.3 \show\ifpdf
  • \meaning\ifpdf returns a string with the meaning of the token. This can be used to write something to the console or .log file, e.g.:


    Example outputs:




This methods can help narrowing down possible candidates that define \ifpdf. Then the package files can be inspected and searched for \ifpdf to find the definition.

BTW, the old class code definition for \ifpdf is wrong. Since many years latex also uses pdfTeX! It can generate both DVI and PDF. If a user runs latex he usually wants to have DVI, but \pdfoutput is defined and the class forces a mode switch to PDF.

share|improve this answer

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