PDF LaTeX by example

CTJ Dodson


Starting from little or no experience of LaTeX, the examples given below serve as templates from which portable articles, books, slideshows, letters can be created in PDF format. Many pure mathematicians, in my case 30 years ago, were attracted to use computers (initially with just command line input) for the first time in their work by LaTeX . It liberated them from the problem of preparing their papers in camera-ready format, initially in Postscript format then subsequently in pdf. In 1989 Steve Jobs created the NeXT computers, bundled with Mathematica, LaTeX and more, with a graphical interface that included video email (to other NeXT users). That quickly set the standard environment for many scientists and is now available on portable devices.

Free pdf viewers (see below) are usually already associated with a browser so it is convenient to use pdf output format and then you can include also hyperlinks, coloured text, graphics and even movies in your documents, electronic books, and CD/DVD media. Acrobat Reader can rotate graphics, it has an automatic slideshow mode and the LaTeX beamer package (cf. below) provides good looking conference slides for computer projection.

In the case of a collection of course documents or a connected series of articles---possibly including some on remote computers, it is convenient to use web-based access to the archived resources, as is in operation with the page you are now reading. Accordingly, the working example of this page is an easily understood template that you can modify to provide access to your own archived materials; it has been designed using elementary raw HTML so it is easily portable. On the other hand, whereas professional web editing facilities are very powerful, they use many hidden or at best obscure procedures and may bury in file libraries necessary items, so it is hard to create a stand-alone webpage. Creating simple raw HTML in a plain text editor like Notepad is sufficient for most purposes, like creating and updating a course homepage or carrying a connected set of documents for discussions and presentations at another institution.


The following software is commonly used [install in this order]:

Using the examples---Red text is hyperlinked

Article example

The procedure to create a pdf document using LaTeX is the same in all cases: make a plain text artex.tex source file using LaTeX commands, in any plain text editor [recommended is WinEdt]. Then run the command
pdflatex artex
If correctly installed, WinEdt will have a button to click for this operation.
The result is creation of a file artex.pdf and WinEdt has a button for viewing it.
To illustrate with the example here, download the necessary files:
Source file: artex.tex, graphic files for inclusion: 3dpdf.pdf contpdf.pdf

The result of pdflatex will create from artex.tex several files of which two are immediately important: artex.log, which contains information on any errors and artex.pdf which is the output. If artex.pdf is not how you want it, then resume editing artex.tex before again processing it with pdflatex. In WinEdt the errors will be highlighted for you.

[NB You could edit the LaTeX source file artex.tex eg in Notepad and then use a command line in the same directory as artex.tex to run pdflatex, but much better is to edit in WinEdt. If you do use a command line then the pdflatex command presupposes that your PC knows the path to the program pdflatex.exe. For example, in MiKTeX the full address of this file is probably
This you can check by looking down the directory tree; of course, you can always use the full path in your command. However, by far the easiest method to run pdflatex is to use MiKTeX via WinEdt as a front end editor and edit artex.tex or create your own *.tex file in WinEdt.]

Resolving errors in LaTeX code
If pdflatex finds errors in the commands used in artex.tex, then it will write information on these in artex.log but additionally it will give feedback in the DOS window and this can help corrections. You can ask for more help about an error message by entering h or you can ask pdflatex to do the best it can by entering s after an error message. This help is often cryptic but together with the output you can usually decide what has gone wrong. Typical beginners' errors are omission of the preamble commands \documentclass{article} one of the packages required eg \usepackage{amsmath,amssymb,amsfonts}, or one of the essential beginning \begin{document} and end commands \end{document}. Other common errors are omission of $ around mathematics or failure to end an environment after once beginning it: \begin{eqnarray} must eventually be followed by \end{eqnarray}. The example artex.tex contains a selection of commonly used environments.
If you want to be adventurous, you can include movies in pdf documents using the \includemovie command.

Beamer Slideshow example

