From charlesreid1

LaTeX Overview

LaTeX is a document typesetting system used primarily for scientific and mathematical documents. Latex consists of Tex source code, which is typeset and output into one of a number of different formats (PDF, DV, PS, etc.)

The following LaTeX code is a selection from Batchelor's classic Introduction to Fluid Dynamics:

\documentclass[12pt]{article}
\usepackage{amsmath}
\title{\LaTeX Example}
\date{}
\begin{document}

\maketitle

The function $\boldsymbol{u}(\boldsymbol{x},t)$ will thus be the primary 
dependent variable in our analysis, and other flow quantities such as 
pressure will likewise be regarded as being functions of $\boldsymbol{x}$ and $t$.

When $\boldsymbol{u}$ is independent of $t$, the flow is said to be \emph{steady}.

A line in the fluid whose tangent is everywhere parallel to $\boldsymbol{u}$ instantaneously 
is a line of flow, or a \emph{streamline}; the family of streamlines at time $t$ are solutions of

\begin{equation}
\frac{dx}{ u(\boldsymbol{x},t) } = \frac{ dy }{ v(\boldsymbol{x}, t) } = \frac{ dz }{ w(\boldsymbol{x}, t) },
\end{equation}

where $u,v,w$ are the components of $\boldsymbol{u}$ parallel to rectilinear 
axes and $x,y,z$ are the components of $\boldsymbol{x}$. When the flow is steady, 
the streamlines have the same form at all times. A related concept is a \emph{stream-tube}, 
which is the surface formed instantaneously by all the streamlines that pass through a given closed 
curve in the fluid.

\end{document}

and, when typeset, it generates the following text as output:

Output of given LaTeX example.


Parts of a Latex Document

The following barebones LaTeX document will be used as a starting point for discussing different parts of a LaTeX document:

\documentclass[english]{article}
\begin{document}
This is a basic latex document.
\end{document}

Preamble

The preamble is the portion that comes before the \begin{document}. It first specifies the class of the document. This must be specified because LaTeX needs to know what settings to use for things like margins, font, sections, subsections, etc. The first class you can try is "article", but there are a number of different classes, such as book, phdthesis, letter, etc. You can even write your own LaTeX class, if you find yourself getting picky about the same fonts, settings, layouts, etc., and always use the same settings (or at least, want to bundle them together in an easy-to-use package). Many scientific journals provide their own class files for journal articles submitted to the journal.

The preamble is also where you specify packages to use. Many mathematical functions and notation require a mathematics package; additionally, other packages for graphics, colors, tables, etc. also use packages, and are not included by default.

\documentclass[english]{article}

% The following packages provide AMS (American Mathematical Society) functions, fonts, and symbols:
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

% The following package allows graphics to be put into LaTeX documents:
\usepackage{graphpicx}

% The following package allows wrapping text around figures:
\usepackage{wrapfig}

\begin{document}
This is a basic latex document.
\end{document}

Additionally, other document settings can be specified in the preamble.

The title, author, and date of the document can be set using:

\title{Document Title}
\author{Author Name}
\date{\today}

The size of paragraph indents can be set using:

\setlength{\parindent}{16pt}

The depth of section numbering (i.e. 1.2.3.4.5.6.....) can be set using:

\setcounter{secnumdepth}{3}

The basis for equation numbering can be set using

\numberwithin{equation}{section}

Some information, such as page numbers, may be included by default in the header or footer. To empty the header and footer, add this to the preamble:

\pagestyle{empty}

Margins

Margins can also be set in the preamble. The default margins are 1 inch. The left margin can be set by adding to or subtracting from the default value, by using \addsidemargin:

\setlength{\addsidemargin}{-0.25in}
% Alternatively,
\addsidemargin=-0.25in

which will make the left side margin 1 in - 0.25 in = 0.75 in.

To make the left and right margins match, the text width must be set using

\setlength{\textwidth}{7.0in}
% Alternatively,
\textwidth=7.0in

It can be set according to

$ \text{page width} = \text{left margin} + \text{text width} + \text{right margin} $

Plenty of additional details and settings relating to margins can be found here: http://en.wikibooks.org/wiki/LaTeX/Page_Layout

Body

Top Matter

The top matter consists of things set after the \begin{document} that set information about the document. The title, author, and date may be set in the preamble, or it may be set in the top matter. The main page, which contains the title, author, and date of the document, can be included using the LaTeX command \mainpage. More complex authors and titles can be set... for example,

\title{Document Title}
\author{Author1 \and Author2 \\
  Department \\
  University \\
  City \\
  State \\
  Country \\
  \texttt{address@email.com}
}
\date{\today}

and the title page created via

\maketitle

More advanced title page creation may be found here: http://en.wikibooks.org/wiki/LaTeX/Title_Creation

Abstract

The abstract of a document, like the document body, may be created by putting it between \begin{abstract} and \end{abstract}. For example, the LaTeX version of [Einstein, Podolsky, and Rosen's paper Can Quantum-Mechanical Description of Physical Reality Be Considered Complete? http://prola.aps.org/abstract/PR/v47/i10/p777_1] would look something like this:

\documentclass[english]{article}
\begin{document}

\title{Can Quantum-Mechanical Description of PHysical Reality Be Considered Complete?}
\author{A. Einstein \and B. Podolsky \and N. Rosen}
\date{May 1935}

\maketitle

\begin{abstract}
In a complete theory there is an element corresponding to each element of reality. A sufficient condition for the reality of a physical quantity is the possibility of predicting it with certainty, without disturbing the system. In quantum mechanics in the case of two physical quantities described by non-commuting operators, the knowledge of one precludes the knowledge of the other. Then either (1) the description of reality given by the wave function in quantum mechanics is not complete or (2) these two quantities cannot have simultaneous reality. Consideration of the problem of making predictions concerning a system on the basis of measurements made on another system that had previously interacted with it leads to the result that if (1) is false then (2) is also false. One is thus led to conclude that the description of reality as given by a wave function is not complete.
\end{abstract}

\end{document}

Sections

In a document, a hierarchy of sections can be created using the LaTeX commands \section, \subsection, \subsubsection, etc.

The preamble may contain \setcounter{secnumdepth}{N}, which will number N levels of sections. These are, in order,

  • section
    • subsection
      • subsubsection
        • paragraph
          • subparagraph




LaTeX Examples

I have several examples of (simple) LaTeX documents and reports at the documents page.

Software

There are a large number of programs and pieces of software for interfacing with LaTeX. The simplest is to use LaTeX through a text editor, such as Vim or Emacs, or a LaTeX text editor such as TexMaker or TexShop. Alternatively, one may use a full WYSIWYM (What You See Is What You Mean) editor like LyX.

Personally, I recommend TexMaker for creating LaTeX documents by hand, and LyX for putting together LaTeX documents with lots of equations, or in a short time.

Tricks and Tips

Stump.gif This article is a stub.

A team of expertly-trained librarian ninjas has been dispatched to research this topic, finish this article, and assassinate all eyewitnesses who contradict their account.

They should be done pretty soon.

Template:Stub

Category:Stubs

References

http://www.texample.net/tikz/examples/rooty-helix/

http://www.texample.net/