Showing posts with label eps. Show all posts
Showing posts with label eps. Show all posts

Monday, 12 May 2008

EPS files and pdflatex

There is this odd quirk in LaTeX. The latex executable compiles your .tex files in the old-fashioned DVI format. As such, it accepts by default only .eps (Encapsulated PostScript) images. pdflatex compiles your .tex files in the standard PDF format. For some mysterious quirk, pdflatex accepts raster formats like .png and .jpg , but does not accept .eps!

Sometimes you want the best of both worlds. An undergraduate of my lab, after some googling, found you can force pdflatex to insert .eps files happily:

1)Install texlive-extra packages, or any other package containing the epstopdf utility.

2) Insert the following code in your .tex file:

\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse
\else
\pdfoutput=1
\pdftrue
\fi
\ifpdf
\usepackage{graphicx}
\usepackage{epstopdf}
\DeclareGraphicsRule{.eps}{pdf}{.pdf}{`epstopdf #1}
\pdfcompresslevel=9
\else
\usepackage{graphicx}
\fi

3) Compile using pdflatex with the -shell-escape command line option

It seems to work.

Thursday, 17 May 2007

EPS to PDF : how to avoid clipping

Again, the fancy world of interconverting formats. I had to convert a bunch of Encapsulated Postscript (.EPS) files (generated by Inkscape) into PDF pages, for work. No problem, I initally thought, there is ps2pdf that will help me.

Problem is, ps2pdf has the nasty habit to use a fixed page size by default, clipping everything that goes beyond the limits of the page. No matter if most of the drawing is outside the page: ps2pdf will silently and mercilessly cut most of it.

Added to this, ps2pdf documentation is bad by almost any standard. The problem is that ps2pdf is a script that relies on GhostScript, so ps2pdf docs are (mostly) GhostScript docs.

After almost 90 minutes of googling, I found what I needed. To convert an arbitrary EPS file into a PDF page of your standard GS page size, just type:

ps2pdf -dEPSFitPage file.eps file.pdf