[edit] ShareLaTeX guides

[edit] LaTeX Basics

[edit] Mathematics

[edit] Figures and tables

[edit] References and Citations

[edit] Languages

[edit] Document structure

[edit] Formatting

[edit] Fonts

[edit] Presentations

[edit] Commands

[edit] Field specific

[edit] Class files

LaTeX is a great tool to create documents, it's based on the wysiwym (what you see is what you mean) idea, meaning you only have focus on the contents of your document and the computer will take care of the formatting. With LaTeX is very easy to create professional-looking material. This article presents the basics to create a document.


[edit] Introduction

Let's start with the simplest working example:

First document. This is a simple example, with no 
extra parameters or packages included.


The first line of code declares the type of document, in this case is a article. Then enclosed in the \begin{document} \end{document} tags you must write the text of your document.

Note: To learn how to generate the output file see the Compile article

  Open an example in ShareLaTeX

[edit] The preamble of a document

In the previous example the text was entered after the \begin{document} command. The part of your .tex file before this point is called the preamble. In the preamble you define the type of document you are writing, the language and several other elements. For instance, a normal document preamble would look like this:

\documentclass[12pt, letterpaper]{article}
\title{First document}
\author{Hubert Farnsworth \thanks{funded by the ShareLaTeX team}}
\date{February 2014}

Below a detailed description of each line:

\documentclass[12pt, letterpaper]{article}
As said before, this defines the type of document. Some additional parameters inside brackets and comma-separated can be passed to the command. In the example, the extra parameters set the font size (12pt) and the paper size (letterpaper). Of course other font sizes (9pt, 11pt, 12pt) can be used, the default size is 10pt. As for the paper size other possible values are a4papper and legalpaper; see the article about Page size and margins for more details about this.
This is the encoding for the document. Can be omitted or changed to another encoding but utf-8 is recommended. Unless you specifically need another encoding, or if you are unsure about it, add this line to the preamble.

The next three lines are self-descriptive. Anyway, you can see a description about what they actually do in the next section.

Another important parameter that can be passed to the \documentclass command is twocolumn if you want your text in a two-column format and twoside for two-side paper sheet printing.

  Open an example in ShareLaTeX

[edit] Displaying the title of your document

To display the title of your document you have to declare its components in the preamble and then use some additional code:

\documentclass[12pt, letterpaper, twoside]{article}
\title{First document}
\author{Hubert Farnsworth \thanks{funded by the ShareLaTeX team}}
\date{February 2014}
In this document some extra packages and parameters
were added. There is a encoding package
an a pagesize and fontsize parameters.


There is a block with three lines in the preamble that define what information is going to be included in the title page.

\title{First document}
This is the title.
\author{Hubert Farnsworth}
Here you put the name of the Author(s) and, as a optional parameter, you can add the next command:
\thanks{funded by the ShareLaTeX team}
This can be added after the name of the author, inside the braces of the title command. It will add a superscript and a footnote with the text inside the braces. Useful if you need to thank an institution in your article.
\date{February 2014}
You can enter the date manually or use the command \today so the date will be updated automatically at the time you compile your document.

Once you have that in the preamble now in the body of your document you can use the next commands for the information to be printed.

\begin{titlepage} \end{titlepage}
This declares an environment, a block of code with a specific behaviour depending on its type. In this case whatever you include in this titlepage environment will appear in the first page of your document.
This command will print the title, the author and the date in the format shown in the example. If it's not enclosed in a titlepage environment, it will be shown at the beginning of the document, above the first line.

  Open an example in ShareLaTeX

[edit] Basic formatting: abstract, paragraphs and newlines

Everything included inside the \begin{document} \end{document} commands will be rendered in the final document.

This is a simple paragraph at the beginning of the 
document. A brief introduction about the main subject.
In this document some extra packages and parameters
were added. There is a encoding package
an a pagesize and fontsize parameters.
This line will start a second Paragraph. And I can
 brake\\ the lines \\ and continue in a new line.


In scientific documents it's a common practice to include a brief overview of the main subject of the paper. In LaTeX there's the abstract environment for this. The abstract environment will put the text in a special format at the top of your document.

When writing the contents of your document, if you need to start a new paragraph you must hit the "Enter" key twice (to insert a double blank line). Notice that paragraphs have a white space before the first line.

To start a new line without actually starting a new paragraph insert a break line point, this can be done by \\ (a double backslash as in the example) or the \newline command

You can find more information in the Paragraphs and new lines article.

For a more complete discussion about the document structure see the article about sections and chapters.

  Open an example in ShareLaTeX

[edit] Comments

Sometimes it's necessary to add comments to your LaTeX code for readability. This is straightforward, put a % before the comment and LaTeX will ignore that text.

\usepackage[utf8]{inputenc} %codification of the document
%Here begins the body of the document
This documents contains a lot of comments, non of them
will appear here, only this text.
This documents contains a lot of comments, non of them
will appear here, only this text.
This text won't show up in the compiled pdf
this is just a multi-line comment. Useful
to, for instance, comment out slow-rendering
while working on the draft.


In the last part of the example you can see a comment environment, this helps in multi-line comments instead of putting a % at the beginning of each line. For this to work you must add the next line to your preamble:


The % symbols is a reserved character, if you actually need this symbol to be printed in your document, use \%. See the reference guide for a full list of reserved characters.

[edit] Reference guide

Document types available in the \documentclass command.

Document type Description
article For short documents and journal articles. Is the most commonly used.
report For longer documents and dissertations.
book Useful to write books
letter For letters
slides For slides, rarely used
beamer Slides in the Beamer class format. See the beamer documentation for a better description

Reserved characters

The following symbol characters are reserved by LaTeX because they introduce a command and have a special meaning.

# $ % ^ & _ { } ~ \

These symbols and can be printed with special commands (in some cases - inside mathematical environment).

Character Function How to print it
# Macro parameter \#
$ Math mode \$
 % Comment \%
^ Superscript (in math mode) \^{} or $\textasciicircum$
& Separate column entries in tables \&
_ Subscript (in math mode) \_
{ } Processing block \{ \}
~ Unbreakable space, use it whenever you want to leave a space which is unbreakable $\textasciitilde$ or \~{}
\ Starting commands, which extend until the first non-alphanumerical character $\textbackslash$ or $\backslash$

[edit] Further reading