EPS Graphics

EPS graphics files are the traditional way to insert graphics files into LATEX documents. As mailing lists are full with questions concerning EPS graphics, we will discuss some important aspects and demonstrate how Kile supports them.

LATEX and EPS Graphics

If you decided to use the traditional LATEX to produce PS or PDF output, you will probably run into some problems with graphics. You have to use EPS graphics (Encapsulated PostScript), no JPEG or PNG files. This should be no problem, as there are a lot of converters like convert from the excellent ImageMagick package. But, it needs some time of course.

The EPS files are used by both LATEX and the DVI-PS converter:

  • LATEX scans the EPS file for the bounding box line, which tells LATEX how much space to reserve for the graphics.

  • The DVI-PS converter then reads the EPS file and inserts the graphics in the PS file.

This has some implications:

  • LATEX never reads the EPS file if the bounding-box parameters are specified in the graphics-insertion command.

  • Since LATEX cannot read non-ASCII files, it cannot read the bounding-box information from compressed or non-EPS graphics files.

  • The EPS graphics are not included in the DVI file. Since the EPS files must be present when the DVI file is converted to PS, the EPS files must accompany DVI files whenever they are moved.

Now you can call LATEX, and a DVI-PS converter like dvips to create your PostScript document. If your goal is a PDF document, you should run dvips with option -Ppdf and then call ps2pdf. You will find a lot of documents describing this solution.

The PostScript Way of Kile

Kile helps you to get the bounding-box information. If you have installed ImageMagick package, Kile will extract this information from the EPS file and insert it as an option. This is done automatically when you select the graphics file. There are two advantages to proceed like this:

  • The information is already scanned in the dialog, and need not to be done by LATEX later on.

  • Even more important is that the width and height of the picture can be calculated, when the its resolution is known. This information will be shown near the top of the dialog, and may serve as a clue when you want to scale the graphics.

  • Kile can also support zipped or gzipped EPS files, which are much smaller than uncompressed EPS files. But, this feature can only be used with a special system setup and a change of your local graphics configuration, like it is described in the Bitmap Graphics section.

The PostScript Way and Bitmap Graphics

If your systems allows shell-escape, Kile also supports an easy way to include bitmap graphics, if you set up your TEX system properly. There is no need to convert JPEG or PNG graphics, this can be done automatically when the DVI file is converted to PS.

LATEX needs some information about the file suffixes. The package graphicx looks for a file graphics.cfg, which must be somewhere in your search path for LATEX documents. Search for entries like:

   \DeclareGraphicsRule{.pz}{eps}{.bb}{}%
   \DeclareGraphicsRule{.eps.Z}{eps}{.eps.bb}{}%
   \DeclareGraphicsRule{.ps.Z}{eps}{.ps.bb}{}%
   \DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{}%
   \DeclareGraphicsRule{.eps.gz}{eps}{.eps.bb}{}%

and replace these lines with:

   \DeclareGraphicsRule{.pz}{eps}{.bb}{}%
   \DeclareGraphicsRule{.eps.Z}{eps}{.eps.bb}{}%
   \DeclareGraphicsRule{.ps.Z}{eps}{.ps.bb}{}%
   \DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{}%
   % changed or new graphic rules
   \DeclareGraphicsRule{.eps.zip}{eps}{.eps.bb}{`unzip -p #1}%   zipped EPS 
   \DeclareGraphicsRule{.eps.gz}{eps}{.eps.bb}{`gunzip -c #1}%   gzipped EPS
   \DeclareGraphicsRule{.jpg}{eps}{}{`convert #1 eps:-}%         JPEG
   \DeclareGraphicsRule{.gif}{eps}{.bb}{`convert #1 eps:-}%      GIF
   \DeclareGraphicsRule{.png}{eps}{.bb}{`convert #1 eps:-}%      PNG
   \DeclareGraphicsRule{.tif}{eps}{.bb}{`convert #1 eps:-}%      TIFF
   \DeclareGraphicsRule{.pdf}{eps}{.bb}{`convert #1 eps:-}%      PDF-graphics

You will find this file, for example in Debian, at /etc/texmf/latex/graphics.cfg. The best way to proceed is to copy this file to your local texpath and then change this file. See the yours TEX distribution manual to learn how to get a list of your TEX folders.

With this configuration file you are able to insert bitmap graphics and zipped or gzipped EPS files in LATEX. The command for conversion is given by dvips. When you look at the conversion command you will see that no extra file is created. The result of the conversion process is directly piped into the PS file. The only thing LATEX must know is the size of the graphics, and therefore we need the bounding box, which is provided by Kile.

Some say that this way is insecure; you have to decide on how to work. In any case, you need no bounding box, as Kile will extract this information from all types of graphics.

PDFLATEX and EPS Graphics

As already stated, PDFLATEX is not able to handle EPS graphic files, but converters like epstopdf will help. The best way is to include package epstopdf, which must follow the graphicx package.

   \usepackage[pdftex]{graphicx}
   \usepackage{epstopdf}

Now you can already include EPS graphics, if you run pdflatex with option --shell-escape, but we can make it even better and also handle zipped or gzipped EPS files. Again we have to change the graphics configuration file graphics.cfg like above. This time we search for:

   % pdfTeX is running in pdf mode
   \ExecuteOptions{pdftex}%

and simply add some lines.

   % pdfTeX is running in pdf mode
   \ExecuteOptions{pdftex}%
   \AtEndOfPackage{%
      \g@addto@macro\Gin@extensions{.eps.gz,.eps.zip}%
      \@namedef{Gin@rule@.eps.gz}#1{{pdf}{.pdf}{`gunzip -c #1 | epstopdf -f >\Gin@base.pdf}}%
      \@namedef{Gin@rule@.eps.zip}#1{{pdf}{.pdf}{`unzip -p #1 | epstopdf -f >\Gin@base.pdf}}%
   }%

With these lines, PDFLATEX is able to handle EPS files, and hopefully there should be no more issues concerning graphics.