4

I'm working on a long document (written by someone else). The author has used a lot of pstricks pictures, and I'd like to compile the document using pdflatex (without doing the detour over dvi). The documentclass depends on TikZ, and I've noticed the following very strange behaviour.

Compliling

\documentclass{article}

%% Works if we don't load tikz
\usepackage{tikz}
\usepackage[pdf]{pstricks}

\begin{document}

% Works if we load tikz, but don't use center
\begin{center}
\begin{pspicture*}(-3.24,-1.49)(10.23,5.7)
\psline(-1,0)(6,0)
\end{pspicture*}
\end{center}

\end{document}

the auto-pst-pdf phase crashes with a Ghostscript error:

"-------------------------------------------------"
"auto-pst-pdf: Auxiliary LaTeX compilation"
"-------------------------------------------------"
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014/W32TeX) (preloaded format=latex)
entering extended mode
Error: /typecheck in --div--
Operand stack:
   1   0   0.0   TeXcolorgray   65781.8
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1932   1   3   %oparray_pop   1931   1   3   %oparray_pop   1915   1   3   %oparray_pop   1803   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   --nostringval--   5   --nostringval--   %repeat_continue   --nostringval--
Dictionary stack:
   --dict:1180/1684(ro)(G)--   --dict:0/20(G)--   --dict:118/200(L)--   --dict:173/300(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 91942
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.

!!! Warning: Empty Bounding Box is returned by Ghostscript!
!!!   Page 1: 0 0 0 0
!!! Either there is a problem with the page or with Ghostscript.
!!! Recovery is tried by embedding the page in its original size.

==> 1 page written on `basic-pics.pdf'.
"-------------------------------------------------"
"auto-pst-pdf: End auxiliary LaTeX compilation"
"-------------------------------------------------"

If I don't load TikZ, everything works ok. Weirdly, if I remove the \begin{center} and \end{center}, everthing works ok too.

This is running TexLive14 on a Windows machine, but the same thing happens on a recent version of MacTex on a Mac machine.

In the end, the center environment won't be there, and the problem will go away by itself. Nevertheless, I'd be interested in a fix or at least any ideas where to dig for the problem. I haven't used pstricks and auto-pst-pdf much myself.


Update Apparantly, center wasn't the full story. I redefined the center-environment into a dummy do-nothing, and all seemed (sort-of) well until I compiled the full document with the real documentclass. The documentclass builds on memoir, using the showtrims option. Without showtrims, everything is ok, but with it I get the same errors as above.

Is there a way to configure auto-pst-pdf to use a different document class for its temporary creation of figures?

mrf
  • 904
  • No errors running pdflatex here using TeXlive 2014 on Linux. But the PDF output has 2 blank pages. Normal with latex and the DVI ouput has one single page with the horizontal line. – Sigur Nov 02 '14 at 12:43
  • @Sigur Look at the log file. The error is on GS level. – percusse Nov 02 '14 at 12:45
  • @percusse, yes. You're right. The log file shows: !!! Warning: Empty Bounding Box is returned by Ghostscript! !!! Page 1: 0 0 0 0 !!! Either there is a problem with the page or with Ghostscript. !!! Recovery is tried by embedding the page in its original size. – Sigur Nov 02 '14 at 12:48
  • If you compile with xelatex (removing the [pdf] option), there is no problem. – Bernard Nov 02 '14 at 13:20
  • @Bernard Yes, but that causes other problems (letterspacing small caps doesn't work with xelatex at least not with microtype, textls). Also compiling this document with xelatex is extremely slow. – mrf Nov 02 '14 at 13:46
  • If I were you, I would put each diagram (either coded in PSTricks or TikZ or others) in a separate compilable input file (usually we use standalone document class), compile it with latex-dvips-ps2pdf (for PSTricks and TikZ) or pdflatex (for TikZ) to obtain a PDF version for each diagram. Then you can import all the diagrams (in PDF) from within your main input file and compile the main input file with pdflatex. With this approach, you can get many advantages: 1. you can use microtype, 2. your input files are easy to maintain, 3. you can reduce the compilation time, 4. etc. – kiss my armpit Nov 02 '14 at 13:49
  • @InPSTrickswetrust Yes, the thought did occur to me. A downside is that the original author will have to work further with the document, and he's not very tech-savvy. That solution might be too complicated for him. (Also, there are hundreds of figures and I'd rather not spend the time stripping the figures out of the tex-files, even if that step can be somewhat automated.) – mrf Nov 02 '14 at 14:11
  • Avoid the minimal class. – egreg Nov 02 '14 at 14:17
  • @egreg I don't really use the minimal class, but I thought it was still the recommended one for MWE:s – mrf Nov 02 '14 at 14:23
  • @mrf See http://tex.stackexchange.com/questions/42114/why-should-the-minimal-class-be-avoided – egreg Nov 02 '14 at 14:27
  • @mrf: XeLaTeX is very slow in general for the first compilation, much less slow for subsequent compilations. As for letterspacing, fontspec can use directly the LetterSpace=… font feature of Opentype fonts. – Bernard Nov 02 '14 at 14:41

2 Answers2

4

It works for me if I add \leavevmode before \begin{pspicture*}.

I guess this has to do with the changes TikZ makes to some of the innards of LaTeX, but going through the details could be very challenging.

Since adding \leavevmode shouldn't be a concern, because direct inclusion in the vertical list is something that should be avoided in LaTeX anyway, you can add

\makeatletter
\@namedef{pspicture*}{\leavevmode\pspicture*}
\makeatother

to your document preamble.

egreg
  • 1,121,712
  • Thank you! That solved the center problem, but alas not the showtrims one. I posted my alternative workaround which seems to take care of both issues. – mrf Nov 02 '14 at 15:01
2

Seems like I found a workable "solution". Patching the documentclass with

\RequirePackage{ifpdf}
\ifpdf
\LoadClass[a4paper,11pt,twoside,fleqn,showtrims]{memoir}
\else
\LoadClass[a4paper,11pt,twoside,fleqn]{memoir}
\fi

and a similar guard where TikZ is loaded

\ifpdf
\RequirePackage{tikz}
\fi

sorts everything out. The actual guarding is done via an option for the documentclass, so that TikZ still loads normally regardless of whether we're compiling to pdf or not when the workaround is not needed.

mrf
  • 904