# Why can't I get pstricks with auto-pst-pdf (and cropping) running on MikTeX?

\documentclass{minimal}
\usepackage[pdf]{pstricks}

\begin{document}

\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}


I run it with:

pdflatex -shell-escape Test.tex > log.txt 2>&1


But stdout says:

PDFCROP 1.33, 2012/02/01 - Copyright (c) 2002-2012 by Heiko Oberdiek.
!!! Error: Ghostscript exited with error code 1!


The same happens when using \usepackage{pstricks} \usepackage{auto-pst-pdf}.

If I use \usepackage{pstricks} \usepackage[crop=off]{auto-pst-pdf} then it works!

I use Windows 7 x64, MikTeX 2.9 x86 (complete system) with latest packages, installed latest ActivePerl x86 and also applied the pdfcrop fix (as the related problem appeared earlier).

You see all details in the logs for stdout, Test.log, and Test-autopp.log.

Any ideas?

UPDATE: I tried to manually run pdfcrop and got the same error. When I run it with --debug I see that it can't locate the Ghostscript executable gswin32c.exe. I looked into the MikTeX bin/ folder because I thought it is there, but it isn't. Do I have to install Ghostscript separately?

-
Maybe I should ask: How can I get more detailed error information than !!! Error: Ghostscript exited with error code 1!? –  neo Sep 8 '12 at 16:37
Use TeXLive and see what happens? –  I am who I say I am Sep 9 '12 at 3:36
Ghostscript is not included in MikTeX. –  percusse Sep 9 '12 at 19:37
@percusse: Why not? I mean, why include pdfcrop if it can't be used anyway? I always thought MikTeX is a complete solution. –  neo Sep 9 '12 at 20:01
Ghostscript has, as far as I know, license issues to be distributed freely. It's a standalone product and not a part of MikTeX family. –  percusse Sep 9 '12 at 20:31

I made some test with miktex 2.9.: auto-pst-pdf with pdfcrop works for me only if an external perl is in the path. An external ghostscript is not necessary. This here is the "minimal working path" (I guess the windows path is needed for cmd.exe):

Path=J:\MiKTeX2.9\miktex\bin;C:\WINDOWS\system32;J:\Perl\bin;

-
I already have Perl in my PATH, this was done automatically when installing ActivePerl. –  neo Sep 8 '12 at 15:16
@neo: And what else have you in your path? Is there another ghostscript? Does it work if you restrict the path to the entries I mentioned? –  Ulrike Fischer Sep 9 '12 at 16:58
There's no other ghostscript in my path. I don't think it's a path problem anyway because the error says it exited with error code 1 which means that it actually run ghostscript. I will delete this question soon as it seems I get away with crop=off for my specific cases (using pstree). –  neo Sep 9 '12 at 18:54
Forget that. See my update! We're getting closer.. –  neo Sep 9 '12 at 19:15

I really don't know why, but I had to separately install Ghostscript so that pdfcrop could use gswin32c.exe. I thought it was included (shouldn't it?) in MikTeX.

Another note: Although my minimal example is working now, I couldn't get it working for bigger documents. I figured out that there seems to be some (unwanted?) difference between

\usepackage{pstricks,auto-pst-pdf}


and

\usepackage[pdf]{pstricks}


Only the first worked! For the second one I got strange Ghostscript errors:

Error: /typecheck in --div--
Operand stack:
1   0   0.0   -0.0367123   a   65781.8
Execution stack:
%interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1926   1   3   %oparray_pop   1925   1   3   %oparray_pop   1909   1   3   %oparray_pop   1803   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   --nostringval--   4   --nostringval--   %repeat_continue   --nostringval--
Dictionary stack:
--dict:1169/1684(ro)(G)--   --dict:0/20(G)--   --dict:122/200(L)--   --dict:104/300(L)--
Current allocation mode is local
Current file position is 167839

-
You should ask your problem with \usepackage[pdf]{pstricks} vs. \usepackage[pdf]{pstricks} as a separate question, so it could potentially be seen by more people with a clue to answer. –  Speravir Sep 9 '12 at 20:55
write \listfiles into your preamble and then show the file list which is at the end of the log file. –  Herbert Sep 10 '12 at 5:48
@Herbert: Here you go: pastie.org/4694273 –  neo Sep 10 '12 at 7:44
@neo: please create a minimal example with the article class which shows the problem. Then it is easier to see what's going wrong. –  Herbert Sep 10 '12 at 8:17
@Herbert: Alright, as Speravir already suggested I will create a new question for that issue when I got some time. I'll link it from here then. –  neo Sep 10 '12 at 8:19