ShareLaTeX guides

LaTeX Basics


Figures and tables

References and Citations


Document structure





Field specific

Class files

The styles, contents and layout in a L a T e X document are defined by means of tags or commands in a plain .tex file, this file can be used to generate several types of "human-readable" versions of the document. The easiest way to generate this final output is to use ShareLaTeX , ShareLaTeX has a ready-to-use LaTeX distribution and final documents can be generated by simply clicking the "Recompile" button; if this is your case you can skip this article. Otherwise, if you need to learn how to compile documents in your computer, this article describes how to generate PS, DVI and PDF output from a L a T e X file.



L a T e X documents are plain documents with a .tex extension (see the Creating a document in LaTeX article for examples), this plain text file has some markup commands that are meant to format the document but, how do you actually generate the final output?. It depends on the type of document you want to generate.

Suppose you saved your document and named the file "mydocument.tex". To create a .PDF file just run this command in the system terminal.

pdflatex mydocument.tex

And a file named "mydocument.pdf" will appear.

TeX distributions

The set of programs that make possible to compile T e X and L a T e X documents is called a T e X typesetting or a T e X distribution. There are many T e X distributions available for different operating systems:

  • MiKTeX for Windows
  • TeX Live for Linux and other UNIX-like systems
  • MacTeX redistribution of TeX Live for Mac OS X
  • teTeX for Linux and other UNIX-like systems, now is no longer actively maintained
  • proTeXt is based on MiKTeX

Of course, if you don't want to go through the process of installing a T e X distribution, you can use an on-line ready to use option like ShareLaTeX .

LaTeX editors

There are many advanced text editors specifically dedicated to L a T e X for the most popular operating systems, some of them can be downloaded for free while others are proprietary software:

  • Open source: AUCTEX, GNU TeXmacs, Gummi, Kile, LaTeXila, MeWa, TeXShop, TeXnicCenter, Texmaker, TeXstudio, TeXworks
  • Freeware: LEd, WinShell
  • Proprietary/Shareware: Inlage, Scientific WorkPlace, WinEdt

There are also general-purpose editors that add L a T e X -friendly options by means of plugins. For example the well known editors emacs and vim have both a LaTeX extension.

It's worth to mention that the editor in ShareLaTeX can be customized to emulate the emacs or vim behaviour. It is also themeable , so you can choose the same syntax highlighting of some of the aforementioned editors.

Output formats

There are three output formats available in all T e X distributions. To generate a specific output the document has to be compiled by running a command in a terminal (linux and osx) or the command prompt (windows).

For example, if you want to compile a file named "mydocument.tex" you can use one of the next commands:

latex mydocument.tex
This will create "mydocument.dvi", a DVI document
pdflatex mydocument.tex
This will generate "mydocument.pdf", a PDF document

There are some additional commands that allow conversion between formats, PS images are also supported. See the reference guide for a schematic description of commands and output formats.

A description of each output format is provided below:

  • (DVI) Device independent file format consists of binary data describing the visual layout of a document in a manner not reliant on any specific image format, display hardware or printer.
  • (PS) PostScript file format describes text and graphics on page and it is based on vector graphics. PostScript is, until now, a standard in desktop publishing areas.
  • (PDF) Portable Document Format is a file format, based on PostScript, used to represent documents in a manner independent of application software, hardware, and operating systems. It is now widely used as a file format for printing and for distribution on the Web.

Note: Most of the editors nowadays include quick-access icons to compile to different output formats so you don't have to actually run the commands in a system prompt.

Compiling documents with cross-references

In some cases, when your document includes cross-references, you must compile the source twice. It is necessary to include the correct numbers in the table of contents, list of images, reference numbers to theorems and so on.

During the first compilation the L a T e X compiler writes the .aux file for informations about different numbering and during the second one the compiler reads these informations in order to properly generate a table of contents, bibliography, etc.

This process can be automatized by the command latexmk . For example, to create a pdf out of the "mydocument.tex" file, run

latexmk -pdf mydocument.tex

only once, even if the document has referenced images and bibliography. You can change -pdf to -dvi to set a different file type.

Reference guide

L a T e X compilation file flow

Latex file flow

Further reading