# Chapter 11. LaTeX

11.1. Introduction
11.2. Preparing basic LaTeX documents

# 11.1. Introduction

LaTeX is a typesetting system that can be used to produce high-quality articles, books, letters and other publications. LaTeX is based on TeX, a lower-level typesetting language that was designed by Donald E. Knuth. LaTeX does not work like a WYSIWYG (what you see is what you get) word processor, the kind of document preparation system most people are accustomed to. With LaTeX you do not have to care about formatting the document, only about writing the document.

LaTeX files are plain-text files that contain LaTeX macros. LaTeX formats the document based on the macros that are used. In the beginning using LaTeX may be a bit awkward to a new user. But after a while you will discover that using LaTeX has some distinct advantages. To name a few:

• LaTeX-formatted documents look very professional.

• You do not have to care about the layout of your documents. You just add structure to your documents, and LaTeX takes care of the formatting.

• LaTeX files are plain text, and can easily be changed using standard UNIX tools, such as vi, sed or awk

• LaTeX provides very good support for typesetting things like mathematical formula, references and Postscript images.

LaTeX is very extensive, so this chapter will only touch the surface of LaTeX. But it should be enough to get you started to be able to make simple documents.

# 11.2. Preparing basic LaTeX documents

## 11.2.1. Minimal document structure

Each LaTeX document has some basic minimal structure that describes the document. Let's look at an example:

\documentclass[10pt,a4paper]{article}

\title{The history of symmetric ciphers}
\author{John Doe}

\begin{document}

This is a basic document.

\end{document}



You can already see the basic syntactical structure of LaTeX commands. A command is started with a backslash, followed by the name of the command. Each macro has a mandatory argument that is placed in accolades, and an optional argument that is placed in square brackets.

The first command in every document is the documentclass. This command specifies what kind of document LaTeX is dealing with. The type of document is specified as a mandatory parameter. You can also specify some optional parameters, such as the font size and the paper size. In this case the font size is changed from the default 12pt to 10pt, and A4 is used as the paper size. The document classes that are available in LaTeX are shown in Table 11-1.
After the documentclass you can add some meta-information to the document, like the title of the document. In this case the title is The history of symmetric ciphers.
The author command specifies the author of the book.
The \begin command marks the beginning of an environment. There are many different environments, but they all implicate certain typesetting conventions for the text that is in an environment. In this case we start an document environment. This is a very basic environment, LaTeX interprets everything in this environment as the body of the text.
The content of the document can be placed within the document, in this case a friendly warning about the nature of the document.
All environments eventually have to be closed. The document environment is the last environment that is closed, because it denotes the end of the body of the text.

Table 11-1. LaTeX document classes

Class
article
book
letter
report

## 11.2.2. Generating printable formats

Once you have a LaTeX file, you can use the latex command to generate a DVI (Device Independent format) file:

$latex crypto.tex This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4) entering extended mode (./crypto.tex LaTeX2e <2003/12/01> Babel <v3.8d> and hyphenation patterns for american, french, german, ngerman, b ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch, esperanto, e stonian, finnish, greek, icelandic, irish, italian, latin, magyar, norsk, polis h, portuges, romanian, russian, serbian, slovak, slovene, spanish, swedish, tur kish, ukrainian, nohyphenation, loaded. (/usr/share/texmf/tex/latex/base/article.cls Document Class: article 2004/02/16 v1.4f Standard LaTeX document class (/usr/share/texmf/tex/latex/base/size10.clo)) (./crypto.aux) [1] (./crypto.aux) ) Output written on crypto.dvi (1 page, 248 bytes). Transcript written on crypto.log.  As the LaTeX command reports a DVI file is created after running the latex command. You can view this file with an X viewer for DVI files, xdvi: $ xdvi crypto.dvi



This file is not directly printable (although DVI files can be printed with xdvi). An ideal format for printable files is Postscript. You can generate a Postscript file from the DVI file with one simple command:

$dvips -o crypto.ps crypto.dvi  The -o specifies the output (file) for the Postscript document. If this parameter is not specified, the output will be piped through lpr, which will schedule the document to be printed. PDF (Portable Document Format) is another popular format for electronic documents. PDF can easily be generated from Postscript: $ ps2pdf crypto.ps



The resulting output file will be the same as the input file, with the .ps extension replaced with .pdf.

## 11.2.3. Sections

Now that you know how to create a basic LaTeX document, it is a good time to add some more structure. Structure is added using sections, subsections, and subsubsections. These structural elements are made with respectively the \section, \subsection and \subsubsection commands. The mandatory parameter for a section is the title for the section. Normal sections, subsections and subsubsections are automatically numbered, and added to the table of contents. By adding a star after a section command, for example \section*{title} section numbering is suppressed, and the section is not added to the table of contents. The following example demonstrates how you can use sections:

\documentclass[10pt,a4paper]{article}

\title{The history of symmetric ciphers}
\author{John Doe}

\begin{document}

\section{Pre-war ciphers}

To be done.

\section{Modern ciphers}

\subsection*{Rijndael}

Rijndael is a modern block cipher that was designed by Joan Daemen and
Vincent Rijmen.

In the year 2000 the US National Institute of Standards and Technologies
selected Rijndael as the winner in the contest for becoming the Advanced
Encryption Standard, the successor of DES.

\end{document}



The example above is pretty straightforward, but this is a good time to look at how LaTeX treats end of line characters and empty lines. Empty lines are ignored by LaTeX, making the text a continuous flow. An empty line starts a new paragraph. All paragraphs but the first paragraph are stared with a extra space left of the first word.

## 11.2.4. Font styles

Usually you may want to work with different font styles too. LaTeX has some commands that can be used to change the appearance of the current font. The most commonly used font commands are \emph for emphasized text, and \textbf. Have a look at Table 11-2 for a more extensive list of font styles. Emphasis and bold text are demonstrated in this example paragraph:

Working with font styles is easy. \emp{This text is emphasized} and
\textbf{this text is bold}.



Table 11-2. LaTeX font styles

Command Description
\emph Add emphasis to a font.
\textbf Print the text in bold.
\textit Use an italic font.
\textsl Use a font that is slanted.
\textsc Use CAPS.
\texttt Use a typewriter font.
\textsf Use a sans-serif font.