Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've noticed that the pstricks macro psGTriangle, to draw triangles with Gouraud shading does not work in combination with auto-pst-pdf/pdflatex. There is no error message, the pspicture environment is just ignored. Here is minimal example to illustrate the problem :

\documentclass{minimal}

\usepackage{pstricks,pstricks-add}
\usepackage{auto-pst-pdf}

\begin{document}

\psset{unit=0.5cm}

\begin{pspicture}[showgrid=true](-5,-5)(5,5)
  \psGTriangle(-2,-2)(3,-1)(-0.5,3){red}{white}{blue}
\end{pspicture}

\begin{pspicture}[showgrid=true](-5,-5)(5,5)
  \psline(-3,-2)(4,3)
\end{pspicture}

\end{document}

Compiling this example with latex -> dvips -> ps2pdf gives a pdf with both pspictures environment.

latex pdfmini.tex && dvips pdfmini.dvi && ps2pdf pdfmini.ps pdfmini_latex.pdf

Compiling the same example with pdflatex gives a pdf with 2 blank pages and the second pspicture environment on a third page.

pdflatex -shell-escape pdfmini.tex 

Looking in the generated pdfmini-pics.pdf file, it is visible that something is wrong with the figure containing the psGTriangle, even if it is displayed. It seems that some how the crop did not work really fine .

During my research to solve this problem, it appeared that compiling with xelatex renders a good pdf file. However I use the psGTriangle macro in a bigger document, and i'd rather stay with pdflatex (since I'm really not familiar with the xelatex).

Is this problem known, solvable, or do I have to live with it ?

Thank you for your help.

Edit : @percusse: I'm using Ubuntu 12.04 with

  • texlive version 2012.20120611-3~ubuntu12.04.1.

  • pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)

  • XeTeX 3.1415926-2.4-0.9998 (TeX Live 2012/Debian)

share|improve this question
    
Both Xe- and pdf- TeX works fine on my system (MikTeX 2.9 SumartaPDF and AcroRead X). –  percusse Sep 16 '13 at 18:26
    
Use [crop=off], see my answer –  Herbert Sep 17 '13 at 8:35
add comment

2 Answers 2

up vote 3 down vote accepted

Just a suggestion. Put your drawing code in a separate, compilable input file as follows.

% figure.tex
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\psset{unit=0.5cm}

\begin{document}
% figure-1
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
  \psGTriangle(-2,-2)(3,-1)(-0.5,3){red}{white}{blue}
\end{pspicture}
% figure-2
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
  \psline(-3,-2)(4,3)
\end{pspicture}
\end{document}

Compile figure.tex with latex-dvips-ps2pdf sequence to obtain a PDF containing some pages. Each page represent a single diagram.

From your main input file, import the PDF images with \includegraphics (from graphicx package) as follows.

% main.tex
\documentclass{article}
\usepackage{graphicx}

\newcommand\Insert[2][1]{\includegraphics[scale=#1,page=#2]{figure}}

\begin{document}
\Insert{1}

\Insert{2}
\end{document}

Compile the main.tex with pdflatex.

Simulation

The following code simulates the above scenario in a single file. Compile it with pdflatex -shell-escape simulation.tex.

% simulation.tex
\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{figure.tex}
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\psset{unit=0.5cm}

\begin{document}
% figure-1
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
  \psGTriangle(-2,-2)(3,-1)(-0.5,3){red}{white}{blue}
\end{pspicture}
% figure-2
\begin{pspicture}[showgrid=true](-5,-5)(5,5)
  \psline(-3,-2)(4,3)
\end{pspicture}
\end{document}
\end{filecontents*}

\usepackage{graphicx}
\usepackage{pgffor}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages=/None}/ps}{\immediate\write18{\compiler\space figure.\ext}}


\newcommand\Insert[2][1]{\includegraphics[scale=#1,page=#2]{figure}}
\begin{document}
\Insert{1}

\Insert{2}
\end{document}

Note

ps2pdf -dAutoRotatePages=/None figure.ps is used to prevent the ps2pdf from automatically changing the page orientation. The simple example simulating the case in which ps2pdf automatically rotates the page is given as follows.

\begin{pspicture}[showgrid=false](4,4)% grid must be disabled
    \rput{90}(2,2){PSTricks}% the text should be rotated by 90 ccw
\end{pspicture}
share|improve this answer
    
Thank you for this great answer. It solves my problem, even if I still don't understand why it does not work with the auto-pst-pdf package. –  Adam B. Sep 17 '13 at 6:50
    
@AdamB.: Sorry. I don't know why as I don't use auto-pst-pdf that is not suitable for a long document project economically (wasting much time to compile unchanged PSTricks code). –  Please don't touch Sep 17 '13 at 6:58
add comment

use

\documentclass{minimal}    
\usepackage{pstricks-add}
\usepackage[crop=off]{auto-pst-pdf}%%%%%%%

\begin{document}    
\psset{unit=0.5cm}
\begin{pspicture}[showgrid](-5,-5)(5,5)
  \psGTriangle(-2,-2)(3,-1)(-0.5,3){red}{white}{blue}
\end{pspicture}

\begin{pspicture}[showgrid](-5,-5)(5,5)
  \psline(-3,-2)(4,3)
\end{pspicture}

\end{document}

in some special cases the pdfcrop command fails.

share|improve this answer
    
Indeed it solves the problem. Thank you for your help. Can you give more details about those special cases where pdfcrop fails ? –  Adam B. Sep 17 '13 at 9:13
    
If you have no Perl installed then you also need that option. The other cases are very rare, so that I cannot remember. –  Herbert Sep 17 '13 at 9:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.