# How do I create my first document in LaTeX?

Very basic crash intro.

## 1. General Idea: The Nature of the Beast

LaTeX is a macro package that sits on top of the typesetting system called TeX (designed by computer scientist Donald Knuth). This probably means nothing to you, but you should at least learn to pronounce the names properly. "TeX" rhymes with "tech" (as in technology'), not with "Tex-Mex", so don't say "teks" or people will laugh at you. There are two ways of pronouncing LaTeX, one of which I can't stand, so I will give you the other. It's just like you would pronounce the world "latex" except for replacing the final sound "ks" with "k" (because it's a derivative from TeX).

You won't be interacting with TeX directly although everything boils down to it. Only the most seasoned computer veterans with a death wish would descend to that level. Instead, you, like me and like all other weenies, will be working with LaTeX, whose author Leslie Lamport has tamed the beast for the rest of us.

LaTeX is a package that allows the use of markup in the document to structure it logically in a way that users would never have to think about formatting. This is similar to style sheets (CSS) in HTML and styles in Word. You mark different sections of your document in different ways and then you can produce a variety of layouts by tinkering with the styles, not with the text.

That's all in theory. In practice, most people do not tinker with anything at all, and so their LaTeX documents are instantly recognizable because they all look the same. Yours will look canned too for a while until you develop a taste for tinkering. Then you will find out that not everything is as rosy as I made it sound.

For now, all you have to remember is that a LaTeX document, sometimes called source' is your text with markup (commands telling the program how to format it) interspersed throughout. HTML is a markup language and the concept is the same.

This means that your source is not something you'd be looking at without the aid of an interpreter. For example, you use a browser to look at HTML pages. The browser reads the markup along with the text and then displays it accordingly.

LaTeX documents are similar except that you compile' them first into viewable files. That is, you translate the ASCII (human-readable) text with markup into binary (machine-readable) files that you can then preview, print, or forget.

## 2. Overview of the Document Creation Process

Let's say you have a document in a file called 'paper.tex' The extension '.tex' is a convention, so you may want to stick with it. Generally, you will go through a series of steps for each document.
1. Write text with LaTeX markup code in text editor -> produces 'paper.tex'
2. Run 'latex' on this source -> produces 'paper.dvi'
3. Preview 'paper.dvi' in a special viewer
4. Edit your paper, go back to step 1.
So, YOU create the file 'paper.tex'. When you compile the source with 'latex' (a program installed by MiKTeX), this program will create the file 'paper.dvi' The extension '.dvi' stands for "device independent". This is a binary file that can only be looked at with special viewers. MiKTeX has installed one such viewer, and it is called 'yap'. To view the document, you'd type 'yap paper' and marvel at the result. ('yap' stands for "yet another previewer", a goofy way of naming things with a long and honored tradition in computer science).

Now, here's why you want WinEdt in the first place: It lets you compile and preview documents without having to run commands from the command line (which many may not even know how to get to). This is accomplished by the cunning use of pull-down menus and toolbar buttons, much like you're used to clicking in Windows.

So, you fire up WinEdt, and then do everything from there!

## 3. An example first document

So, start WinEdt and create a new empty file (Ctrl+N). Now type the following text exactly:
\documentclass{article}

\title{Hello, Cruel World!}

\begin{document}
\maketitle

\section{Introduction}
This is where you tell people why they should bother reading your article.

\section{Literature Review}
This is the section that is invariably much longer than it should be, and
where everyone tries to impress peers about how easy it is to locate various
references in online databases.

\section{Conclusion}
Not much of a paper, but it's a start.

\end{document}

1. Save the document in some folder and call it 'test.tex'.
2. Select "LaTeX" from the Accessories menu in WinEdt. This will run latex on your source. If it produces an error, either you have a typo in the source or you did not install the programs correctly.
3. Select "DVI Preview" from the same menu. This will run yap on the dvi file (which now lives in the same folder as the source) and you should see a nice 1-page document.
That's all there is to it. These are the basic mechanics. It gets a bit fancier if you want to do things like bibliographies or create PDF documents from the DVI. More on that later. For now, remember that you will generally go through the DVI file, and you can print the document from the YAP previewer.

## 4. Some Explanation

There are two sections in each LaTeX document. The first is called the 'preamble', and the other is the document:
\documentclass{article}

% --> this is the preamble

\begin{document}

% --> this is the document

\end{document}

The first line tells LaTeX that it should format your document as an article. There are other classes (e.g. book, slide) but this is the one you will be using 99% of the time.

The next two lines tell LaTeX the author and the title so it can typeset them properly.

Then the document begins. With first command tells LaTeX to typeset the title immediately. This also generates the current date automatically.

Then your document follows. As you see, it is logically divided into sections. LaTeX formats and numbers them properly for you. If you move them around in your source, LaTeX will renumber them. Let's try it. Modify the source to look like this:

\documentclass[12pt]{article}

\title{Hello, Cruel World!}
\\Department of Political Science
\\UCSD}

\begin{document}
\maketitle

\section{Introduction}
This is where you tell people why they should bother reading your article.

\subsection{What Is the Question?}

\subsection{Why Do We Care?}
We're all generally curious.

\section{Conclusion}
Not much of a paper, but it's a start.

\section{Literature Review}
This is the section that is invariably much longer than it should be, and
where everyone tries to impress peers about how easy it is to locate various
references in online databases.

\end{document}
`
Run latex and refresh the previewer. First, note the '12pt' argument to the document class command has changed the font size (the default is 10pt, which is too small). Also, the department name and university affiliation have been added to the author information. You can indulge in the common practice of thanking everyone by the use of the '\thanks' command. Further, we introduces a couple of subsections, and moved sections around. Note the numbering that LaTeX supplies automatically.

And that's all there is to it!

Branislav L. Slantchev, UCSD