Beginner's LATEX

This text serves as a guide for new staff members at the Alfa-Informatica department who have to start using LaTeX, and are completely unfamiliar with LaTeX.

Absolute Beginner

LaTeX is a document formatting system. It differs significantly from word processors such as MS-Word and WordPerfect. Unlike word processors, LaTeX documents are created as plain ASCII files, mixing content and formatting commands in a human readable form. Emphasis is on the logical structuring, less on actual typesetting. LaTeX documents are compiled by the external program latex that is independent of the program used to do the actual writing of the document.

Getting started

Let's start, not with writing a LaTeX document, but with compiling an existing one. Save these files in your local directory (you should be working on an X terminal or X workstation):

Now, compiling is very simple. Just give the command:
latex sample2e
You'll end up with a file named sample2e.dvi. You can view the formatted document with the command:
xdvi sample2e.dvi &
To print this document you'll need two more steps. First convert it to PostScript, and then send it to the print spooler. Use the following commands:
dvips sample2e.dvi
Or you could combine the previous two as:
dvips -o '|lp' sample2e.dvi
You can view the result with gv or ghostview, or you could distribute the file to anyone who might be interested in reading it. It usually isn't a good idea to distribute DVI files, because they are not self-contained. The conversion to PostScript makes it an independent file, containing all the resources needed to view or print the formatted document.

Learning LaTeX

LaTeX can be intimidating in its richness. Start by writing simple documents, gradually getting familiar with more complex structuring commands, at the time you actually need them. A good start is to view the file sample2e.tex and compare it to the compiled and printed result. Make a print of the file small2e.tex too, using the same steps as described above for sample2e.tex. Both documents have comments in the source that explain about simple commands.

A second step is to buy a well written tutorial. A good book is:

This is both a practical tutorial and a valuable reference manual for the LaTeX2e language.

Some further hints

Paper size

The standard LaTeX classes define the paper size to be the American Letter. To change this to the common European A4 paper size, put something like the following at the top of your LaTeX document:

If you omit the a4paper option, the page lay-out will be wrong for the printers used at Alfa-Informatica, and, maybe, some printer might not be able to print the document at all.

Using bibliographic references

In writing scientific documents, you most likely will need to include references to other papers. BibTeX is a program that extends LaTeX for this purpose. You need to put bibliographic data in a separate database file in BibTeX format.

As an example, save these two files in your local directory:

Then, compile the document using these commands:
latex bibdemo
bibtex bibdemo
latex bibdemo
latex bibdemo
Running LaTeX several times is necessary to get the cross-references right. Have a look at bibdemo.dvi to view the result, and compare this with the LaTeX and BibTeX sources.

To create a BibTeX database you should use the Emacs editor. When you start editing a file with the extension .bib, Emacs automaticly enters bibtex-mode. You'll see an additional item at the Emacs menu: Entry-Types. If you want to include, say, an entry for a book, click this menu item and select the appropriate entry type Book. Then, this template is what will appear in your document:

  author = 	 {},
  title = 	 {},
  publisher = 	 {},
  year = 	 {},
  OPTkey = 	 {},
  OPTeditor = 	 {},
  OPTvolume = 	 {},
  OPTnumber = 	 {},
  OPTseries = 	 {},
  OPTaddress = 	 {},
  OPTedition = 	 {},
  OPTmonth = 	 {},
  OPTnote = 	 {},
  OPTannote = 	 {}
Now you should enter a label on the first line starting with @, right after the curly brace. This label is what you will use in your LaTeX document to refer to this entry. Second, you should fill in any information about this book you have into the appropriate fields. Fields starting with OPT can be left blank. When you're done, place the cursor at the beginning of the second line, and type Ctrl-C twice. Emacs will remove any unused fields, and remove the letters OPT from remaining field names.

Don't try maintaining a BibTeX database without the use of these templates. Every entry type has its own particular fields, and mistakes are easily made. Data in misspelled fields will be omitted in your formatted LaTeX document.

When you compare bibdemo.dvi with biblio.bib you'll notice there are capital letters in the database that are converted to lowercase in the formatted document. This happens in titles of certain entry types. If you want to prevent BibTeX to down-case some letters such as the first letter of a name in mid-sentence, you should put additional curly braces around the letter.

Notice the way names of authors are entered in a BibTeX entry. Last name first, then first names, separated by a comma. Multiple authors are separated by the word and. The same goes for the editor field.

One last advice: Divide your BibTeX database in two parts. First articles and the like, and then books, collections etc. This way, when you reference articles that themselves reference books in the database, BibTeX is able to find these forward references.

More on the use of BibTeX in the LaTeX book mentioned above.

Using pictures

In LaTeX you can draw graphics using the LaTeX picture commands. However, you shouldn't waste any time trying to learn these commands. There's a far better way to include graphics in your document: Using PostScript.

Many programs that produce graphics have the option to save these graphics as an Encapsulated PostScript file. Some even have the option to save it as a LaTeX picture, but usually, the results are worse.

It is very easy to include a PostScript image into your LaTeX document. You need to do just two things. At the beginning of the document, include the package psfig:

Second, at the position you actually want a PostScript image to appear, say, enter the following line:
Or, if the image is too large, you can scale it down to fit the width of the surrounding text:
Of course, you can write your own graphics directly in PostScript. It isn't more difficult to learn than writing LaTeX pictures, but it's much more flexible. All you have to keep in mind is, for LaTeX to be able to include the PostScript figure, the PostScript file should have a line of text such as:
%%BoundingBox: 0 0 595 842
With the four values replaced by the actual values of the BoundingBox of the picture. The package psfig will then take care of scaling and repositioning of the image to its proper place on the LaTeX output page.

To learn about PostScript, consult the book:

The book is incomplete and slightly outdated, but it gets you started in no time.

Another book supposedly very good, though I haven't seen it myself, is:

Distributing PostScript documents

You may want to make your articles available to the public, for example, by including a link in your Web homepage. You should compile the document first into a DVI-file, and then convert it to PostScript. Only then, all resources are combined into a single document. A DVI-file is not self-contained.