L^{A}TEX courses Course 1 : Introduction

Isabelle HURBAIN isabelle.hurbain@free.fr

August 4, 2009

Contents

1 But what is L^{A}TEX anyway ?

L^{A}TEX is a document preparation system. It allows you to create professionallooking documents without pain. The main idea of L^{A}TEX is that the author of the document concentrates on the content and not the form of the document. To achieve this, L^{A}TEX provides a set of macros and predefined styles.

Let’s take a basic example. On a “standard” word-processing tool, to make a section title, most people use form-modifying commands. For example, they put it in Bold, Underlined, Size 16. With L^{A}TEX, the form of your document is independant of its content : your section title will be in a \section command and you let L^{A}TEX manage how it will be printed and diplayed.

You may ask : “What’s the big point ?” Well, there are indeed at least three big points. The first is obviously that you don’t have to remember what “style” you used for your previous sections, subsections, chapters and so on. The second is that when you decide that your section title font is too big, you don’t have to change it in the whole document, you can do it with a single modification. The third is that, as the document is marked with sections, subsections and so on, it is much easier to do tables of contents - in fact, it can be done automagically.

The last point I’d like to underline is that L^{A}TEX is really fantastic to typeset mathematical formulaes. You can do things like

∑_{i=0}^{n} i = \frac{n(n + 1)}{2}

in a very short time. Even if this formula is really simple, you will soon see that once used, you cannot do without L^{A}TEX for scientific publishing ;-)

I hope that this very short introduction has given you the envy to continue, so let’s go !

2 What do I need to make L^{A}TEX ?

L^{A}TEX is not, like most word-processors, WYSIWYG (What You See Is What You Get) (or, more frequently, WYSIMOLWYG, What You See Is More Or Less What You Get). You first write your L^{A}TEX source code, then you compile it into a .dvi file, which you can transform in .ps or .pdf. There are also means to convert L^{A}TEX into HTML for example.

So what you need are basically :

• a text editor - Emacs, Vi, TextPad, UltraEdit or whatever you like

• a L^{A}TEX distribution. You can find teTEX under Linux Debian, and there is a TEX/L^{A}TEX distribution bundled with almost all Linux distribution. Under Windows, if you use Cygwin there is also a teTEX; you can also find MiKTEX and TEXLive (I’m sorry for Mac users, I don’t use Mac so you’ll have to find a Mac distro yourself :P )

• a .ps or a .pdf viewer (or both). There are numerous - the most famous are gv / Ghostview for .ps and Adobe Acrobat Reader for

     .pdf.

All these things can be installed very easily - just do it the way you install any other program.

Once all is installed, let’s write our first L^{A}TEX document.

3 L^{A}TEX Hello World

3.1 The document

We will look at a very simple document :

\documentclass[a4paper, 11pt]{article}
\title{My first \LaTeX{} Document}
\author{Isabelle HURBAIN}
\begin{document}
\maketitle
Hello, world !
\end{document}

You can copy and past it into, for example, a new text file named ”helloworld.tex”.

3.2 Compilation

Save it, and compile it. To compile the file, just cd to the directory you saved it into and type

latex helloworld.tex

in a console (or a command in Windows).

You should see some lines displaying, and three new files are created.

• The .dvi file is the output of the compilation - what you can view and print

• The .aux file is an auxilliary file, which contains things like section numbers and figures numbers, so that it is possible to create a table of contents or a table of figures

• The .log file is the file that logs all L^{A}TEX information - L^{A}TEX compilation messages and errors.

3.3 Visualization

Your L^{A}TEX distribution probably provides a way to visualize .dvi files - in teTEX there is xdvi, in MiKTEX there is YAP...

If you find a .dvi viewer, you can directly view the helloworld.dvi file. If not, you can use

dvips helloworld.dvi

to get a ps file, or

dvipdfm helloworld.dvi

to get a pdf file. (dvipdfm can be slightly different, you may also find dvipdf or others).

Nice isn’t it ?

3.4 Explanations

Let’s look a bit more at the code. As you can see, all the commands begin with a \ ; \ is a special character in L^{A}TEX that can be typed with $\backslash$. The other special characters ({, }, $, %, # and ) can be obtained with \{, \}, \$, \%, \# and \_. A \\ breaks the line (but you should not use this much as we’ll see later).

The first line,

\documentclass[a4paper, 11pt]{article}

is very important. It tells L^{A}TEX several things. \documentclass{article} tells it to follow an article layout. There are other layouts, such as report, book, letter... which we will discover in this course. The a4paper and 11pt in the square brackets are general parameters of the document. I will talk about it a bit further in these courses. They tell L^{A}TEX that the result will be printed onto A4 paper, with a text character size of 11 points. Of course, if you use letter paper, feel free to replace a4paper with letterpaper.

\title{My first \LaTeX{} Document}

defines the title of the document, with a lovely L^{A}TEX symbol.

\author{Isabelle HURBAIN}

defines the author of the document.

\begin{document}

is the signal for L^{A}TEX that the real document begins. The lines before this line are called the preamble of the document.

\maketitle

is a command to create a title from the information in the preamble (typically \title and \author, eventually \date).

After that, you can compose the document (here just “Hello, world !”), and finish it by

\end{document}

It is true that it seems a bit complicated for just that. However, look how simple it was to create the title...

4 In the next course

In the next course, we will learn how to create a real-world document, with titles and sections, and I will explain more deeply the form-content dissociation advantages.