L Tex Tutorial: University of Chicago Computer Science Instructional Laboratory (Maclab / Linux Lab)
L Tex Tutorial: University of Chicago Computer Science Instructional Laboratory (Maclab / Linux Lab)
L Tex Tutorial: University of Chicago Computer Science Instructional Laboratory (Maclab / Linux Lab)
ATEX Tutorial L
Introduction
A L TEX is a professional-quality typesetting program, written by the legendary Donald Knuth. A A L TEX is portable, light, secure, and free. L TEX is smart by default, but also allows for ne control of all aspects of your document.
A AL TEX document has two main parts: the preamble and the body.
2.1
Preamble
A The preamble is at the beginning of the L TEX le and includes commands that will eect how your content is displayed. A The rst line of your L TEX document will be the \documentclass command, followed by a list of options and the name of a style. A standard example is \documentclass[12pt]{article}
Between the curly brackets, put your document class. Your choices are article, report, book, and letter. Between the square brackets, put options, separated by commas. With the options, you can control things such as font size, paper size, and paper orientation. Here are the default options for the article document class: Category Default Body text point size 10pt Paper size 8.5x11 (use letterpaper) Orientation Print side Title page Columns Displayed equations Other Options 11pt, 12pt a4paper, a5paper, b5paper legalpaper, executivepaper Portrait landscape oneside Both sides/duplex (use twoside) Title area on page 1 (use notitlepage) Title page (use titlepage) onecolumn twocolumn Centered Flush left (use fleqn)
2.2
A Because L TEX is so lightweight, many options and functions are not included by default A (for example, mathematical fonts). You can tell your L TEX document to include special functionality by including packages.
After the \documentclass command, you can include some packages with the \usepackage command, followed by the name of your package in curly brackets. For instance, use \usepackage{amssymb} for the AMS math symbols. Most packages you will use are already installed on the computers in the lab (but you still have to use the \usepackage command in order to apply them to your document). If you need a package that is not already installed, download the appropriate .sty le and put it A where L TEX can nd it (a good place is your working directory). Download packages from http://ctan.org Some common packages you might want to use: color, lets you change the color of your text graphics, lets you include graphics A fullpage, to have smaller margins (L TEX has very large margins by default) setspace, to switch between single, double, and 1.5 spacing (more about this later)
2.3
Body
Put your content that you want to typeset between \begin{document} and \end{document} tags. Most things that you type in the body of your document are typeset and show up in your nal output document. Some exceptions: commands, spacing, special characters, comments. 2.3.1 Commands
Commands alter the formatting of your text in the nal output document. They are preceded by a single backslash. Some commands take arguments in curly brackets. We will discuss specic commands later. 2.3.2 Spacing
A Spacing in your L TEX source code does not correspond to spacing in the typeset nal product. For instance, if you see something like this in your text editor:
The
quick 2
brown
fox
the typeset version in your nal output document will look like this: The quick brown fox jumped over the lazy dog. For a paragraph break, use: a line or more of blank space in your source code. For a line break, use: \\ (this will give you a blank line in between two chunks of text) For a page break, put \newpage To skip space vertically, use: \smallskip , \medskip, \bigskip, or \vspace{length}. Replace length with a unit of measurement (see table below).
1 em of blank space), \enspace To skip a space horizontally, use \thinspace (which inserts 12 1 (which inserts 2 em), \quad (which inserts 1 em), or \hspace{length} (which inserts as much blank space as you specify). In math mode, you can also use \; and \,.
2.3.3 pt in mm cm ex em sp bp dd pc cc mu 2.3.4
Units of Measurement point: 72.27pt = 1in inch: 1in = 25.4mm millimeter: 1mm=2.845pt centimeter: 1cm = 10mm height of the letter x in the current font width of the letter M in the current font scaled point: 1sp = 65536pt big point (or PostScript point): 72bp = 1in didt point: 1dd=0.376mm pica: 1pc=12pt Cicero: 1cc=12dd math unit: 18mu = 1em Special Characters
A Some special characters are reserved by L TEX , and must be preceded by a backslash if you want them to show up in your document: &, $, #, %, ^, {, and }
The backslash is also a special character, and you have to type $\backslash$ to get one to appear in your document.
2.3.5
Comments
Every line preceded by a % sign is a comment and will not show up in your typeset document.
A Comments are good for writing little notes or explanations within your L TEX legood if you want someone else to read and understand the organization of your source code, or if you want to remember it yourself. Comments are also useful when writing papers; if you want to take out a paragraph but dont want to delete it entirely, just comment it out.
3
3.1
Maths
Environments
You can include math in-line (math mode), centered on a line by itself (math display mode), or centered on a new line with numbered equations (equation mode). 3.1.1 math mode
To include math in-line, surround the math with dollar-signs as delimiters. For example: $\exp(x) = \sum_{n = 0}^{\infty}\frac{x^n}{n!} = \lim_{n \rightarrow \infty} \left( 1 + \frac{x}{n}\right)^n$ This is the result: exp(x) = of your text. 3.1.2 math display mode
xn n=0 n!
= limn 1 +
x n . n
To put the math on a separate line, larger, and centered, use double dollar-signs as delimiters. This is the result of typesetting the same code as above(but with dierent delimiters):
exp(x) =
n=0
xn x = lim 1 + n n! n
Notice how the sum and limit behave dierently. 3.1.3 equation mode
To display one-line equations that will be numbered automatically, surround your math code by \begin{equation} and \end{equation}. You will get the following result: xn exp(x) = (1) n! n=0 4
If you use equation mode again later in your paper, it will pick up the numbering where it left o: x n exp(x) = lim 1 + (2) n n
3.1.4
For multi-line equations, use \begin{align} and \end{align}. In order to use this tag, you need to include the amsmath package. The following code \begin{align} \exp(x) & = \sum_{n = 0}^{\infty}\frac{x^n}{n!} \\ & = \lim_{n \rightarrow \infty} \left( 1 + \frac{x}{n}\right)^n \end{align} Produces this output
exp(x) =
n=0
xn n! 1+ x n
n
(3) (4)
= lim
Use & signs where you want your math to line up in a column. You can include as many &s as you want, but be sure to use the same number on each line. Also notice that align automatically numbers lines. For un-numbered lines, use align* instead.
3.2
Special Characters
Special mathy characters are inserted with a backslash and the name of the character. For instance, $\Omega$, $\alpha$ produces: , . For a comprehensive list of special characters, consult symbols-letters.pdf (which you can nd at http://www.ctan.org/tex-archive/info/symbols/comprehensive/symbols-letter.pdf). This document lists all the special symbols you could want, and the packages in which they are included.
3.3
Use the ^ and _ characters. In-line, $x_i^y$ produces xy i . If you want to force the super- and sub-scripts into the height of one line, use $x{}_i^y$ to get xy and sub-scripts by using curly i . You can also nest superr yk brackets. For instance, $x_{i_j}^{y_k^r}$ produces xij . As you saw above, in math display mode ($$), the super- and sub-scripts spread out in relationship to the main character when youre working with sums, products, integrals, and limits. If you want to force this positioning within a single line, use $\sum\limits_{i=1}^N$
N
to get
i=1
3.4
Delimiters
produces () [] {}
3.5
Roots: $\sqrt{4} + \sqrt[3]{x + y}$ gives Fractions: $\frac{1}{x+y}$ gives Choose: $x \choose y$ gives Atop: $x \atop y$ gives x . y
x y 1 . x+y
Tables
Sample code:
\begin{tabular}{ c | c c c } 6
& col1 & col2 & col3 \\ \hline row1 & 11 & 12 & 13\\ row2 & 21 & 22 & 23\\ $\vdots$ & & $\ddots$ & \\ \end{tabular}
col3 13 23 n3
Edit the arguments in the second set of curly brackets like so: each letter (l, c, or r) denotes a column aligned left, center, or right (respectively). A pipe () between columns creates a vertical line between them. Within the body of your table, separate columns with &, and end a row with \\. To include a horizontal line between rows, use \hline.
5
5.1
Lists
enumerate
Enumerate is numbered automatically, and you can nest enumerated lists up to four times.
A You can change the character sets L TEX uses to enumerate by including the following code in your preface: \renewcommand{\labelenumii}{\alph{enumi}}. Replace enumi with enumii for the second level, enumiii for the third, and enumiv for the fourth. Here, \alph produces lower-case letters; replace it with \Alph for upper-case, \arabic for regular numerals, \Roman for big Roman numerals, and \roman for little Roman numerals.
\item first thing. \begin{enumerate} \item another thing. \begin{enumerate} \item nesting. \begin{enumerate} \item nest up to four times! \end{enumerate} \end{enumerate} \item dont forget to end the nests, though. \end{enumerate} %\item second thing. \item third thing. \end{enumerate} Produces: 1. rst thing. (a) another thing. i. nesting. A. nest up to four times! (b) dont forget to end the nests, though. 2. third thing.
5.2
itemize
A For un-numbered lists; uses bullet points. You can change the bullet points L TEX uses by including the following command in your preface: \renewcommand{\labelitemi}{$\star$}. Replace \labelitemi with \labelitemii, \labelitemiii, and \labelitemiv . Replace $\star$ with basically any symbol you want (notice that $\star$ is in math mode).
5.3
description
Description is for giving short denitions or descriptions: \begin{description} \item[Newton] 18th century physicist. \item[Descartes] 18th century philosopher. \end{description} Newton 18th century physicist. See also, g newton. Descartes 18th century philosopher. See also, the Monty Python rhubarb tart song. 8
Paper Writing
A L TEX can do everything youre used to your WYSIWYG editor being able to do. Some of A these things, L TEX does more simply and cleanly (but some things are less intuitive).
6.1
Text Flow
Center with \begin{center} and \end{center}. Adjust line spacing by including \usepackage{setspace} . Then, within your document, use \doublespacing, \onehalfspacing, and \singlespacing. All text following your command will be spaced as specied, until a new line-spacing command is issued.
A L TEX includes a nice block-quote environment: \begin{quote} and \end{quote} This environment is not automatically single-spaced.
6.2
Organization
You might notice the wonderful, clean, and easy-to-follow organization of this document ;-) To start o dierent parts of your document, use: \chapter{Chapter Name} \section{Section Name} \subsection{Subsection Name} \subsubsection{Sub-subsection Name} \paragraph{Paragraph Name} \subparagraph{Sub-paragraph Name}
A L TEX automatically numbers the sections for you (so if you add or remove a section, you dont have to re-number anything by hand). Also notice that you dont have to begin and end the sections.
6.3
1
Footnotes
6.4
Font Sizes
font sizes are relative to the normal font size of your document. The point measurements below are normalized to a 10-point document. If you are writing, say, a 12-point document, then the large font size is 20% bigger (or 14.40 pt). \tiny tiny is 5 pt \scriptsize scriptsize is 7 pt \footnotesize footnotesize is 8pt \small small is 9pt \normalsize normalsize is 10pt \large large is 12pt \Large Large is 14pt \LARGE \huge
LARGE is 18pt
\Huge You can modify font size in two ways: surround the text to be modied by curly brackets, or use the tag without curly brackets (in which case it is applied until you next include a text-modifying tag).
6.5
Text Style
Bold \textbf{text} or \bf Underline \underline{text} Italic \textit{text} or \it Slanty \textsl{text} or \sl Small Caps \textsc{text} or \sc Emphasized \emph{text} or \em The \emph tag is handy; it makes things italic, unless youre already writing in italics, in which case it makes the words not-italic. Good for emphasizing words in (e.g.) a quote written in a foreign language. To switch between font families: Roman (normal) font \textrm{text} or \rm Sans-Serif \textsf{text} or \sf Typewriter \texttt{text} or \tt As with the font sizes, you can use these tags by surrounding the text to be modied by curly brackets. Alternatively, you can use the tags \bf (for bold), \sl (for slanty), \em (for emphasis), and \sc (for small caps), etc. These tags apply until you include a dierent font-modifying command.
10
If you dont know how to do something, as always, you are welcome to ask the MacLab A A tutors at the front desk (many of us know L TEX ). If youre using L TEX at home and run into trouble, an internet search for latex plus the thing you want to know how to do is almost always fruitful.
A Here are some personal favorite L TEX -related websites: A L TEX : A document preparation system http://www.latex-project.org/ (complete with ocial lion mascot)
Word Processors: Stupid an Inecient http://ricardo.ecn.wfu.edu/~cottrell/wp.html (particularly heavy-handed, but includes good information) The TeX showcase http://www.tug.org/texshowcase/ (some absurdly complicated, awesome functionality)
11