Friday, 17 February 2012

Good reasons to use PDF(La)TeX

If you're a long-time LaTeX user who still compiles to PDF by converting DVI to PostScript to PDF, you've probably asked yourself why you bother. After all, who even uses PostScript these days? I suspect the answer is no-one. Or at least, no-one who can't also use PDF. Here are a few more reasons to start compiling straight to PDF with PDF(La)TeX. If you always object to PDF because you mainly produce EPS plots, there are clean ways to convert EPS figures near the end of the post.

It's simpler. That is, instead stringing together enough commands to reach the moon, as in,

latex thesis ; dvips thesis.dvi -o ; ps2pdf thesis.ps

you cut it down to

pdflatex thesis

Done.

PDF files are smaller than PS. As above, only a small point but worth mentioning. Most of this is because PDF files are binary whereas PS files can be read as text. PDF also has built-in compression.

PDF looks better. Specifically, it has better font-handling in general, related, I believe, to the way that the fonts are stored in the PDF file. Also, it allows you to use the microtype package, which gives you the awesomeness on the right rather than the ugly sister of the typographic world on the left.
The effect of microtype. The left sample is rendered without microtype; the right sample with. (texblog.net)
The microtype package makes maximum use of advanced typographic things like kerning. So tack \usepackage{microtype} in your next preamble. Even if you write garbage, it'll be beautiful garbage.
I have never been as self-conscious about my handwriting as when I was inking in the caption for this comic. (xkcd.com)
You get hyperlinking and clickable contents in the document. Okay, this is also achieved by compiling through other formats but it's done better when compiling straight to PDF. All you need is to \include{hyperref} in your preamble. There are plenty of options to set so explore the documentation.

Your figures are automatically compressed. Now, I need to be careful with this one because it can be a downer if EPS figures are compressed with the low default quality factor. A lot of people still make use of EPS figures (especially in astronomy) so this might be why you haven't shifted to PDF(La)TeX before.

The easiest way around this is to export your plots straight to PDF. I make my publication plots with Veusz, which has a PDF option. Actually, Veusz is generally awesome and I highly recommend it for high-quality final plotting. I believe that MATLAB also exports to PDF but I'm not sure about gnuplot. Just another reason I only use it for day-to-day purposes.

If you must make EPS plots, you can dictate how the compression is done. Open the EPS file in a text editor and add one of the following snippets at the end of the preamble. i.e. the bit commented out with leading % symbols.

For lossless FlatEncode, add

systemdict /setdistillerparams known {
<< /AutoFilterColorImages false /ColorImageFilter /FlateEncode >> setdistillerparams
} if

Alternatively, you can use lossy DCTEncode but force the quality factor to be very high, in which case you should add
systemdict /setdistillerparams known {
<< /ColorACSImageDict << /QFactor 0.15 /Blend 1 /ColorTransform 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >>
    >> setdistillerparams
} if

When you convert the EPS using, say, ps2pdf, there should be no (or little) loss of quality. Thanks to one Gary Steele for these tips. I haven't tested the two algorithms carefully but experiment to see what works for you. Using FlatEncode appeared to be lossless but still occasionally reaped some huge compression ratios.

So that's why you should switch to PDF(La)TeX. When my thesis is done, you can bet there won't be a PS version!

1 comment:

  1. I usually use plain latex, but used pdflatex for my thesis. I don't think plain latex is quite as bad as you make out: first, dvipdf will go straight from dvi to pdf format, without going through the bloated pdf stage; and second, IDL will happily generate eps output but getting pdf looks a bit tricky (I never tried myself, but David Fanning has a couple of ways of doing so).

    In pdflatex's defence, it can handle eps files itself: put \usepackage{epstopdf} in your preamble, and run pdflatex with the --shell-escape command line option to allow it to call the eps converter. However, I found that this took a long time to compile if there were a lot of figures: it insisted on converting everything, every time I compiled.

    By the way, how do I get monospace fonts in the comments here?

    ReplyDelete