# Compilation issue with pdfLaTeX and auto-pst-pdf

I am using a lot of png/jpg images in a document, so I decided to use pdfLaTeX. The main issue of this approach is that PSTricks is not directly supported. Since I found a package (auto-pst-pdf) supposed to solve this, I gave it a go. But I found a problem.

Let's take a simple example:

\documentclass[12pt,a4paper]{report}

\usepackage[pdf]{pstricks}
\usepackage[on]{auto-pst-pdf}

\begin{document}

This is a test file
\newline
\newline
\begin{pspicture}(-5.25,-5.25)(5.25,5.25)
\pscircle*[linecolor=cyan]{5}
\psgrid[subgriddiv=0,gridcolor=lightgray,gridlabels=0pt]
\Huge\sffamily\bfseries
\rput(-4.5,4.5){A} \rput(4.5,4.5){B}
\rput(-4.5,-4.5){C}\rput(4.5,-4.5){D}
\rput(0,0){auto-pst-pdf}
\rmfamily
\rput(0,-3.8){PSTricks}
\rput(0,3.8){\LaTeX}
\end{pspicture}

\end{document}


If we try to compile this file in its folder (with output folder = build):

pdflatex -shell-escape -output-directory=build test.tex


Everything works well, and the resulting PDF is moved to result. Now, let's imagine that we have a folder with the following structure:

-- root (Makefile)
|___ src (tex files)
|___ build (everything generated by pdfLaTeX)


If we call make from the root folder, the following command will be executed:

pdflatex -shell-escape -output-directory=build src/test.tex


Even though the only difference is the location of the tex file, this does not work: the temporary image files (dvi, ps, pdf) are not compiled, and the resulting document does not get its figure.

I have tried using some auto-pst-pdf options:

\usepackage[on,
latex={-out-directory=. -jobname=test-pics test.tex},
dvips={-o test-pics.ps test-pics.dvi},
pspdf={-dAutoRotatePages=/None test-pics.ps test-pics.pdf},
crop=off
]{auto-pst-pdf}


But this does not work so far, and I do not know if that is the right way to do this. Has anyone faced any similar problem, and if yes, how did you solve it?

-
I found a similar problem: tex.stackexchange.com/questions/36414/… –  BenC Jun 13 '12 at 15:54

You are starting pdflatex in root. So this is the current directory. auto-pst-pdf will at first call latex --jobname=test-autopp test to generate a test-autopp.dvi with the pictures. This first step will already fail as latex obviously can't find test in the current directory root and has no idea that it should look in scr.

You should always start pdflatex in the directory of the main file. Everything else can get quite confusing.

-
Indeed, which is why I tried to use some custom commands in \usepackage{auto-pst-pdf}, but it still fails for some reason. If in src, I call pdflatex -shell-escape -output-directory=../build test.tex, the file is properly generated, the only issue is that the temporary pdf is located in src too (I like having a clean src folder). Still, a temporary folder option to pdflatex would solve this problem I guess. –  BenC Jun 13 '12 at 15:23
@BenC It doesn't help to add options which tells LaTeX/dvips where to write something or how to name the output. The LaTeX call of auto-pst-pdf has problems to find its input. It's expecting it in the current directory and there is no option to change this. You would have to hack the code. I suggest to write some batch file which either moves all you source files to some temporary folder before compilation, or which cleans up you scr-folder after compilation. –  Ulrike Fischer Jun 13 '12 at 16:24
Theoretically, using auto-pst-pdf options to change the output directory, and \graphicspath to use that output directory instead of the current one should be doable, because pst-pdf relies on \includegraphics and auto-pst-pdf is just a wrapper. Does that make sense? –  BenC Jun 13 '12 at 17:56
No. The problem is not that (pdf)latex can't find the graphic, but that latex can't find your main file and so can't even start to generate the graphic. –  Ulrike Fischer Jun 13 '12 at 18:06
If I launch pdflatex from the src folder, latex, dvips, ps2pdf and pdfcrop all find the files, now I am just trying to move the temporary files to the build folder (test-pics.pdf that remains for instance), since that's the only thing possible apparently. –  BenC Jun 13 '12 at 18:13

\graphicspath{{./}{./src/}{./build/}}

This did not work for me. \graphicspath is used by the latex compiler to find the pictures, but will not help for this compilation step, will it? –  BenC Jun 13 '12 at 14:58
it should work with \usepackage{auto-pst-pdf} –  Herbert Jun 13 '12 at 15:15