Thursday, May 10, 2007

Latex Tips

I was playing around with the URL formating with Latex today and found the following.

\url{http://example.com} in the url package displays URLs inserting line breaks properly. But, the same \url{} doesn't insert line breaks if you use the hyperref package with the dvips option (hyperref is a useful package to create hyperlinks in PDF), but works fine with the pdftex option.

So, I started to use pdflatex to create PDF instead of the old-style latex-dvips-ps2pdf combination. pdflatex doesn't support EPS files, so I converted all EPS files to PDF using epstopdf.

But, I still want to use latex and xdvi for quick modification. It's because xdvi refreshes the updated dvi file automatically. I can just keep xdvi open showing some specific page. Every time I compile the TeX file, I can see the modified result right away. I don't need to reopen the file and move to the specific page. So, I did the following to make the LaTeX file compilable both with latex and pdflatex.

First, I load the hyperref package with the proper option detecting how the file is compiled.


\ifx\pdftexversion\undefined
\usepackage[dvips]{hyperref}
\else
\usepackage[pdftex]{hyperref}
\fi

Then, I removed file extensions, like \includegraphics{foo}, so that includegraphics finds foo.eps or {foo.pdf or foo.png} depending on how I compile it.

No comments:

Post a Comment