[Tex/LaTex] TikZ and auto-pst-pdf break Ghostscript

auto-pst-pdfghostscriptmiktextikz-pgf

After profiting enormously from other people's questions here, I finally need to ask one myself: since I updated my MiKTeX 2.9 installation a week ago, I can't compile my PhD thesis anymore.

I use pdflatex in conjunction with the auto-pst-pdf package to include graphics obtained with matlabfrag. I also need TikZ for a couple of diagrams and custom chapter and section headings that I programed using the features of the memoir class.

In this configuration, Ghostscript 9.05 (the one included in MiKTeX 2.9) crashes with an irrecoverable error. Here's a minimal example to reproduce the problem:

\documentclass{article}

% (A) alternatively, comment the following two lines
\usepackage{tikz}
\usetikzlibrary{arrows}

\usepackage{psfrag}
\usepackage{auto-pst-pdf}

\begin{document}

% (B) or those two lines in order to prevent the Ghostscript error
\begin{center}
\end{center}

\input{brachistochroneA1.tex}
\includegraphics[width=\textwidth]{brachistochroneA1}

\end{document}

The weird thing is that Ghostscript doesn't break if either the TikZ import or the \begin{center} and \end{center} block is commented out. (I expect that this also holds for other blocks, but I haven't tested it yet.)

I'd greatly appreciate any help!

Also, as an alternative, I tried pstool (since the auto-pst-pdf manual suggests its use as replacement), but this gives me different trouble: the \includegraphics{...} directive takes subdirectories (as usual) with a forward slash /, but since I'm on Windows, these need to be translated into backslashes \ for shell-escape commands. Unfortunately, pstool seems not to be doing this, resulting in command line errors when copying the bbl file. (Should I ask this in a separate question?)

Best Answer

Try

   \usepackage{ifpdf}
    \ifpdf
      \usepackage{tikz}
    \fi

Remark: Why the new pgf version breaks in auto-pst-pdf hasn't been analysed yet. So this is more a work-around then a solution.

Related Question