A Brief Introduction to

L^{A}TEX

Created for 15-251: Great Theoretical Ideas in Computer Science

Patrick Riley January 2000

L^{A}TEX?

What is it?

• A system to produce beautiful typeset documents

• Converts a plain text file to postscript Why should I use it?

• Easiest and best way to typeset equations (much faster than MS equation editor)

• By far, the most commonly used document system in computer science research

• It’s pretty

• Cross-platform

• Extensible

• Number figures, equations, etc. automatically

A Few Things You Should Know

• There are two version of L^{A}TEX around: 2.09 and 2ϵ

• I’ll be teaching you 2ϵ (which is the newer of the 2)

• L^{A}TEX is based on another program called TEX, which is a much more low-level formatting language

How do I use LaTeX?

(This is the process for andrew UNIX systems)

1. Create a latex document with your favorite text editor. (Use a .tex extension)

2. Convert your .tex to a .dvi file with the command 'latex soup.tex' This will create a soup.dvi file. (note that in CS, you have

to use latex2e)

3. Preview the dvi file by using the command

'xdvi soup.dvi'

4. When it’s all done, convert the dvi to postscript

with the command 'dvips -o soup.ps soup.dvi'

5. Print out the soup.ps file using print or lpr

6. (or just Print from the dvi with

'dvips -Pprintername soup.dvi')

What does it look like?

• Plain text file

• \command used for commands

• \command{arg} for commands with arguments

• \begin{name} and \end{name} pairs

• $x=y$ is used for math mode (more on this later)

• blank lines for paragraphs

• all whitespace is the same (except for blank lines)

An Example Document

\documentclass{article}
\usepackage{fullpage}
\input macros.tex
% This is a comment
% load other packages as necessary
\usepackage{amssymb}
\usepackage{proof}
\title{CS 15-814 Type Systems for PL}
\author{Patrick Riley}
\date{September 23, 1999}
%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%
\maketitle
\section{$T_n$ Inductive Definition}

We will prove that
$\mathcal{T}_n \subseteq \mathcal{T}_{n+1}$ by
induction on $n$.
\begin{enumerate}
  \item Base Case $n=0$:
     $\mathcal{T}_0 = \emptyset$
  \item Inductive Step:
\end{enumerate}
\end{document}

An Example Run of L^{A}TEX

gs231:~/latex-test % latex hw1.tex
This is TeX, Version 3.1415 (C version 6.1)
(hw1.tex
LaTeX2e <1995/12/01> patch level 2
(/usr/local/lib/texmf/tex/latex2e/base/article.cls
Document Class: article 1995/12/20 v1.3q Standard LaTeX document class
(/usr/local/lib/texmf/tex/latex2e/base/size10.clo))
(/usr/local/lib/texmf/tex/contrib/fullpage.sty
Style Option FULLPAGE Version 2 as of 15 Dec 1988
) (/usr/local/lib/texmf/tex/latex2e/base/latexsym.sty)
(/afs/cs.cmu.edu/user/pfr/tex/macros.tex) (/afs/cs.cmu.edu/user/pfr/tex/pl.tex
(/usr/local/lib/texmf/tex/latex2e/amslatex/inputs/amsmath.sty
(/usr/local/lib/texmf/tex/latex2e/amslatex/inputs/amstext.sty
(/usr/local/lib/texmf/tex/latex2e/amslatex/inputs/amsgen.sty))
(/usr/local/lib/texmf/tex/latex2e/amslatex/inputs/amsbsy.sty)
(/usr/local/lib/texmf/tex/latex2e/amslatex/inputs/amsopn.sty)))
(/afs/cs.cmu.edu/project/prodigy-1/pstone/tex/amssymb.sty
(/afs/cs.cmu.edu/project/prodigy-1/pstone/tex/amsfonts.sty))
(/afs/cs.cmu.edu/user/pfr/tex/proof.sty)
No file hw1.aux.
(/usr/local/lib/texmf/tex/latex2e/base/Ulasy.fd)
(/usr/local/lib/texmf/tex/latex2e/base/Umsa.fd)
(/usr/local/lib/texmf/tex/latex2e/base/Umsb.fd) [1] (hw1.aux) )
Output written on hw1.dvi (1 page, 860 bytes).
Transcript written on hw1.log.

