Wednesday, April 7, 2010

Auto EPS Conversion in pdflatex

I recently decided to start using PDF figures in my thesis instead of EPS and compiling my TeX code directly to PDF. This requires that you have the perl script 'epstopdf' installed on your system, as well as ghostscript and the associated machinery. The TeX package "epstopdf", combined with usepackage[pdftex]{graphicx} will auto convert any EPS figures used in your document to PDF. The actual conversion works wonderfully. There is a snag however, as described by the author of the package: even with TEXINPUTS set correctly, the 'epstopdf' script cannot find figures located in nested subdirectories.

A solution upon which I settled was to modify the script and put it in my local path before the real epstopdf (which is usually in /usr/bin). The trick is to use kpsewhich to scan all the associated TeX directories, including those recursively specified in TEXINPUTS. The fix is as follows:

Make a copy of 'epstopdf', and find the following lines in your new copy:

@ARGV > 0 or die errorUsage "Input filename missing";
@ARGV < 2 or die errorUsage "Unknown option or too many input files";
$InputFilename = $ARGV[0];

and change the last line to

chomp($InputFilename = `kpsewhich $ARGV[0]`);

This will prepend the correct path to InputFilename as found by kpsewhich.

So far this works like a charm on all my linux distros (RHEL and Ubuntu). YMMV!

No comments: