## LaTeX: My First LaTeX Document

Now that you should have LaTeX on your PC, this tutorial will provide you with almost all you need to write your first LaTeX document. It is highly recommended that you try out the examples by yourself to see how easy yet professional LaTeX can be.

## Input File Preliminary Structure

Because LaTeX is consistent and will always provide the output you had in mind, you need to be consistent too. Any input file should start with defining a document class, such command tells LaTeX what kind of document you are intending to write. A LaTeX document could be any of article, letter, book, articles or others as we will see later on. For this demonstration, we will use 'article'. You can also provide additional options like the paper size, layout (portrait or landscape) and the font size that you will be using for normal text within your article.

\documentclass[a4paper,10pt]{article}

The \documentclass[options]{class} is the command where you specify options like the number of columns in each page, font size, page layout, one side or two sided printing and so on. You are highly encouraged to check Tables 1.1 & 1.2 of the "The Not So Short Introduction to LaTeX2e" for a deeper insight in the options and document classes of the \documentclass command.

Just for now, we will skip the talk about commands that you can include to have a more customized document. Let us just begin our first article. The actual LaTeX article should be included as follows:

\begin{document} Hello World! \end{document}

The \documentclass command must be your first command, and the script between it and the \begin{document} will be referred to as the "preamble" of your document. We will be talking about the preamble in a couple of minutes.

## Document Preamble

It's not our aim in this tutorial to provide a mini-documentation for LaTeX; there are plenty out there. Nevertheless, we provide brief hints of commands that are most frequently used in the document preamble, as the next tutorials in this series will assume pre-knowledge of such commands.

By default, LaTeX adds page numbers to the center bottom of the page. To disable such output, you need to modify the default value of the page style, using:

\thispagestyle{empty}

The \thispagestyle{option} command is used as well to manipulate the headers and footers, but we will not talk about this at least for the moment. You can check Table 1.4 of the "The Not So Short Introduction to LaTeX2e" for an overview of the available styles. In our demonstration we will not use it, because it would be nice to have a first page numbered document.

One of the most frequently used commands in the preamble as well is the command to include a package. Packages are meant to enhance the capabilities of the core LaTeX, to include graphics, colors, fancy headers and others. You will need the command:

\usepackage[options]{package}

## Spaces and paragraphs

As you have already seen, you can start writing just after the \begin{document} command. One thing to note about spaces. Like HTML, several consecutive white spaces will be treated as only one. The same follows for empty lines, a single empty line (as well as multiple ones) denote the end of a paragraph.

\LaTeX{} is pretty straight forward, multiple spaces are ignored. A new line continues within the same paragraph. But an empty line starts a new paragraph.

The commands in LaTeX starts with a \ followed by the command name. Commands usually eat any spaces just after it, to override this you can append {} at the end just as we did above.

## Special characters

There's a set of escape sequences for special characters, for a larger set please check the LaTeX Cheat sheet.

These characters should be escaped: \# \$\% \& \_ \{ \} \~{} \^{} and the backslash needs special treatment$\backslash\$