An Example Output Basic Nuts and Bolts (and stuff you need to know)

• Line breaks can be anywhere (L^{A}TEX makes it look nice anyway)

• A blank line makes a new paragraph

• Several kinds of quotation marks

Type this to get this

   '  ’
   `  ‘
   ''  ”
   ``  “

• There are ten “special characters” that are not handled as basic characters:

  # $ % & _{ } ~ ^\

• The first seven you can get by using \#, \$, etc.

• The ‘%’ character makes the rest of the line a comment

Basic Stuff Example- The Source

Line breaks
do
not matter
Blank lines
do.
``Quote'' `quote'
The next part will be gone
because %it's a comment
\# \$ \% \& \  \{ \}

Basic Stuff Example- The Result

Line breaks do not matter Blank lines do. “Quote” ‘quote’ The next part will be gone because # $ % & { }

Bigger and More Exciting Bolts and Nuts

• Text markup commands

 – \emph{test}: test
 – \textbf{test}: test
 – \textit{test}: test

• use $x=y$ to write math stuff in text (x = y instead of x=y) (much more math stuff to follow)

• \section{Name} can be used to start a new section. Automatic numbering and such makes this a good thing.

• ‘~’ is the same as a space, except that it will never become a line break. Useful for

Dr.~Smith or Figure~7

More Bolts and Nuts Example - The Source

Make \emph{text}look \textbf{different}
in a \texttt{sentence}.
Don't use n, when you mean $n$.
$x>y$ looks better than x>y.
\section{I am a title}
Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table
6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6
Table 6 Table 6 Table 6 Table 6 Table 6
is not as good as
Table~9 Table~9 Table~9 Table~9 Table~9 Table~9 Table~9
Table~9 Table~9 Table~9 Table~9 Table~9 Table~9 Table~9
Table~9 Table~9 Table~9 Table~9 Table~9 Table~9 Table~9
Table~9 Table~9 Table~9

More Bolts and Nuts Example - The Output

Make text look different in a sentence.

Don’t use n, when you mean n. x > y looks better than x¿y.

1 I am a title

Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6 Table 6

is not as good as

Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9 Table 9

More stuff

• \begin{itemize}\end{itemize}to create bul-

leted lists (\item) creates the bullet.

– You have seen

– lots of these

• \begin{enumerate}\end{enumerate}to create

numbered lists (\item) creates the number.

1. When you need

2. numbers, you just

3. need numbers!

• \begin{verbatim}\end{verbatim}looks like typed

text and ignores L^{A}TEX commands:

One way to get $#%&~$ special characters!
\begin{itemize}
 \item I would have a bullet there
\end{itemize}

Everybody loves math!

For some of this, you need to put

\usepackage{amsmath} in the preamble.

• Symbols: There are lots of them, like

\Theta\infty\in\oplus:Θ∞ ∈ ⊕.

• Sub- and Superscript: Use _for subscript and ^for superscript (use {} for multiple characters)

 z^2 ⇒ z^{2} x_{14} ⇒ x_{14} w_n^{12} ⇒ w_{n}^{12}

• Sum and Products

\sum_{i=0}^n i       \prod_1^\infty x^2 y_3

n ; ∑ ; i=0 i  ∞ ; ∏ ; 1x^{2}y_{3}

• Fractions are made with \frac{num}{dem}

\frac\{abc\}\{d^2\} ⇒ \frac{abc}{d^{2}}

• Square Root. – You can use \sqrt{x} to get this: √x – \sqrt also takes an optional argument – optional arguments are in square brack-

ets before the regular arguments

