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 would like to be able to import an EPS file in to LaTeX while using some 3rd party image viewer/editor to quickly find crop coordinates. What are some good free tools for this? GIMP (the GNU Image Manipulation Program) is a free program that works on all major platforms, but it is not a vector graphics editor; will it work? It appears that you can choose any resolution with GIMP when you import. Additionally, since an EPS file is a vector graphics file, are there native units that LaTeX will recognize?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Method A: Dealing directly with PostScript

Since you're dealing with PostScript images, one option might be to use GhostView; I've done so successfully in the past. As an example, consider tiger.eps.

  1. Open tiger.eps using GhostView.

  2. Show the bounding box if you wish to see the extent of the existing whitespace:

    enter image description here

  3. Position the cursor on to identify the left, bottom, right and top coordinates. In my example, these are l b r t = 15 175 564 743.

  4. Open tiger.eps and find the lines starting with %%BoundingBox in the "preamble":

    %!PS-Adobe-2.0 EPSF-1.2
    %%BoundingBox: 1 2 611 792
    
  5. Update this to incorporate the new bounding box:

    %!PS-Adobe-2.0 EPSF-1.2
    %%BoundingBox: 15 175 564 743
    

    There may also be a %%HiResBoundingBox entry, which you can update accordingly.

  6. Refresh the view in GhostView which now shows the cropped bounding box:

    enter image description here

  7. Include as usual via \includegraphics, since the bounding box has been permanently updated. If you don't want to update the EPS permanently, you can also use

    \includegraphics[...,bb=15 175 564 743, clip=true...]{tiger}
    

    in your document.


Method B: Cropping via PDF

  1. Use the command-line conversion

    epstopdf tiger.eps
    

    which produces tiger.pdf.

  2. Use pdfcrop

    pdfcrop tiger.pdf
    

    which produces tiger-crop.pdf.

  3. Convert back to EPS using

    pdftops -eps tiger-crop.pdf tiger.eps
    

    to overwrite tiger.eps with a now-cropped version:

    enter image description here

    New bounding box resembles

    %%BoundingBox: 0 0 548 576
    

    which is marginally different to the manual way described in Method A (which yielded a width of 564 - 15 = 549; height of 743 - 175 = 568).

share|improve this answer
    
Both methods are very nice, especially B, which could be easily added to a script and will probably work for most purposes -- thanks! –  bbarker Apr 14 at 20:43
    
@bbarker: Yes, Method A follows your suggestion (using a vector-graphics viewer) closely. The use of tiger was just to add mooooaaaarrr roooaaaarrr! –  Werner Apr 14 at 20:45

You can use epspdftk, the gui interface to Siep Kroonenberg's epspdf .texlua script. It exists both for Windows and Linux and does everything (converting and cropping the resulting .pdf) in one step. I'll take the example of one of my old graphic files, produced with pstricks and pst-eps, that had a (very) badly computed bounding box. The procedure is very simple: launch epspdftk and check Compute tight bounding box, the click on Open to choose the file to be converted:

enter image description here

Once chosen, you may ask to view the .eps file:

enter image description here

Then click on Convert and save…. A second later, you can look at the resulting .pdf in your favourite pdf viewer:

enter image description here

The .texlua script can also be launched from the command line, if you want to do batch conversion.

share|improve this answer

Firstly, the GIMP does appear to be an adequate and convenient tool for the job. EPS files seem to include a default resolution, which is what the GIMP displays when you open an EPS file, so don't change it:

enter image description here

Next, you can easily use your cursor to find one of two defining coordinates. In this example we do the top-left coordinate. You can see the approximate region of where the cursor is by the small box that is north-west of the figure. The coordinates are shown in the lower-left hand corner of the canvas window. Be sure to choose coordinates that TeX can work with (I don't think the default, px -- pixels, is supported in TeX; What are the possible dimensions / sizes / units LaTeX understands?). In our example we use millimeters (mm):

enter image description here

Now we can import it into a document. Again we will just test this coordinate for now:

\documentclass{article}

\usepackage[english]{babel}
\usepackage{blindtext}

\title{An EPS trimming workflow}
\author{Brandon Barker}
\date{\today}

\usepackage{caption}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}


\begin{document}

% Let's draw a box around the figure so we
% can see where the figure's whitespace ends.
\setlength\fboxsep{0pt}
\setlength\fboxrule{1.5pt}

\begin{figure}[h]
\centering
% give some space for fbox:                    % l       b   r   t
\fbox{\includegraphics[width=0.9\textwidth, trim=104.4mm 0mm 0mm 17.3mm, clip=true]
      {YeastExpFluxCompare}}
\caption{\blindtext}
\label{fig:FluxExpCmp}
\end{figure}

Please refer to Table~\ref{fig:FluxExpCmp}.

\end{document}

This results in the following output, showing that we have correctly made a close crop around the left and top edges of the figure.

enter image description here

share|improve this answer

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.