CSUMS, Monday, May. 18

Introduction to LaTeX.

Introduction

First, a note on text editing: although there is a LaTeX editor installed on all of the CSUMS computers, I think that the very best way to edit tex files (or text files of any type) is to use Vim. There is a wealth of online resources for this amazing text editor, as you can see here.

Exercise 0. A good way to get acquainted with vim is to edit your vimrc file to get coloring, spell-check, and other cool features to start up automatically when you load vim. You will need to create this file from scratch by typing vim .vimrc into the terminal, and then adding the lines you want. There is more information that you need on this process available here. I have a text copy of my own vimrc file for you to look at as well.

Basic typesetting in LaTeX

LaTeX is a program designed primarily for typesetting mathematical and scientific documents, and as such it is very well suited to handle symbols and mathematical notation. Although primarily used for writing papers and journal articles, it can also be used to create neat-looking presentations or even CV's. Unlike programs such as Microsoft Word or OpenOffice Writer, the tex file you create looks nothing like the final document. Instead, LaTeX allows an author to focus on content, and all of the formatting is done automatically. When writing a paper with LaTeX, you must create a source tex file, and then 'compile' this code into a pdf, ps, dvi, etc.. file. Although this means that using LaTeX requires a bit more technical expertise, with a short introduction it is very easy to learn.

Unlike text editors, you cannot just type words into a tex file and expect then to be typeset well. You need a few commands before the text, called the preamble, to tell the LaTeX compiler what to do. In the most basic case, this is just the following:

\documentclass[12pt]{article}
\begin{document}
...
All text goes here
...
\end{document}

Note. In LaTeX, all commands are preceded by the backslash \ symbol. Also, all comments are preceded by the ampersand %. These symbols let LaTeX know that you are not typing text that will appear in the final document.

In LaTeX, all normal words typed into the tex file are typeset in the usual way. However, new lines within the tex document do not correspond to new lines in the output. To start a new paragraph, skip a line.

When creating equations, there are two types of output mode. The display style is used for big and important equations, and is created with the command \begin{equation} ... \end{equation} in conjunction with math commands and symbols. For smaller, inline equations, simply surround any math text with dollar signs (i.e. $ ... $). Note that the characters typed in math mode will appear differently in the final document. For example, $a/b$ will not produce a nice-looking fraction; instead, you will need to type the 'fraction' command.

Example. The command \frac{a}{b} to create fractions, and the command \int to make an integral sign are two examples. Note that LaTeX labels equations automatically.

\begin{equation}
\int \frac{a+bx^2}{2y}
\end{equation}
$\int \frac{a+bx^2}{2y}$

For a complete list of math symbols, see the online references here.

Once you have created the tex file, you create the output using a latex compiler. To compile a document and view the results, type the following into the terminal.

latex sample.tex   or   pdflatex sample.tex

To view the results, type

xdvi sample.dvi   or   open sample.pdf , respectively.

Exercise 1. Reproduce this pdf file. Here is a skeleton tex file to get you started.

Packages

For more advanced typesetting, you will need to load packages. For example, to print cool-looking website addresses in LaTeX, we need to load the url package. All packages are loaded using the usepackage command.

Example. The usepackage goes anywhere before the \begin{document}, and after the documentclass commands.

\usepackage{url}
...
Other code here
...
\url{http://math.asu.edu/CSUMS}

Note. You can load many packages at once with the usepackage command, by separating them with a comma. For example:
\usepackage{graphicx,amssymb,amsmath,verbatim,url}

Exercise 2. Reproduce this file. To figure out what packages you will need, use Google, or the references here.

Figures and Tables

Another important aspect of LaTeX is the addition of tables and figures to your document. Pictures and images are added using the includegraphics command, which requires the graphicx package.

Example. The includegraphics command takes one argument which gives the location of the picture, and several optional arguments to set height, width, etc. Note that the image is placed in line with the text unless a line is skipped.

Figure below.

\includegraphics[height=2in]{./images/sample_im_ben.jpg}
Figure to the left.
Note. The type of image that can be included (jpg, pdf, png, ps, etc.) depends on the LaTeX compiler that you are using.

For more important or interesting things such as tables, lists, or figures with captions, you will need to use one of the LaTeX environments. Environments are used with the begin ... end command. For more information about the many LaTeX environments, see this list.

Example. The itemize environment is used to create non-numbered lists. New items are added to the list with the \item command.

\begin{itemize}
\item Item A
\item Item B
\item ???
\item Profit
\end{itemize}

Exercise 3. Reproduce this file. Here are the images: [1] [2] [3] [4].

Writing Papers

Ultimately, the goal is to use the information above to create official-looking articles. In order to do this, there are a few commands, such as title, author, and maketitle that you will use often.

Example. The footnote command is also fun.

I want a footnote here
\footnote{Footnote text goes here}
Bottom of page

Exercise 4. Write up a short (3-5 sentence) abstract that outlines the research you hope to be working on over the summer, and a prospective title. Of course, you are in no way bound to this, but I personally have found it very helpful to keep a running abstract that describes the work I am doing. This way, when you need to submit a summary of you research, you will be prepared. I have a template here.

Created in 2009 by Taylor Hines. Not for general distribution; some of this content is borrowed from other sources.