From charlesreid1

Line 562: Line 562:
{{Ambox
{{Ambox
|text=Personal Tex files should be stored in ~/Library/texmf. (Recall that ~/Library is the library folder in your home directory, while /Library is a system folder analogous to /Applications.) You will have to create the subfolder "texmf." When TeX needs to open a file, it searches ~/Library/texmf first, so if you modify a standard TeX file and place it there, the modified file will be used.
|text=Personal Tex files should be stored in ~/Library/texmf. (Recall that ~/Library is the library folder in your home directory, while /Library is a system folder analogous to /Applications.) You will have to create the subfolder "texmf." When TeX needs to open a file, it searches ~/Library/texmf first, so if you modify a standard TeX file and place it there, the modified file will be used.


The folder structure inside ~/Library/texmf should mimic that of the texmf trees in your TeX distribution. This is easier than it appears. TeX will locate any file in ~/Library/texmf/tex or in a subfolder of this folder; LaTeX will locate any file in ~/Library/texmf/tex/latex or a subfolder of this folder. Bibtex will locate any file in ~/Library/texmf/bibtex/bib or in a subfolder of this folder. Etc.
The folder structure inside ~/Library/texmf should mimic that of the texmf trees in your TeX distribution. This is easier than it appears. TeX will locate any file in ~/Library/texmf/tex or in a subfolder of this folder; LaTeX will locate any file in ~/Library/texmf/tex/latex or a subfolder of this folder. Bibtex will locate any file in ~/Library/texmf/bibtex/bib or in a subfolder of this folder. Etc.

Revision as of 21:56, 19 April 2011

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

The right margin is the remaining space left after the left margin and page width are specified.

$ \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}
LatexAbstract.png

By default, the abstract has the title Abstract. However, this can be changed using

\renewcommand{\abstractname}{Executive Summary}

LatexAbstract2.png

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

Latex has lots of different types of lists.

Bullet lists:

\begin{itemize}
\item First
\item Second
\item Third
\item Fourth
\end{itemize}

Numbered lists:

\begin{enumerate
\item First
\item Second
\item Third
\item Fourth
\end{enumerate}

Description/definition lists:

\begin{description}
  \item[First] Description of first
  \item[Second] Description of second
  \item[Third] Description of third
\end{description}

Customizing enumerated lists:

http://en.wikibooks.org/wiki/LaTeX/Formatting#List_Structures

Notes

Footnotes

Footnotes can be made using the \footnote macro.

This is some text.\footnote{This is a footnote.}

Footnotes can be enumerated using numbers, letters, or symbols. The following code goes in the preamble, and sets the footnote enumeration.

Latex code Enumeration
\renewcommand{\thefootnote}{\arabic{footnote}}
Arabic numbers (1,2,3,...)
\renewcommand{\thefootnote}{\roman{footnote}}
Lowercase Roman numerals
\renewcommand{\thefootnote}{\Roman{footnote}}
Uppercase Roman numerals
\renewcommand{\thefootnote}{\alph{footnote}}
Lowercase letters
\renewcommand{\thefootnote}{\Alph{footnote}}
Uppercase letters
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
Series of 9 symbols

Mathematics

Equations

Labels

Symbols

Brackets and parentheses

Packages

Installing LaTeX Packages

The following instructions are not very helpful: http://en.wikibooks.org/wiki/LaTeX/Packages/Installing_Extra_Packages

Installing LaTeX Packages on Mac

I use MacTex.

From the following webpage: http://pages.uoregon.edu/koch/texshop/whereisstuff.html

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.

References