Chapter 8. LaTeX

Table of Contents
Running LaTeX from the shell
Running LaTeX from within emacs
Local style
How to learn more about LaTeX

LaTeX is a document preparation system that lets the author focus on the content and structure of the document rather than on the layout. The document is then typeset nicely according to a predefined layout. The document is written with a text editor like emacs and the final output is then very much different from what one sees on the screen.

A short LaTeX code that illustrates what was said above is the following minimal but complete listing of a LaTeX file:

\documentclass{article}

\author{Peter Olsson}
\title{A test document}

\begin{document}
\maketitle

\section{Short introduction}

\LaTeX\ is a document preparation system that lets the author focus
on the content and structure of the document rather than on the
layout. The document is then typeset nicely according to a predefined
layout.
\end{document} 


Running LaTeX from the shell

Create a new directory (mkdir) and cd to that directory. Open a new file short.tex in emacs and copy the above text into that buffer. Save the buffer with C-x C-s. As we will se below it is possible and very convenient to run both LaTeX and the viewer program from emacs, but to understand what is going on it is good to first do it from an xterm. Therefore, go back to the xterm and start emacs like this:

$ latex short

This is e-TeX, Version 3.14159-2.1 (Web2C 7.4.5)
entering extended mode
(./short.tex
LaTeX2e <2001/06/01>
Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, b
ahasa, basque, catalan, croatian, czech, danish, dutch, finnish, greek, iceland
ic, irish, italian, latin, magyar, norsk, norsk, portuges, romanian, russian, s
lovak, slovene, spanish, swedish, turkish, ukrainian, nohyphenation, loaded.
(/usr/share/texmf/tex/latex/base/article.cls
Document Class: article 2001/04/21 v1.4e Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo))
No file short.aux.
[1] (./short.aux) )
Output written on short.dvi (1 page, 824 bytes).
Transcript written on short.log.

So far there is no visible result but LaTeX has created a number of files and of these it is the .dvi-file that contains the formatted document in a device-independent form. To take a look at the output do

$ xdvi short.dvi &

which will open a new window with the formatted output.


Running LaTeX from within emacs

To run LaTeX from emacs one can either choose LaTeX from the Command menu or press C-c C-c followed by return two times. To view what has been produced either press C-c C-c again. The text "Command: (default View)" then appears at the bottom line. After again pressing return twice a new window will be opened where the produced document appears.


Local style

The predefined layout doesn't mean that there is no room for changing things, on the contrary there is a great freedom of modifying the standard layout and settings. One such example is the title page that is available in a local style. By including "\usepackage{cse}" in the preamble one gets a local version of the \maketitle command for Computational Science and Engineering at Umeå University. Beside the definitions of \author and \title this version also needs \course and allows for (but doesn't require) \email and \bottomtext. Two versions of skeleton LaTeX files may be found both in /Home/guests/olsson/linux-guide/latex and at http://www.tp.umu.se/ModSim/latex: skeleton.tex and the swedish version skelett.tex. Copy both these files to your home directory. Open the files in emacs, run LaTeX and examine the output with the viewer.

An more complete example that illustrates equations, the inclusion of postscript figures, and tables may be found in /Home/guests/olsson/linux-guide/latex/example.tex. Note that you also need the figure in the postscript file /Home/guests/olsson/linux-guide/latex/example-fig.ps.


How to learn more about LaTeX

Each LaTeX document is split into two parts, the preamble which only contains definitions and doesn't produce any output and the document itself which is the part between \begin{document} and \end{document}. LaTeX is a complicated system and is not easy to master. To produce standard documents with ordinary mathematics and included figures is however not at all difficult. The simplest way to proceed is to start from an example file as discussed above and learn new things by looking at others documents. To learn things in a more systematic way The Not So Short Introduction to LaTeX is a good place to start. To read the pdf file choose the program /usr/local/bin/acroread.