Generate PDF from LaTeX

This page introduces how to generate pdf files with bookmarks and hyperlinks from your LaTeX file. For a more complete discussion of pdfLaTeX, please refer to here.

There are two ways of doing this. One way is to use ps2pdf, which is explained here in this page, and the other way is to use pdflatex, which is explained here in this page. Using ps2pdf is very simple. However, if you want more fine control for the generated pdf file, you should use pdfLaTeX.

Why pdf is better than ps?

I like pdf format because:

Setting up hyper links

You need to use the hyperref package to use the hyper links in your document. Usehyperref is an example piece of LaTeX code of using hyperref, which is based on the example in this page. You should copy it into the preamble of your LaTeX file right before the \begin{document} part and change the information in the \hypersetup part.

Use latex+ps2pdf generating pdf files

Make sure the ps2pdf option is selected in your hyperref package. After using latex to get an dvi file, you should use this command to generate the ps file:
dvips -Ppdf -G0 myfile
Then use ps2pdf to convert the ps file to pdf:
ps2pdf myfile.ps
If the generated pdf file has very small top margin, it means dvips generated A4 size but you expected letter size. Thus you should use this dvips command:
dvips -t letterSize -Ppdf -G0 myfile

Use pdfLaTeX generating pdf files?

The disadvantage of using pdflatex is that some packages which uses postscripts (like pstricks) cannot be compiled directly by pdflatex.

When using pdflatex, you just run pdflatex instead of latex to compile your LaTeX file. However, pdflatex does not read eps format. Thus you should convert it to pdf format.

When you include your graphics file, do not give the extension:

\begin{figure}
   \includegraphics[width=.5\textwidth, height=!]{myimage}
   \caption{My Figure} \label{fig:my}
\end{figure}

When compiling by LaTeX, the eps file is searched by default. When compiling by pdfLaTeX, the pdf file is searched by default. Thus you don't need to change your TeX file when switching between LaTeX and pdfLaTeX.

The epstopdf command coming from your TeX distribution can convert eps to pdf. However, due to a bug in GhostScript, the image is rotated by 90 degrees sometimes. Thus you should use this command to do the conversion. Of course you want to replace my.eps and my.pdf with the file name of your images.

   egrep -v "^%%Orientation:" my.eps | epstopdf --filter --outfile=my.pdf

Here is a Makefile to convert eps to pdf and use pdflatex and latex automatically.

Back to LaTeX introduction
Back to my home page


Please report any problems with this document to me

GoHappyCup.com web site is sponsored by Santa Clara Youth Go Club.
Go Happy Cup is sponsored by American Go Association Sunnyvale Chapter, American Go Foundation, Bay Area Go Players Association, and Santa Clara Youth Go Club.