[Tex/LaTex] Compilation issue with pdfLaTeX and auto-pst-pdf

auto-pst-pdfcompilingpdftexpstricks

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?

Best Answer

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.