# Taking advantage of auto-pst-pdf when XeLaTeXing

I use a lot of PSTricks-based graphics. Since graphics generation takes an awful long compilation time over XeLaTeX, I resort to pdfLaTeX first using the auto-pst-pdf package. On a later run, meaning, once the graphics have been generated, I can use the off option so as to use the already-existing pdf file issued by auto-pst-pdf, but this works only over pdfLaTeX. I've tried with the \savepicture and \usepicture commands over XeLaTeX, but I don't get the graphics.

My question goes thus: What would be a "good" approach to using the auto-pst-pdf-generated file with the graphics in an automated way when compiling over XeLaTeX in order to have this automated? I know I could split the auto-pst-pdf-generated file and save the graphics on a separate basis, but I'm asking about a more efficient approach in terms of "manual tweaking."

One would have to rewrite pst-pdf and auto-pst-pdf to make them usable with xelatex as they assume a lot regarding the compilation method with latex/dvips to create the images, and you can't use latex/dvips with a normal xelatex document as it can't handle the fonts.

But you can use the externalize library of tikz/pgf:

\documentclass[]{scrartcl}
\usepackage{pstricks}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzset{external/system call={xelatex --jobname="\image"
"\texsource"}}
\tikzexternalize

\begin{document}
%\tikzset{external/force remake} %uncomment if the images should be remade
\begin{tikzpicture}
\node{\begin{pspicture}(-5,-3)(5,8)
\psline(0,1)(2,3)
\end{pspicture}};
\end{tikzpicture}

\begin{tikzpicture}
\node{\begin{pspicture}(-5,-5)(5,5)
\psline(-4,-4)(-4,4)
\psframe[linestyle=none,fillstyle=vlines](-4,-4)(-4.75,4)
\end{pspicture}};
\end{tikzpicture}
\end{document}

• @{Ulrike Fischer, Herbert}: Both answers are useful and valuable. The reason why I'm selecting Ulrike's is only that I think it fits better my question in that it doesn't require that I call any script, and it can be entirely embedded in my LaTeX code (even though I understand that with arara this can be said also about Herbert's answer). I'm sure I'll be using frequently any one of the two answers. – Marcos Jan 13 '14 at 21:37

It makes no sense to use auto-pst-pdf with xelatex. xelatex always takes the route xdvi->xdvipdfmx with or without auto-pst-pdf. And, of course, auto-pst-pdf itself cannot handle xelatex.

As an alternative use the script pst2pdf which is part of TeXLive and MikTeX:

pst2pdf <file.tex> -x


( -x is for xetex) Or without creating new images

pst2pdf <file.tex> -x --noImages


<file>-pst.tex|pdf is the TeX|PDF file which holds all images on single pages. And <file>-pdf.tex|pdf ist the TeX/PDF file which uses \includegraphics instead of the pspicture environments.