– \sqrt[3]\{x\} produces \sqrt[3]{x}

Equations

• $$ is useful for math stuff in text, but what if you need a full separate line?

• The equation environment

This equation gets:
\begin{equation}
  \sum_i=1^n i = \frac{n(n+1)}{2}
  \label{eq:gauss}
\end{equation}
it's own line

This equation gets:

n ; ∑ ; i=1 i = \frac{n(n + 1)}{2}  (1)

it’s own line

Automatic Numbering

What was that \label stuff?

• L^{A}TEX will automatically number equations (and other things) for you

• \label{name} gives those numbers a name • \ref{name} allows you to retrieve that num-

ber

• Instead of saying equation~7, you should

  say equation~\ref{eq:gauss}

• That way, you can add or reorder equations and everything is still okay

• L^{A}TEX numbers many other things (like section and figures) that you can label and ref.

Other equation environments

There are lots of other equation-like environments. Here are two useful ones:

• gather environment puts multiple equations together, but on different lines. (Use \\ to start a new line)

\begin{gather}
  x+y+z  \geq 1 \\
  0      = x^2 - y^3 + z^{111}
\end{gather}

x + y + z ≥ 1  (2)
0 = x^{2} − y^{3} + z^{111}  (3)

• align environment is like gather, but allows you to align the different lines with &

\begin{align}
  x+y+z & \geq 1 \\
  0     & = x^2 - y^3 + z^{111}
\end{align}

x + y + z ≥ 1  (4)
0 = x^{2} − y^{3} + z^{111}  (5)

Math stuff for you to discover

I don’t have time to explain everything. Here are some more interesting mathematical things that L^{A}TEX can do.

• Array and matrix environments

• Delimiters (parentheses, braces, etc.)

• Over and under lines and braces

• Many other equation environments

What else can LaTeX do?

I’m not going to describe these here, but just to tempt you...

• Pictures (from .eps files or natively)

• Tables (with \begin{tabular}) You might need this, but it’s a little complicated to explain. Look in the books.

• Bibliography stuff

• Indexing

• Table of contents

• We just scratched the surface of the mathematics support

• Postscript tricks

Editors and Helpful Stuff for UNIX

I personally use • XEmacs

• AUXTEX: a special emacs mode that helps you write L^{A}TEX quickly and easily

• It should already be installed in the clusters • Try this for some pointers to more info:

  http://sunsite.auc.dk/auctex/

If you must have a WYSIWYG, try LyX. • (Warning, I’ve never used it, but I’ve heard)

• You can’t do everything that you can with regular L^{A}TEX

• It the end, you’ll be better off really knowing L^{A}TEX

Editors and Helpful Stuff for Windows

I’ve never used this, but many people do.

• There are latex distributions for Windows

• However, I would recommend using the unix clusters latex stuff because it’s already installed with lots of packages.

• WinEdt is an editor that provides some GUI support to help you along www.winedt.com

• (Cory has used it a bit)

Editors and Helpful Stuff for Macintosh

• (I’ve never done this)

• but I heard that there is a free port called OzTeX

On-Line Resources

• The L^{A}TEXproject homepage

  http://www.latex-project.org/

• CTAN Catalogue (all the packages you could

  ever need) ftp://ftp.duke.edu/tex-archive/
  help/Catalogue/catalogue.html
• for AuCTeX: http://sunsite.auc.dk/auctex/
• for WinEdt: www.winedt.com

• (See our web page for more useful stuff)

Books

This is a good introductory book (it’s how I learned):

• Lamport, Leslie. L^{A}TEX: A Document Preparation System (2nd Ed.). Addison-Wesley Publishing Corp, 1994.

This is essential if you really start using L^{A}TEX(it describes some of the most useful of the millions of packages available)

• Goossens, Michel and Frank Mittelbach and Alexander Samarin. The L^{A}TEX Companion. Addison-Wesley Publishing Corp, 1994.