## Overview of LaTeX

LaTeX is a system for typesetting documents. It was originally created by Leslie Lamport and is now maintained by a group of volunteers (http://latex-project.org). It is widely used, particularly for complex and technical documents, such as those involving mathematics.

A LaTeX user writes an input file containing text along with interspersed commands, for instance commands describing how the text should be formatted. It is implemented as a set of related commands that interface with Donald E. Knuth’s TeX typesetting program (the technical term is that LaTeX is a macro package for the TeX engine). The user produces the output document by giving that input file to the TeX engine.

The term LaTeX is also sometimes used to mean the language in which the document is marked up, that is, to mean the set of commands available to a LaTeX user.

The name LaTeX is short for “Lamport TeX”. It is pronounced LAH-teck or LAY-teck, or sometimes LAY-tecks. Inside a document, produce the logo with `\LaTeX`. Where use of the logo is not sensible, such as in plain text, write it as ‘`LaTeX`’.

### Starting and ending

LaTeX files have a simple global structure, with a standard beginning and ending. This is a small example.

    \documentclass{article}
    \begin{document}
    Hello, \LaTeX\ world.
    \end{document}

Every LaTeX document has a `\begin{document}` line and an `\end{document}` line.

Here, the ‘`article`’ is the document class. It is implemented in a file `article.cls`. You can use any document class on your system. A few document classes are defined by LaTeX itself, and vast array of others are widely available. See Document classes.

You can include other LaTeX commands between the `\documentclass` and the `\begin{document}` commands. This area is called the preamble.

The `\begin{document}`, `\end{document}` pair defines an environment; the ‘`document`’ environment (and no others) is required in all LaTeX documents (see document). LaTeX make available to you many environments that are documented here (see Environments). Many more are available to you from external packages, most importantly those available at CTAN (see CTAN).

The following sections discuss how to produce PDF or other output from a LaTeX input file.

### Output files

LaTeX produces a main output file and at least two auxiliary files. The main output file’s name ends in either `.dvi` or `.pdf`.

`.dvi`

  If LaTeX is invoked with the system command `latex` then it produces a DeVice Independent file, with extension `.dvi`. You can view this file with a command such as `xdvi`, or convert it to a PostScript `.ps` file with `dvips` or to a Portable Document Format `.pdf` file with `dvipdfmx`. The contents of the file can be dumped in human-readable form with `dvitype`. A vast array of other DVI utility programs are available (http://mirror.ctan.org/dviware).

`.pdf`

  If LaTeX is invoked via the system command `pdflatex`, among other commands (see TeX engines), then the main output is a Portable Document Format (PDF) file. Typically this is a self-contained file, with all fonts and images included.

LaTeX also produces at least two additional files.

`.log`

  This transcript file contains summary information such as a list of loaded packages. It also includes diagnostic messages and perhaps additional information for any errors.

`.aux`

  Auxiliary information is used by LaTeX for things such as cross references. For example, the first time that LaTeX finds a forward reference—a cross reference to something that has not yet appeared in the source—it will appear in the output as a doubled question mark `??`. When the referred-to spot does eventually appear in the source then LaTeX writes its location information to this `.aux` file. On the next invocation, LaTeX reads the location information from this file and uses it to resolve the reference, replacing the double question mark with the remembered location.

LaTeX may produce yet more files, characterized by the filename ending. These include a `.lof` file that is used to make a list of figures, a `.lot` file used to make a list of tables, and a `.toc` file used to make a table of contents (see Table of contents etc.). A particular class may create others; the list is open-ended.

### TeX engines

LaTeX is defined to be a set of commands that are run by a TeX implementation (see Overview). This section gives a terse overview of the main programs (see also Command line).

`latex`
`pdflatex`

  In TeX Live (http://tug.org/texlive), if LaTeX is invoked via either the system command `latex` or `pdflatex`, then the pdfTeX engine is run (http://ctan.org/pkg/pdftex). When invoked as `latex`, the main output is a `.dvi` file; as `pdflatex`, the main output is a `.pdf` file.

  pdfTeX incorporates the e-TeX extensions to Knuth’s original program (http://ctan.org/pkg/etex), including additional programming features and bi-directional typesetting, and has plenty of extensions of its own. e-TeX is available on its own as the system command `etex`, but this is plain TeX (and produces `.dvi`).

  In other TeX distributions, `latex` may invoke e-TeX rather than pdfTeX. In any case, the e-TeX extensions can be assumed to be available in LaTeX.

`lualatex`

  If LaTeX is invoked via the system command `lualatex`, the LuaTeX engine is run (http://ctan.org/pkg/luatex). This program allows code written in the scripting language Lua (http://luatex.org) to interact with TeX’s typesetting. LuaTeX handles UTF-8 Unicode input natively, can handle OpenType and TrueType fonts, and produces a `.pdf` file by default. There is also `dvilualatex` to produce a `.dvi` file, but this is rarely used.

`xelatex`

  If LaTeX is invoked with the system command `xelatex`, the XeTeX engine is run (http://tug.org/xetex). Like LuaTeX, XeTeX natively supports UTF-8 Unicode and TrueType and OpenType fonts, though the implementation is completely different, mainly using external libraries instead of internal code. XeTeX produces a `.pdf` file as output; it does not support DVI output.

  Internally, XeTeX creates an `.xdv` file, a variant of DVI, and translates that to PDF using the (`x`)`dvipdfmx` program, but this process is automatic. The `.xdv` file is only useful for debugging.

Other variants of LaTeX and TeX exist, e.g., to provide additional support for Japanese and other languages ([u]pTeX, http://ctan.org/pkg/ptex, http://ctan.org/pkg/uptex).

### LaTeX command syntax

In the LaTeX input file, a command name starts with a backslash character, `\`. The name itself then consists of either (a) a string of letters or (b) a single non-letter.

LaTeX commands names are case sensitive so that `\pagebreak` differs from `\Pagebreak` (the latter is not a standard command). Most commands are lowercase, but in any event you must enter all commands in the same case as they are defined.

A command may be followed by zero, one, or more arguments. These arguments may be either required or optional. Required arguments are contained in curly braces, `{...}`. Optional arguments are contained in square brackets, `[...]`. Generally, but not universally, if the command accepts an optional argument, it comes first, before any required arguments.

Inside of an optional argument, to use the character close square bracket (`]`) hide it inside curly braces, as in `\item[closing bracket {]}]`. Similarly, if an optional argument comes last, with no required argument after it, then to make the first character of the following text be an open square bracket, hide it inside curly braces.

Some of LaTeX’s commands are a declaration. Such a command changes the value the meaning of some other command or parameter. For instance, the `\mainmatter` declaration changes the typesetting of page numbers from roman numerals to arabic (see \frontmatter & \mainmatter & \backmatter).

LaTeX has the convention that some commands have a `*` form that is related to the form without a `*`, such as `\chapter` and `\chapter*`. The exact difference in behavior varies from command to command.

This manual describes all accepted options and `*`-forms for the commands it covers (barring unintentional omissions, a.k.a. bugs).

### Environment

Synopsis:

    \begin{environment name}
      ...
    \end{environment name}

An area of LaTeX source, inside of which there is a distinct behavior. For instance, for poetry in LaTeX put the lines between `\begin{verse}` and `\end{verse}`.

    \begin{verse}
      There once was a man from Nantucket \\
      ...
    \end{verse}

See Environments for a list of environments. Particularly notable is that every LaTeX document must have a `document` environment, a `\begin{document} ... \end{document}` pair.

The environment name at the beginning must exactly match that at the end. This includes the case where environment name ends in a star (`*`); both the `\begin` and `\end` texts must include the star.

Environments may have arguments, including optional arguments. This example produces a table. The first argument is optional (and causes the table to be aligned on its top row) while the second argument is required (it specifies the formatting of columns).

    \begin{tabular}[t]{r|l}
      ... rows of table ...
    \end{tabular}

### CTAN: the Comprehensive TeX Archive Network

The Comprehensive TeX Archive Network, CTAN, is the TeX and LaTeX community’s repository of free material. It is a set of Internet sites around the world that offer material related to LaTeX for download. Visit CTAN on the web at https://ctan.org.

This material is organized into packages, discrete bundles that typically offer some coherent functionality and are maintained by one person or a small number of people. For instance, many publishers have a package that allows authors to format papers to that publisher’s specifications.

In addition to the massive holdings, the web site offers features such as search by name or by functionality.

CTAN is not a single site, but instead is a set of sites. One of the sites is the core. This site actively manages the material, for instance, by accepting uploads of new or updated packages. It is hosted by the German TeX group DANTE e.V. Other sites around the world help out by mirroring, that is, automatically syncing their collections with the core site and then in turn making their copies publicly available. This gives users close to their location better access and relieves the load on the core site. The list of mirrors is at https://ctan.org/mirrors.