What’s LaTEX all about?

Rein Smedinga

1 Introduction

LaTEX is a text formatting program, i.e., after you have written a text into a file by means of an editor, the LaTEX-program converts this text into printable matter. With LaTEX you cannot do what-you-see-is-what-you-get work: you need two steps: one editing step in which you type in the text together with typesetting commands into a file; and one formatting step, in which the program converts the text, according to the given commands, in printable code. The following steps have to be done:

1. Creation of a text file with text and LaTEX commands. Creation is done using a text editor (any editor will do). For example, you can use the editor emacs:

emacs example.tex

The unix command above starts the editor and creates the file example.tex. You should always give the file a name with extension .tex (otherwize LaTEX will not recognize the file as a text file).

2. Converting this file to printable code. Here the LaTEX-program does the job:

latex example

It is not necessary to give the filename extension here. LaTEX now creates some additional files. One of these is the file example.dvi,that can be printed and previewed. Also example.aux is created (needed for cross referencing) and example.log in which LaTEX writes down a log of everything it has done.

Because each language has its own hyphenation-rules, you can use other rules than English hyphenation by giving special commands in the file. We will return to this subject later on.

3. Previewing the document. By typing:

xdvi example

the file example.dvi will be previewed on your screen.

4. Printing the document. By typing:

lp -dx example

your document will be printed.

2 A document in LaTEX

As we stated before, the original text file example.tex should not only contain text, but also LaTEX-commands. First of all, you need to explain what kind of document you want to make, and you should indicate the beginning and the end of the included text. This is done by typing on the first lines of your text-file the following:

\documentstyle{article}
\begin{document}

The first line explains to LaTEX that you want to make an article. Changing article into report creates a report. Also book and letter are possible. The last one creates a letter that can be mailed. The second line tells LaTEX that after this line your real document starts. At the end of that document, you should add the following line:

\end{document}

which tells LaTEX that your document ends here. Everything after this line will be ignored by LaTEX. A very simple article could be:

\documentstyle{article}
\begin{document}
This is a very simple article. It just contains one paragraph and, in fact,
has nothing to tell, really.
\end{document}

Between \documentstyle and {article} you can put all kind of options to change the documentstyle a little bit or to add additional tools. For example, by:

\documentstyle[dutch]{article}

you create a document in which Dutch hyphenation is used instead of English. Also, languagedependent words, like chapter, contents, etc. will automatically be renamed to the Dutch words hoofdstuk, inhoud, etc. Unfortunately, our system only supports English and Dutch. The mathematical computer network ciwi also supports French and German. Another possibility to use here is the option to enlarge the used font a little bit. Instead of standard 10 pt. fonts you can use 11 pt. fonts by starting with:

\documentstyle[11pt]{report}

In the same way, you can use 12 pt. fonts. If you include more options, each option should be separated by a comma:

\documentstyle[12pt,dutch]{book}

Commands in LaTEX

In order to create a textfile, it will now be clear that the actual text has to be put between \begin{document} and \end{document}. However, in typing your text, you should be aware, that some characters have special meaning. We mention

{ } \ # $ % &

The backslash \ is used to denote a command rather than normal text. So text is some text while \text denotes a command. If you want to use any of the above symbols, you should use

\{ \} \backslash \$ \% \&

instead. Commonly used commands are those to denote the beginning of a new chapter, new section, etc. We mention a few:

• Start of a new chapter (only available in report and book style, not in article style):

\chapter{name}

name becomes the title of the new chapter. Chapter numbering and adding the word chapter itself (or hoofdstuk, if the dutch option is used) is done automatically.

• Start of a new section:

\section{name}

name is the title of the new section. Also here, numbering is done automatically.

• Subsections:

\subsection{name}

Etc.

• Start of a new paragraph: Just including an empty line forces a new paragraph to be started. Most document styles have the first line of a new paragraph indented.

• Start of a new line:

end of a line.\\
start of a next line...

A newline command \\ only works if a line can really be closed. So \\ \\ is not allowed. The second \\ does not close a real line.

• Enumeration:

Some text.
\begin{itemize}
\item first item
\item second one
\item and so forth
\end{itemize}
Some other text.

Some text.

• first item

• second one

• and so forth

Some other text.

With \item a new item will be started. Automatically, a marker will be put before that item and the whole item will be indented. If you want to number the items, you should use:

Some text.
\begin{enumerate}
\item first item
\item second one
\item and so forth
\end{enumerate}
Some other text.

Some text.

1. first item

2. second one

3. and so forth

Some other text.

Numbering is done automatically. Itemize and enumerate lists can be nested and mixed.

• Title of an article.

Title, author(s), and date can be defined using:

\title{This is the title}
\author{A. Writer and B. Reader}
\date{tomorrow or so}