LaTeX provides you with the opportunity (that your word processor doesn't) to add notes to your article which will not be printed out. To comment a single line use a % sign at the beginning or to comment a whole block use:

% This will not be printed, because of the % at the beginning \begin{comment} Not even these ones down here! \end{comment}

and ofcourse we don't have a preview here... simply because it is not printed out! One short note, to use the block comment you need to use the verbatim package. Do it in the preamble as \usepackage{verbatim}

## Layout & Sectioning

One of the mighty powers of Latex, is the ease of organizing your document (which can be as huge as an encyclopedia!). In this word editor, that we don't remember its name, generating a table of contents for a 20 pages document can be as hectic as writing the 20 pages. In Latex you can layout your document using the following commands.

\section{My First Latex Document} \subsection{Typesetting Text} \subsubsection{Escape Sequence} \paragraph{...} \subparagraph{...}

To generate a table of contents with the headings and numbers of your document sections, you just issue one command where you want it to be displayed.

\tableofcontents

To skip a certain section from the table of contents, just use an '*'

\subsection*{Hidden Section}

Actually, the real power of Latex sectioning comes handy when you are referenecing other sections. You can label each of your sections, and reference them by label. When the document is compiled the labels are translated into section numbers. This spares you quite a lot of work, especially with document revisions. You would know what I'm talking about if you ever finished your document and then decided that a couple of sections should be swapped, lucky you, you want have to trace the references back.

You can skip this section\label{sec:beginner} and jump to section \ref{sec:professional} on page \pageref{sec:professional}, if you are already familiar with the topic.

The \label command defines a label for one part of a document which can be referenced later on using the \ref or the \pageref commands. The above code snippet would display as follows, note that the section number and page would change each time we add a section prior to 6.1 for instance.

## Layout & Sectioning

One of the mighty powers of Latex, is the ease of organizing your document (which can be as huge as an encyclopedia!). In this word editor, that we don't remember its name, generating a table of contents for a 20 pages document can be as hectic as writing the 20 pages. In Latex you can layout your document using the following commands.

\section{My First Latex Document} \subsection{Typesetting Text} \subsubsection{Escape Sequence} \paragraph{...} \subparagraph{...}

To generate a table of contents with the headings and numbers of your document sections, you just issue one command where you want it to be displayed.

\tableofcontents

To skip a certain section from the table of contents, just use an '*'

\subsection*{Hidden Section}

Actually, the real power of Latex sectioning comes handy when you are referenecing other sections. You can label each of your sections, and reference them by label. When the document is compiled the labels are translated into section numbers. This spares you quite a lot of work, especially with document revisions. You would know what I'm talking about if you ever finished your document and then decided that a couple of sections should be swapped, lucky you, you want have to trace the references back.

You can skip this section\label{sec:beginner} and jump to section \ref{sec:professional} on page \pageref{sec:professional}, if you are already familiar with the topic.

The \label command defines a label for one part of a document which can be referenced later on using the \ref or the \pageref commands. The above code snippet would display as follows, note that the section number and page would change each time we add a section prior to 6.1 for instance.

## Footnotes

Footnotes\footnote{are so called, because they are displayed at the 'foot' of the page} are used to illustrate a side fact or to provide supplementary information.

## Formatting Text

Although it's not a very good practice to format words using underlines, italics and so forth, but you sometimes need to emaphasize a certain part of your text, maybe a theorem or so. The default for emphasis is italics.

Our main objective is the \emph{quality} of the document. You can as well use \underline{underlines}, but it doesn't look professional enough.

You can also override the default choice for the font face and font size. Check the Latex Cheat Sheet for a summary of the availabla alternatives. Nevertheless, it is highly suggested that you don't override the default fonts in normal text, only do it within an appropriate context (e.g. using typewriter font for code snippets) or when formatting a title page for instance.

## Lists

It is quite often that you need to insert a numbered lists, or even nested lists of lists (those lists that you cannot manage in your word editor). In Latex, it is quite simple and predictable. It follows as:

\begin{enumerate} \item That's the first item in the list. \item and that's the second. \item this can go infinite, if you want. \end{enumerate}

Ofcourse, the tabbing above is not a part of the syntax, it is only for clarity. Especially when you're working on nested lists. Another quite frequent type of lists, is lists with bullets. Here's a combined example.

\begin{enumerate} \item That's the first item in the list. \begin{itemize} \item The first item of the first list \item and even more items. \item[-] you can even specify your bullet! \end{itemize} \item and that's the second. \item this can go infinite, if you want. \end{enumerate}

A definition list, is yet another type, that looks neat. Needless to say, it can be combined or nested within other structures.

\begin{description} \item[Word Processors] An irritating program to write your school assignments. Highly suggested for 2 page documents, and for dummies. \item[ \end{description}

## Text Alignment

Although Latex spares you the effor to layout your document, you might need in some cases to modify the default (left) text alignment. Using the flush environment.

\begin{center} Text alignment basics \end{center} \begin{flushleft} Write as much as you want of the left aligned text and then end the flush left using the \verb!\end{flushleft}! \end{flushleft} \begin{flushright} It should be obvious how this is right aligned! \end{flushright}

## Wrapping up

Having seen how to layout your document and format your text using Latex, it is highly recommended that you go on and practice it. Similar to programming, mastering a programming language would mean you're capable of solving any problem using that language. If you believe there are things that you cannot do with Latex, it does not mean it cannot be done, you just do not know it yet.

## Tutorial source

For this tutorial, as well as all others, it is a good practice that you download the .tex file and the output.pdf file. Taking a look at the pdf file and trying to realize which part of the code actually did that, would make you more familiar with the tags, it is pretty straight forward.

## Coming up next

The next tutorial, will present more advanced (yet still quite simple) capabilities of Latex. Things like title pages, tables, figures, headers and footers and lots of others that are substantial elements of any document. In parallel, a set of other tutorials are published that guide you through your first steps in preparing your presentation slides using Latex.