LaTeX: Difference between revisions
From charlesreid1
| Line 181: | Line 181: | ||
=== Abstract === | === Abstract === | ||
The abstract of a document, like the document body, may be created by putting it between <code>\begin{abstract}</code> and <code>\end{abstract}</code>. For example, the LaTeX version of | The abstract of a document, like the document body, may be created by putting it between <code>\begin{abstract}</code> and <code>\end{abstract}</code>. 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: | ||
<syntaxhighlight lang="latex"> | <syntaxhighlight lang="latex"> | ||
Revision as of 15:48, 25 November 2010
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:
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 title, which contains the title, author, and date of the document, can be inserted using the LaTeX command \maketitle. Also, 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 can be inserted via
\maketitle
A separate page for the title can be created using the titlepage environment:
\begin{titlepage}
\title{Turbulence Project}
\author{Charles Reid}
\date{\today}
\maketitle
\end{titlepage}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}
By default, the abstract has the title Abstract. However, this can be changed using
\renewcommand{\abstractname}{Executive Summary}
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 Type | Level Number |
| Part | -1 |
| Chapter | 0 |
| Section | 1 |
| Subsection | 2 |
| Subsubsection | 3 |
| Paragraph | 4 |
| Subparagraph | 5 |
The section's level number is important. To set the numbering depth for the document, the command to be used is:
\setcounter{secnumdepth}{N}
where N is in the "Level Number" column.
Likewise, to set the level of sections included in the table of contents, the command is:
\setcounter{tocdepth}{N}
Paragraphs
Paragraphs are blocks of text separated by an empty line. The first paragraph of a section will not be indented. All other paragraphs will be indented.
If you want to change the amount by which each paragraph is indented, use
\setlength{\parindent}{1cm}
(or any other value in valid units).
Other environments
Environments are denoted using \begin{environment} and \end{environment}.
The alignment of text can be changed using three environments:
\begin{flushleft}
The flushleft macro will cause the text to be left justified
(meaning LaTeX will align it to the left, and attempt to get
the text flush with the left and right margins).
\end{flushleft}
\begin{flushright}
The same thing with flushleft, except this makes the text right justified.
\end{flushright}
\begin{center}
This text will be center aligned.
\end{center}
The verbatim environment can also be used to include text that won't be interpreted by the compiler:
\begin{verbatim}
The verbatim environment
reproduces every
character you input,
including all s p a c e s!
It also does not interpret
Latex macros like \emph{this}.
\end{verbatim}
Additionally, multi-line comments can be included using the comment environment:
This would be some text.
\begin{comment}
And a very long comment
might go here.
This is more convenient than
putting a percent sign
in front of every single
line in the comment.
\end{comment}
More text would probably go here.
This requires the verbatim package, so you have to put this into your preamble:
\usepackage{verbatim}
Lists
Notes
Mathematics
Equations
Labels
Symbols
Brackets and parentheses
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.