Question

Is there a way, in a LaTeX style/class file, to detect which output device is being used (or at least which capabilities it has)? The reason is, I'm writing a class file in which I want to use some Postscript-specific packages (e.g. pstricks) if Postscript is available, but if I just write

\RequirePackage{pstricks}

then of course bad things happen if I'm compiling the document with pdflatex. So ideally I'm looking for something I can use like

\if@postscriptokay\RequirePackage{pstricks}\fi

It seems like this must be possible because I know packages like pgf can change their behavior to use appropriate graphics commands based on the output device, but I've done some Google searches and checked in my LaTeX book and haven't found a way.

Was it helpful?

Solution

\usepackage{ifpdf}

\ifpdf
  % nothing
\else
  \RequirePackage{pstricks}
\fi

OTHER TIPS

You can detect pdfTeX like this (this is what ifpdf.sty does):

\makeatletter
\ifx\pdfoutput\@undefined
  no pdfTeX
\else\ifnum\pdfoutput<1
  pdfTeX is outputting a .dvi file
\else
  pdfTeX is outputting a .pdf file
\fi\fi

graphicx.sty, hyperref.sty and pgf.sty have their own autodetection mechanisms built in. They load a different driver file (like pdftex.def and hpdftex.def) based on the autodetection and the package option. If you load any of these in your .tex file, try to get the information which driver they loaded. The relevant driver files are:

/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-*.def
/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def
/usr/share/texmf-texlive/tex/latex/graphics/*.def
  /usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def

The name of the driver for pgf.sty and graphicx.sty is stored in the macro \Gin@driver. You can inspect this macro after loading any of these packages.

Have a look at packages pstool and auto-pst-pdf. They are here to help use pstricks and friends with pdfLaTeX.

If you are using the KOMA-Script package (which I can really recommend, unless you need to use a different style of course) you already have a macro for this: \ifpdfoutput{pdf output}{dvi output} is defined in that package. If not, use the ifpdf package as has already been mentioned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top