PDF\LaTeX \ beamer package
Perhaps the best way to make professional looking pdflatex slides with internal and external hyperlinks for conference presentations is to use the free beamer package from sourceforge. This actually comes already bundled with the current full installation of MiKTeX providing working examples and templates. If it is not present in your MiKTeX installation then try using the MiKTeX Update Wizard to identify available upgrades and install them from their homepage.
Open and edit plain text LaTeX source file beamerex.tex
You can see a full conference presentation by looking at beamerex.pdf with source files beamerex.tex including a logo manchesterlogo.jpg
As before, you can include movies in the slideshow using the \includemovie command.

Book example Open and edit LaTeX source file bookex.tex

The book root file bookex.tex gives a basic example of how to use LaTeX for preparation of a book with hyperlinks, using documentclass{book} . You run the command
pdflatex bookex
To use the example here you can download the necessary files:
Source: bookex.tex, graphics for inclusion: 3dpdf.pdf contpdf.pdf chapter files: ch1.tex ch2.tex index file: index.tex.

In the source file bookex.tex there are some options, the line:


includes hyperlinks and chooses colours for them.

Also, the following lines just before \begin{document}
will put a watermark on every page:

\SetWatermarkText{Draft not for circulation}

Just omit them or comment them out with % if you do not want a watermark.

Each Chapter, Appendix and the Index is made as a *.tex file and is called in by the include command---thus ch1.tex is the name here of the file containing Chapter 1. The inclusion of any particular file can be suppressed by prefixing the line by a percent sign. Do not put an end{document} command at the end of chapter files; just one such command is needed at the end of the book. Note the tag used to make an index entry. You may need to consult Lamport's book for details of the procedure to make the index input file; LaTeX will create a pre-index by listing in the file bookex.idx all the tagged items in your input *.tex files, then you edit this into a theindex environment, as index.tex.

When you view bookex.pdf using Acrobat Reader, from the toolbar View choose Single Page and select Bookmarks; then just pressing Enter or via a remote control you display the book one page at a time. For use from a CDROM, the Bookmarks navigation bar at the left is convenient; note that the List of Contents is automatically hyperlinked.

Further examples:

letter, test
In Notepad open the plain text LaTeX source files
lettex.tex , testex.tex These can be edited as required and processed as before with pdflatex.

See the TeX User Group for more information on LaTeX and available augmentations.

Webpage example:
Open plain text raw HTML file pdfbyex.htm in Notepad

This webpage, which has a plain text file pdfbyex.htm as its source, is used as the front end or access route to the various local resources and links to remote other materials needed to experiment with the examples. The text file for this webpage can be opened and edited in any text editor---eg Notepad---but to do this you will need first to open Notepad and through its menu find this file pdfbyex.htm because if you just click on the file then it will be opened in your web browser, which recognises the extension htm for an HTML file. You could be clever and tell your browser tools Internet Options that you wish to use Notepad as HTML editor; then clicking Source in the View menu will open the source text of the webpage in Notepad ready to edit.

To use the example here you can download the necessary files:
Source: pdfbyex.htm, graphic for inclusion: viviani.gif

When you open the file in Notepad and compare the text with what the browser presents from it, you will see how simple it is to write raw HTML code. It is important to use the plain text editing, not rich text and not Word or Wordpad, because the latter think they know what you want and slip in their own controls!

The HTML control commands are all wrapped in braces < > and are often natural abbreviations of the operations: eg HR is `horizontal rule' which gives a dividing line, Hn for n=1,2,3,4 gives headings of descending importance. B means bold and /B means end bold, I and /I begin and end italic, UL begins a list environment, LI precedes each item and /UL ends the list, BR gives a line break and P gives a new paragraph, HREF precedes a hyperlinked reference and a graphic file of a travelling triad on Viviani's curve was included at the top of this page using IMG SRC="viviani.gif".

The only oddly obscure part of HTML is the code for colours, for example #FFFF00 means yellow; so you may have to look up special colours in an HTML manual or go to the sourcecode of a document containing the colour you want and experiment---another way is to view a little text in your web browser Composer, use its editor to colour the text, then open the source file in Notepad and note the code used. It will be of the form: font color="#FF6666" for wrapping round red text and of the form: font color="black" for green text. From the top of this file you can deduce html code for the symbol ; similar detective work on other html source files, which you can read through your browser toolbar `View' `Source' , can yield useful tricks.