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.

Basically ps2pdf -dEPSCrop doesn't crop to the full extent specified and stops at some mysterious point. I'm trying to trim the white space on the left of the image but -dEPSCrop stops short irrespective of the value I give to the lower left bounding box coordinate of the pspicture environment variable.

Please find a not-so-MWE at: http://pastebin.com/MYAJtLUu

Here's the file stripped of all but the \uput's:

    \documentclass[english,landscape,a4paper]{slides}

    \usepackage{graphics}
    \usepackage{graphicx}
    \usepackage{babel}
    \usepackage{pst-eps}
    \usepackage{pstricks}
    \usepackage{multido}
    \usepackage{pst-node}
    \usepackage{pst-math}
    \usepackage{pstricks-add}

    \begin{document}
        \begin{TeXtoEPS}
            \begin{pspicture}(2,-2.966)(12.064,0)
            \psset{linejoin=1}
            \newcommand{\verysmall}{\fontsize{9}{9pt}\selectfont}
            \verysmall
                    \uput{0.2mm}[180](2.349,-1.66){$s$}
                    \uput{1mm}[225](2.522,-2.043){$c$}
                    \uput{1mm}[-110](4.067,-.9){$b$}
                    \uput{0.25mm}[-45](8.405,-2.671){$a$}
                    \uput{0mm}[0](11.808,-1.66){$t$}
                    \uput{1mm}[100](4.799,-1.199){$d$}
                    \uput{0.5mm}[90](8.653,-2.597){$e$}        
            \end{pspicture}
        \end{TeXtoEPS}
    \end{document} 

I'm trying to create cropped PDF images from pstricks graphics. My workflow is as follows:

    latex NoSoMWE.tex
    dvips -E NoSoMWE.dvi
    ps2pdf -dEPSCrop NoSoMWE.ps NoSoMWE.pdf

Lately however, ps2pdf -dEPSCrop no longer works when the pstricks file makes use of the \uput directive. Cropping however works when all \uput's are removed from the not-so-MWE. Cropping does not work if at most one \uput directive is used.

Please advise, thanks.

share|improve this question
2  
I have no problem with your example ... However, using xelatex or package auto-pst-pdf makes more sense. Using pst-eps is a bit outdated. –  Herbert Aug 10 '11 at 14:42
    
Same here. Compiled under TeXLive 2011, dvips 5.991 and GPL Ghostscript 8.71 on Windows. –  Werner Aug 10 '11 at 17:44
add comment

1 Answer

up vote 2 down vote accepted

If your objective is

  • to get a standalone PDF output without excessive white spaces surrounding it, and
  • to import the resulting PDF from within your main (La)TeX input file

then the remaining paragraphs might be useful for you.

In this answer, I assume you are a Windows user. If it is not the case, you have to adapt the given MS-DOS batch files (also known as make file in other OS).

WARNING: I also assume that the TeX input file, that is used to produce the standalone PDF output, does not load animate package. Why? Because the animation in the standalone PDF output will NO LONGER work when it is imported into your main TeX file by using either \includepdf{} or \includegraphics{}.

I will use the following image in this answer, name it hen.jpg.

enter image description here

I will divide into 2 cases based on whether or not an input file, that is used to produce a standalone PDF output, imports images. If you don't import images in the input file, that is used to produce a standalone PDF output, then the division is not important but you should choose the faster one!

Case 1

This compilation is much much faster than the compilation that will be discussed in Case 2. However, you cannot use this work flow if your input file imports any image of type PDF, PNG and/or JPG. If you only import EPS images or you don't import any image, you should choose this work flow because the compilation is much much much faster!

Create a batch file, name it DevLa.bat, to compile an input file that is used to produce a standalone PDF output.

rem It takes an input file name WITHOUT extension.
echo off

del %1.pdf

rem latex %1
latex %1
dvips -D10000 -t unknown %1
gswin32c -r10000 -dCompatibilityLevel=1.5 -dAutoRotatePages=/None -dPDFSETTINGS=/prepress -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%1.pdf %1.ps

del %1.log
del %1.aux
del %1.dvi
del %1.ps

For simplicity, you can save it in the same directory in which the input file exists. If you want to reuse this batch for other project, then you need to setup PATH environment variable.

The following MWE withoutimage.tex (which does not import images) can be compiled with DevLa.bat

% withoutimage.tex
\documentclass{article}
\usepackage{pstricks,multido}
\SpecialCoor
\psset
{
    linecolor=red,
    arrows=->,
    arrowscale=1.5 0.75
}

\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}
    \begin{pspicture}(-2,-2)(2,2)
        \psframe[linecolor=red](-2,-2)(2,2)
        \multido{\i=0+30}{12}
        {%
            \psline(0.9;\i)
            \uput{1}[\i]{\i}(0,0){$\i^\circ$}%
        }
    \end{pspicture}
\end{document}

by invoking

DevLa withoutimage

And you will get a tight PDF output as follows.

enter image description here

Case 2

This compilation is much much slower than the compilation discussed in Case 1. However, you can use this work flow if your input file imports any image of type PDF, PNG, JPG and/or EPS. If you only import EPS images or you don't import any image, you should choose the work flow in Case 1 because its compilation is much much much faster!

Create a batch file, name it DevXe.bat, to compile an input file that is used to produce a standalone PDF output.

rem It takes an input file name WITHOUT extension.

echo off

del %1.pdf

rem xelatex %1
xelatex %1

del %1.log
del %1.aux

For simplicity, you can save it in the same directory in which the input file exists. If you want to reuse this batch for other project, then you need to setup PATH environment variable.

The following MWE withimage.tex (which does import a JPG image) can be compiled with DevXe.bat

% withimage.tex
\documentclass{article}
\usepackage{graphicx}
\usepackage{pstricks,multido}
\SpecialCoor
\psset
{
    linecolor=red,
    arrows=->,
    arrowscale=1.5 0.75
}

\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}
    \begin{pspicture}(-2,-2)(2,2)
        \psframe[linecolor=red](-2,-2)(2,2)
        \multido{\i=0+30}{12}
        {%
            \psline(0.9;\i)
            \uput{1}[\i]{\i}(0,0){\includegraphics[scale=0.1]{hen}}% please adapt it!
        }
    \end{pspicture}
\end{document}
DevXe withimage

And you will get a tight PDF output as follows.

enter image description here

Importing the stadalone PDF outputs

After getting the standalone PDF outputs, you can import them from within your main input file as follows.

% main.tex
\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[hbtp]
\centering
\includegraphics[width=0.75\linewidth]{withoutimage}
\caption{This is a nice image.}
\end{figure}
\lipsum[2]
\begin{figure}[hbtp]
\centering
\includegraphics[scale=1.5]{withimage}
\caption{This is a nice image too.}
\end{figure}
\lipsum[3]
\end{document}

And it can be compiled using either xelatex or pdflatex.

If the main.tex still have other PSTricks codes with labels, then use xelatex because pdflatex with auto-pst-pdf will break the labels.

And the result is as follows.

enter image description here

share|improve this answer
    
Utterly brilliant! Thanks @xport. –  Olumide Aug 11 '11 at 3:37
    
Why have this useful answer only got 2 votes? –  Sveinung Feb 11 '13 at 8:07
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.