and will be printed if you say:

\maketitle

In the article style the title and author-list will appear above the text, in report and book style it will be put on a separate page.

• Table of contents. To get a contents type the following command right there, where you want to have the contents:

\tableofcontents

This command creates an additional file, with extension .toc, that is read the second time, you process your document through LaTEX, to create the table of contents. So, you need to give the unix command

latex example

twice, to really get the (up to date) contents.

Of course, many more commands are possible. See the literature.

3 Accents

Some commonly used accents are:

be\"eindigen

to get beëindigen.

be\"\i nvloed

to get: beïnvloed (the \i creates a dotless i).

\'e\'en

to get: één.

4 Other fonts

The used font can be changed to for example boldface or italics by typing:

{\bf this will be printed boldface} and this in normal font
{\em and this emphasized} and normal again and {\sl slanted} and {\it
italics} and so on.

The used font can be resized to smaller or larger sizes by typing:

{\tiny very small text}
{\footnotetext Quite small text}
{\small Small text}
{\normalsize is normally not used}
{\large Larger text}
{\LARGE Even larger text}
{\Huge Very huge text}

In fact, we have available:

\tiny \scriptsize \footnotesize \small \normalsize
\large \Large \LARGE \huge \Huge

5 Tables

LaTEX provides easy to use commands to create tables. For example:

\begin{tabular}{lr|c|}
just an item & item12 & item13 \\
\hline
             &        & something \\
some more    &        &           \\
item41       &  and   & a long item \\
\hline\hline
\end{tabular}

just an item item12  item13

something

some more

item41  and a long item

The argument after \begin{tabular} defines the structure of the table. Each letter represents a column. A l means a left alined column, a c means a centered column, and a r means a right alined column. Also possible is to put a | there, to define a vertical line between columns. The contents of each part of the table is separated by & and each line is ended by \\. Much more complex tables are possible. The reader is adviced to look in the LaTEX-manual, [Lam86], for more examples.

6 Floating text

Floating text is text that can be put somewhere in the text, but has no specific place within the text. For example figures and tables can be floats. They should be put near the place the figure or table is discussed. Such floats can be created in LaTEX by typing:

\begin{figure}
Figure text...
\caption{Figure title}
\end{figure}

The caption will create the title of the floating part. Also possible is:

\begin{table}
Figure text...
\caption{Figure title}
\end{table}

The difference between figure and table is the name in the caption: Figure and Table, respectivily. Also here, numbering is done automatically.

7 Formulaes

A mathematical formula is put between $. For example:

We have $x := x + 5$
and $y_1 + y_2 = \phi$ holds.

We have x := x + 5 and y_{1} + y^{2} = ϕ holds.

Subscripts are defined using _and superscripts using ^. If more characters are to be sub/superscripted, these should be put between accolades, e.g. compare:

$x_12$ and  $x_{12}$  x_{1}2 and x_{12}

For displayed formulaes, we use:

Some text
\[
\sum_{i=1}^{n} x_i = q
\]
and more text

Some text

∑_{i=1}^{n} x_{i} = q

and more text

Displayed formulaes are put on a separate line and centered. \sum is the summation symbol. In [Lam86] long lists of symbols can be found.

8 And many more…

The reader is adviced to read the LaTEX-manual [Lam86] to explore LaTEX. Sample text files exists, to get a first impression on LaTEX, for example try:

cp /usr/local/newtex/lib/tex/inputs/latex/sample.tex .
latex sample
xdvi sample

and compare the contents of the file sample.tex with the previewed result.

Errors in your LaTEX document

If some error occurs in your document, you get an error message on the screen. Something like:

! Undefined control sequence.
l.22 ...eation of a text file with text and \LateX
                                                  \ commands. Creation is
?

The first line tells in which line of your text file the error occurs. The last part of that same line gives the part that causes the error. The question mark is a prompt. You can type h here to get additional information about the error. Other possibilities are x to quit the whole LaTEX-session, or giving a return only, to let LaTEX try to fix the error by himself (possibly more errors occur because of this error, so most likely, a couple of returns are necessary to recover from this error; also, the error is not corrected in your original text file!). The last option (giving a return) makes it possible to check the remainder of the document. After a LaTEX-run you should correct the error(s) yourself in your text file using an editor and, next, try to run LaTEX again.

References

[Knu84] Donald E. Knuth. The TEXbook. Addison Wesley, 1984.

[Knu89] D.E. Knuth. The errors of TEX. Software - practice and experience, 19(7):607–685, 1989.

[Lam86] Leslie Lamport. LaTEX, A document preparation system. Addison Wesley, 1986. In 1994 an updated version for LaTEX2_{ϵ} appeared.