L Tex: From Beginner To Texpert: 2 2 What Is L Tex? 3 3 How Does L Tex Work? 3 4 Getting L Tex 4
L Tex: From Beginner To Texpert: 2 2 What Is L Tex? 3 3 How Does L Tex Work? 3 4 Getting L Tex 4
Contents
1 Introduction
A 2 What is LTEX? A 3 How does LTEX work? A 4 Getting LTEX 4.1 On Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 On Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 On Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A 5 LTEX basics A 5.1 LTEX commands . . . 5.2 The preamble . . . . 5.3 The document body 5.4 Document structure
2 3 3 4 5 5 6 6 6 6 8 8 9 10 11 12 12 12 13
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
6 Environments 7 Modifying text styles 8 Packages 8.1 The graphicx package 8.2 The geometry package 8.3 The AMS packages . . 8.4 Other packages . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
9 Figures and tables 13 9.1 Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 9.2 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 10 Annotations 10.1 Footnotes and endnotes 10.2 Cross references . . . . . 10.3 Table of contents . . . . 10.4 Bibliography . . . . . . . 11 Inserting mathematics 11.1 Inline math . . . . . . . 11.2 Display math . . . . . 11.3 Equation . . . . . . . . 11.4 Align . . . . . . . . . . 11.5 Mathematical notation 12 For further reference 16 16 16 16 17 17 17 18 18 18 19 21
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
1 Introduction
A This document introduces the LTEX typesetting system. After digesting the information below, youll be able to: A Download and install LTEX on your PC or Mac A Create basic documents using LTEX A Install new LTEX packages A Insert tables and gures into a LTEX document A Use LTEXs cross-referencing, footnote and basic bibliography features A Insert equations into a LTEX document
These topics cover the majority of tasks that most people need to do when A writing a document. However, please note that while the LTEX system makes it very easy to create professional-looking documents, it is both comprehensive and extensible. There are many topics that are not covered by this basic tutorial. 2
A Fortunately, LTEX is very well documented. If you come across something that you cant gure out how to do, ask your old friend Google for help.
A 2 What is LTEX?
A At its core, LTEX is a typesetting system that allows authors to create highly polished documents without having to worry about formatting, page breaks, object positioning, or any other style concerns that distract them from focusing A on writing. LTEX is pronounced lay-tech, as it is an extension of TEX (tech), the original typesetting system. You can read all about the history of TEX and A LTEX on Wikipedia. A LTEX is used widely in a variety of professions. Mathematicians, physicists, economists, statisticians and other academics and professionals that regularly A use mathematical notation in their documents often use LTEX because of the ease with which it handles such notation. Many publishers use TEX-based systems for typesetting documents.
Test Document
Your Name April 21, 2006
This is a test document.
A LTEX is designed to create the same output on any system. As a result, if A you distributed the above text to anyone with a working LTEX distribution, reA gardless of their particular system, they would get the exact same result. LTEX outputs compiled documents in several formats, but the most popular is PDF.
A 4 Getting LTEX
A A All you technically need to create LTEX documents is a LTEX engine the binary les and libraries that will convert plain text .tex les to polished PDF les. A LTEX can be run from the command line, so Linux and DOS acionados will A feel right at home. However, using a frontend for LTEX can make things much easier. Most frontends are essentially text editors with functions to A Compile documents with LTEX without using the command line A Facilitate writing in the LTEX language (wizards for table creation, syntax highlighting, code completion, etc.) A In this document, I assume that youll use both a LTEX engine and a frontend. There are many engines and frontends to choose from on every operating system. Im going to describe how to install the most popular (and easy to
A install) open-source tools for Windows and Mac OS X. Other LTEX tools have different conguration requirements and operating instructions, but almost every working environment involves (i) editing raw tex les using a frontend and (ii) A compiling the LTEX document to a PDF, generally using buttons or menu commands in the frontend rather than the command line.
4.1 On Windows
Engine MikTeX is a popular open-source distribution. To install, visit http: //www.miktex.org, download the executable, and follow the dialog. Additional installation instructions are on the download page. Frontend TeXnic Center, available from http://toolscenter.org, is an opensource frontend with many helpful features. Installation is standard, just download and open the executable, which opens a wizard. TeXnic center is automatically congured to work with MikTeX. To test out your setup, save the sample document above as a tex le using TeXnic Center and select Build Current file. If everything is set up properly, a new PDF le (along with a log le) will be created in the directory where your document is saved.
4.2 On Mac OS X
A Engine gwTeX is a free and open-source LTEX distribution for OS X that comes with a graphical installer. To install, download the i-Installer application, select a mirror, then select the TeX package. Additional installation instructions are available at http://ii2.sourceforge.net/tex-index.html. Once installation is complete, all you need is a frontend.
Frontend TeXShop (http://www.uoregon.edu/~koch/texshop/) is a very A popular LTEX frontend for OS X. Installation requires a simple drag and drop to the /Applications folder. TeXShop is automatically congured to work with gwTeX, so if thats the engine that youre using, youre set. To test out your distribution, try saving the sample document above as a A tex le and running LTEX on your document by pressing command-t. If everything is congured properly, a window will appear similar to the example
output above, and a new PDF le (as well as a log le) will appear in the directory where your le is saved.
4.3 On Linux
Different Linux systems have their own application management utilities (aptget or rpm, for example), and installation will depend on your particular Linux distribution. Ubuntu users can use the Synaptic Package Manager. Kile is a popular and easy-to-use frontend that works with both KDE and Gnome. A 5 LTEX basics
A 5.1 LTEX commands
A LTEX commands generally begin with a backslash and take the form:
\command[options]{argument}
For example,
\section{Introduction}
would dene a new section, named Introduction. The % character denes a comment, and everything from that character to the end of the line is comA mented out and will be ignored by LTEX. To insert the % character into a document, escape it with a backslash: \%. To insert a backslash, use $\backslash$. This is true of other characters as well; use \& to produce &, \$ to produce $, \# to produce #, \_ to produce _ and \{ to produce {. A Quotes work a bit differently in LTEX. To insert quote marks, use the form ``text''. That is, the ` character (top left of the keyboard) twice, followed by the single quote character, ', twice.
\documentclass[11pt,twocolumn]{article}
would organize body of the document into two columns. Note that options are separated by a comma. Other options include: oneside or twoside: change the margins for a one or two-sided document landscape: change the document from portrait to landscape titlepage or notitlepage: dene whether there is a separate title page, or if the title, author and date are presented at the top of the article There are document classes other than article. The book class, for example, is useful for writing books. By installing the beamer package, you can use the A beamer document class to make impressive presentations in LTEX. For information on other document classes, consult Google. 7
\section{Name} \subsection{Name} \subsubsection{Name} \paragraph{Name} To insert an unnumbered section, use the command \section*{Name}. The section numbering will continue as normal with the next section, subsection, etc. The \paragraph{} command doesnt need to be included unless you want to insert a heading for a paragraph. The image below shows the different structure commands in use:
Section command
Section command
2.1
Subsection command
6 Environments
Environments are special blocks of text. For example, the itemize and enumerate environments create bulleted and numbered lists, respectively. The following markup:
\begin{itemize} \item First thing \item Second thing \item Third thing \end{itemize} \begin{enumerate} \item First numbered thing \item Second numbered thing \end{enumerate}
would produce a bulleted list followed by a numbered list. Note that environments always begin with \begin{environmentname} and end with \end{environmentname}. They can be nested, so one item of a bulleted list might contain another bulleted list, or a numbered list, etc. Other frequently used environments include: 9
1
Quote \begin{quote}...\end{quote} creates a section of indented, quoted text Verbatim \begin{verbatim} ... \end{verbatim} is similar to <pre> in HTML. In the verbatim environment, text is printed in a monospace font and special characters (such as \ and %) are ignored. Verbatim is useful for typing code tips Description Description lists are similar to bulleted lists, with a bold item name followed by a description:
\begin{description} \item[First item] Description of item \item[Second item] Description of item \end{description}
This list is presented using the description environment; the code samples in this document are presented using the verbatim environment.
To insert bold text, use \textbf{text here} To insert italic text, use \emph{text here} To insert monospace text, use \texttt{text here} To use verbatim text within a sentence, use \verb|your text here|. Note that any delimiter can be used, for example \verb+your text here+ will produce the same result To center a line, you can use
10
8 Packages
A Packages extend LTEXs functionality. Package installation essentially consists of two steps (after downloading the package, that is): A 1. Running LTEX on the ins le to produce sty or cls les
2. Copying the newly created les to an appropriate directory and updating A the LTEX database However, there are exceptions. The letypes sty and cls stand for style and class, respectively. If a package does not come as an ins le, but rather a sty or A cls le, it does not need to be processed with LTEX, and you can skip directly AT X on an ins le usually produces a dtx le. This to step two. Also, running L E A le can be processed with LTEX to create a manual for the package.
A Note To process a package le (ins or dtx) with LTEX, just open that le with your frontend and process it like you would a normal tex le. A Hopefully, youll never need to do any of this. Most LTEX distributions include automatic, graphical methods for nding and installing packages (including gwTeX and MikTeX).
Windows The easiest way to install a package on a PC using MikTeX is to use the MikTeX package manager, which is available through the Start Menu. Just open the package manager, select a mirror (the location from which you will download les), and navigate to the package that you want to install. MikTeX will take care of the rest. Another nice feature of MikTeX is that if you are processing a tex le that requires a package that isnt installed on your machine, it will prompt you to download it. OS X Launch i-Installer to browse through the available packages. Almost every popular package is installed by default with gwTeX, so you may never need to do this. To install a package on your Mac that isnt available using i-Installer, process the les as described above, and move the cls, sty and other les to /Library/texmf. If this directory does not exist, create it. Next, I discuss some popular packages. These packages are already installed with gwTeX and MikTeX, so there is no need to download and install them. 11
\includegraphics[options]{filename.png}
The graphicx package supports many letypes, including PDF, PNG and JPG. The options include: width=Xin height=Xin scale=X (where x is between 0 and 1) You can also use, for example, the command width=.8\textwidth to scale a picture to 80% of the width of your text. If you only use, say, the width option, the height will be scaled proportionally; if you want to skew your image, you need to specify both the height and width.
\usepackage[margin=1in]{geometry}
in your documents preamble.
\usepackage{amsthm,amsmath,amsfonts}
12
in the preamble of your document. The amsthm package allows you to include Theorems, Propositions, Proofs, etc. in your document. The amsfonts packA age includes symbols that are not available in standard LTEXsuch as R (blackboard bold)which I inserted using the command $\mathbb{R}$. The amsmath package includes several environments and commands for displaying mathematics. These commands, which are introduced in a later section, make certain mathematical constructs much easier to typeset.2
9.1 Figures
To insert a gure, use
13
\includegraphics{...} species the location of the le that is being inserted as a gure \label{your-reference-key} is a label that you can use to refer to the gure in the text. For example, if you label your gure g1 then you can reference it later on by typing \ref{fig1}
9.2 Tables
A A oated table in LTEX consists of two environments: table, the actual oated entity in the text, and tabular, the data contained in the table. For example,
\begin{table}[hbtp] \caption{This table is an example} \begin{center} \begin{tabular}{c|cc} First row, first column & First row second column & First row, third column \\ \hline Second row, first column & Second row, second column &
14
Second row, third column \\ Third row, first column & Third row, second column & Third row, third column \\ \multicolumn{3}{c}{...} \end{tabular} \end{center} \label{exampletable} \end{table}
would produce Table 1. Table 1: This table is an example
First row, rst column Second row, rst column Third row, rst column
First row second column Second row, second column Third row, second column ...
First row, third column Second row, third column Third row, third column
Everything except the code between \begin{tabular} ... \end{tabular} is the same as the gure environment described above. Heres how the tabular environment works:
A \begin{tabular}{c|cc} tells LTEX to start a new tabular environment A with three centered columns. The bar (|) after the rst c, tells LTEX that the rst column has a vertical border. Using {lcrr} would create four columns, the rst left aligned, the second centered, and the third and fourth right aligned
Table cells are separated by & and table rows are separated by \\ \hline creates a horizontal line \multicolumn{3}{c}{Text here} creates a row that spans all three columns, is centered, and contains the text Text here
15
There are more complicated options for creating and inserting tables, but the rules above cover the commands needed to create most basic to intermediate tables.4
10 Annotations
A LTEX is capable of automatically creating important annotations, such as footnotes, cross references, tables of contents and bibliographies. Note that, since A the following commands require LTEX to automatically number text elements, AT X must be run on your document twice for proper display. L E
\usepackage{endnote}
and use the command \endnote{Text} to create new endnotes. At the point in your document where you want the endnotes to appear, simply type \theendnotes.
16
10.4 Bibliography
To create a bibliography, insert a list of the citations at the end of your document, using the form:
\begin{thebibliography}{99} ... \bibitem{key1} Gardner, John. 2006. ``\LaTeX{}: from beginner to \TeX pert.'' \emph{Dataninja}. Available online at \texttt{http://generaldisarray.wordpress.com}. ... \end{thebibliography}
You must manually type the bibliography entries. To refer to an item within A the text, use \cite{key}[1]. The {99} tells LTEX that there a maximum of 99 AT X needs to know this so it can correctly justify entries in the bibliography. L E the bibliography entries with their numbering on the left. A more efcient way to create bibliographies is to use BibTeX, which allows you to maintain a database of citations and call them as needed in your bibliography. There are also graphical tools for managing your reference databases, so you dont have to hard code the citations, and can easily change them to different formats. However, BibTeX is too complicated to explain in this document. For an introduction, see http://bibtex.org.6
11 Inserting mathematics
A There are several ways to include mathematical notation in LTEX documents.
To insert references that look like Author (2008) or (Author 2008), use the natbib package.
17
\[ \]
a^2+b^2=c^2
would create a paragraph break and center the equation on the page, like this: a2 + b2 = c 2.
11.3 Equation
The equation environment can be used to place numbered equations in the text. For example,
11.4 Align
The align environment allows you to align parts of equations at the equal sign. For example,
Notes You must have invoke the amsmath package in order to use the align environment. Also, it is possible to suppress the numbering by using the commands \begin{align*} and \end{align*}. Labeling works the same for the align and equation environments. A shortcut to referencing an equation is the command \eqref{label}. For example, \eqref{myeqn} produces (1).
Indexing and exponents Subscripts are denoted using the underscore (x_i) and superscripts use the ^ key (a^2). To type i j ,k you need to write i_{j,k} A to tell LTEX that the j,k comprises the entire subscript. The bracket characters A are generic grouping operators in LTEX, and they wont appear in your document. Some operators \sum{1/x} produces 1/x and \sum_{i=1}^{\infty}{x_i} produces x i . Other operators include \prod ( ), \int ( ), \sin, \log, i =1 \arg, \max (combine them as \arg\max_x f(x) to get arg maxx f (x)), \lim, \sqrt, etc. To produce, for example, a cube root, use the command \sqrt[3]{x} A ( 3 x). Note that, for operators, LTEX automatically chooses the appropriate location for arguments and subscripts. For example, if \int_0^1 f(x) dx is in1 line, it looks like 0 f (x)d x, whereas if it is displayed math, it looks like
1
f (x)d x.
0
19
Decorations \hat{x} puts a hat over x (x), as does \hat x (use the former if there are multiple characters under the hat). Similarly, \tilde{x} produces x, \bar{x} produces x, \underline{x} produces x, \vec x produces x, etc. You can use the \overset and \underset commands to place labels over symbols. For example, x\overset{p}{\rightarrow}b produces x b.
a Fractions Use \frac{a}{b} to display ( b ). p
Brackets For brackets use (, [ or \{ and \} for { and }. However, if you need stretched brackets, use \left(...\right) or \left\{ <math here> \right\}. For example,
Once again, you must invoke the amsmath package The code shown above would produce: a b c . . .. . . . . . . . . . d e f Other matrix types include pmatrix for a matrix with parenthetical brackets and cases to dene, for example, a piecewise function. Notice, in the above, the various dots commands. Another useful one is \ldots which inserts an elipsis . . . The reason for the command, rather than simply typing three periods, A is that LTEX precisely controls the spacing of the elipsis according typographical standards. 20
Other tips To insert a space within an equation, use \quad for a space the width of an M or \qquad for twice that much space. To put some ordinary text within a math environment, use \text{}. For example:
y_i=\alpha+\beta x_i+\varepsilon_i \qquad e_i \sim N(0,\sigma^2) \quad \text{A basic line}
would produce: y i = + x i + i e i N (0, 2 ) A basic line
For help with other symbols and operators, see the American Mathematical A Societys Short Math Guide for LTEX.7
References
A [1] Gardner, John. 2006. LTEX: from beginner to TEXpert. Dataninja. Available online at http://dataninja.wordpress.com. A [2] Indian TEX Users Group. 2003. LTEX Tutorials: A primer. Available online at http://sarovar.org/frs/download.php/120/ltxprimer-1. 0.pdf.
ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf.
21