Abstract: LaTeX is a cool type setting system that many use especially when generating documents that contain fancy formulas and mathematical/Greek symbols. Many use this program when writing the thesis/dissertation and when giving presentations. Many journals require authors to use the LaTeX format when submitting articles. Also, many instructors and TAs find it convenient to use LaTeX to create handouts, lecture notes, and of course, those notorious examinations. It is a very versatile program and a useful tool for both master's and doctoral students. This talk will start from scratch and give a very basic introduction to using LaTeX and some of its most useful features.
LaTeX (pronounced "lay-tek" or "lah-tek") is a typesetting language. LaTeX was created for the purpose of typesetting text and mathematical formulas.
LaTeX is not a word processing program. Unlike programs like MS Word where your document is produced "on the fly" through a "What You See Is What You Get" format, LaTeX files need to be processed or compiled first before the final product can be viewed.
Useful in typesetting:LaTeX is freely available. On our UNIX system LaTeX will automatically be found. For those interested in downloading LaTeX on a PC, visit this link. At this link you will find information on MikTeX, which is one of the more popular implementations used on the PC. Once the LaTeX "engine" (like MikTeX) is installed, you will find it useful to use a program that conveniently links the steps of editing, compiling, and viewing your LaTeX file. One such program which is freely available is Crimson Editor.
For the remainder of this presentation, we will focus on using our UNIX system to create a LaTeX document. Once you understand the main principles of creating a LaTeX file in UNIX, you will have no troubles creating files on the PC environment.
In an Xterm window type:
> add tetex [RETURN]
This will give you access to the LaTeX related commands we will need. You will need to issue this command whenever you start a new Xterm session.
For the purposes of this presentation, let us create a subdirectory (called latex) in your UNIX account where we will store our example LaTeX files.
In the same Xterm window used above type:
> cd [RETURN]
> mkdir latex [RETURN]
> cd latex [RETURN]
When creating a LaTeX document, cycle through these steps:
Implementation in UNIX
> nedit myfile.tex & [RETURN]
Notice the ampersand (&) at the end of the command. This will keep the Xterm window free for future use. This will be the one and only time the xdvi command needs to be issued.
> latex myfile.tex [RETURN]
This will create a device independent (.dvi) file.
> xdvi myfile.dvi & [RETURN]
Notice again the use of the ampersand (&).
Our First Example
Click on the LaTeX template file link below and save it locally in your newly created latex subdirectory.
Once it has been saved, follow steps 1 through 4 as stated above to compile and view your sample LaTeX document.
The overall form of a typical LaTeX file will look like the following:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sample LaTeX Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12pt]{article}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The Preamble
\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{-0.25in}
\setlength{\topmargin}{-0.75in}
\setlength{\headheight}{0.20in}
\setlength{\headsep}{3ex}
\setlength{\parskip}{2.3ex}
\setlength{\parindent}{0.0in}
\setlength{\baselineskip}{2ex}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.8in}
% The Preamble
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
% Body of the document
\end{document}
|
As with any computing language (like HTML) LaTeX has its own set of key words and language structure. However, unlike some languages, LaTeX is case sensitive. Most commands in LaTeX begin with the backslash (\).
Emphasizing Text, Other Fonts, and Font Sizes
Three basic ways to emphasize text is have it appear with an underline, in italics, or in bold. Here are the commands to implement this in LaTeX:
LaTeX Code |
Final Output |
| \underline{a string of text} | a string of text |
| \emph{a string of text} | a string of text |
| \textbf{a string of text} | a string of text |
Here are commands to generate other fonts and font sizes. By adding other packages, you can have access to many more fonts.
Math Symbols
When using math related keywords, it is necessary to specify the math environment. For example, if you wanted to express the sum of the Greek lower case letters alpha, beta, and gamma, you can type any of the following:
\begin{math}
\alpha + \beta + \gamma
\end{math}
|
\( \alpha + \beta + \gamma \)
|
\[ \alpha + \beta + \gamma \]
|
$\alpha + \beta + \gamma$
|
Here is a compilation of keywords to generate some other symbols. Note that some of the symbols require the use of certain packages.
Some examples of math related expressions:
LaTeX Code |
Final Output |
| $x_{1}, x_{2}, x_{3}$ | x1, x2, x3 (subscript) |
| $y^{1}, y^{2}, y^{3}$ | y1, y2, y3 (superscript) |
| $\sqrt{x+y}$ | (square root of x+y) |
| $\frac{a}{b}$ | (fraction of the form a over b) |
| $\int_{0}^{\infty} f(x) dx$ | (integral of f(x), limits from 0 to infinity) |
| $\sum_{i=1}^{\infty} x_{i}$ | (infinite sum of xi using Sigma notation) |
Other Environments
Aside from the math environment, there are many other environments in LaTeX that allow the user to create useful features such as tables, lists, equations, and so on.
Building a table
Suppose we would like to create the following table in LaTeX where each column is right justified.
| Regression | beta0 | beta1 |
| Estimate | 2.145 | 14.642 |
| SD | 1.451 | 4.395 |
\begin{tabular}{|r|r|r|}
\hline
Regression & $\beta_{0}$ & $\beta_{1}$ \\ \hline
Estimate & 2.145 & 14.642 \\ \hline
SD & 1.451 & 4.395 \\ \hline
\end{tabular}
|
Building a list
Suppose we would like to create the following list in LaTeX where each item is bulleted.
My Grocery List
|
\underline{My Grocery List}
\begin{itemize}
\item Eggs
\item Butter
\item Bacon
\item Pasta
\end{itemize}
|
If the items of the list should be enumerated, use:
\underline{My Grocery List}
\begin{enumerate}
\item Eggs
\item Butter
\item Bacon
\item Pasta
\end{enumerate}
|
Making equations
When typesetting equations, it is often desirable to align a set of equations in a particular way. For example, when expanding an expression to equivalent forms, we usually align the equivalent forms in the same column. For example, consider the following expansion:
| (x + y)3 | = | (x + y)(x + y)(x + y) | = | (x2 + 2xy + y2)(x + y) | = | x3 + 2x2y + xy2 + x2y + 2xy2 + y3 | = | x3 + 3x2y + 3xy2 + y3 |
We can create this same alignment of equations with the following:
\begin{eqnarray}
& & (x+y)^3 \\
& = & (x+y)(x+y)(x+y) \\
& = & (x^2 + 2xy + y^2)(x+y) \\
& = & x^3 + 2x^2 y + xy^2 + x^2 y + 2xy^2 + y^3 \\
& = & x^3 + 3x^2 y + 3xy^2 + y^3
\end{eqnarray}
|
The eqnarray environment is just like a tabular environment where it has exactly 3 columns. Note, however, that within this environment the math mode is already in effect (no need to surround expressions with $...$). Once compiled, each line will automatically be numbered by LaTeX. To suppress the numbering scheme, use instead \begin{eqnarray*} ... \end{eqnarray*}
Suppose in your LaTeX document you know you will be making many references to the exact form of the pdf of the normal distribution which, in LaTeX code, looks like:
\frac{1}{\sqrt{2\pi}\sigma}e^{-(x-\mu)^2/(2\sigma^2)}
|
Even with a text editor that is capable of cutting/pasting, the repetitive act of placing this long code can become cumbersome. Instead, we can create a shortcut by defining a new keyword in the preamble to represent this complicated code. It would be wise to select a keyword that is not already used by LaTeX (let us use npdf to represent the normal pdf).
Somewhere in the preamble, we can place the following line:
\newcommand{\npdf}{\frac{1}{\sqrt{2\pi}\sigma}e^{-(x-\mu)^2/(2\sigma^2)}}
|
Then, anywhere in the midst of the body of the document, we can invoke this shortcut by simply typing \npdf (must be in math mode).
Importing Images (Postscript)
To import postscript images we need to use a package like graphicx. Assuming that the statement \usepackage{graphicx} appears in the preamble, if we have a postscript file named graph_1.ps, we can import this image with the following statement placed in the body of the LaTeX file:
\includegraphics[width=2.5in]{graph_1.ps}
|
Sometimes, LaTeX will have trouble importing the image in the exact preferred location of your document. Consult a LaTeX reference text for additional information on how to remedy this problem.
Two very flexible and powerful programs available on UNIX that can create postscript images are xfig and tgif. To use tgif you will first need to add the goodies locker (type add goodies at the UNIX prompt) and then type tgif.
To use xfig, simply type xfig at the UNIX prompt. Launch xfig and export a simple picture as a postscript file.
Example Postscript Image Use the right mouse button to choose "save link as" or "save target as".
Converting to Postscript or PDF
Now that you have completed your masterpiece, convert it to postscript or PDF to be able to view the printed form.
In the Xterm window type:
dvips myfile.dvi |
This will convert the .dvi file into postscript format (saved as myfile.ps). Print the file with the command lpr myfile.ps. If the printed form looks misaligned, you can make adjustments with:
dvips -O 0.xin,0.yin myfile.dvi |
Above we are using the -O switch (capital letter `oh') to adjust the location of the image 0.x inches along the horizontal direction and 0.y inches in the vertical direction (you can use negative values as well). If this does not help, you may need to return to the preamble section of the LaTeX file and make adjustments there.
You can create a Adobe PDF file by converting the postscript file. In the Xterm window type:
add acrobat distill <myfile.ps> myfile.pdf |
Reference Texts
Many to choose from -- here are only some:LaTeX : A Documentation Preparation System User's Guide and Reference Manual Author: Leslie Lamport, Duane Bibby(Illustrator) Format: Trade Paperback Publication Date: August 1994 ISBN: 0201529831
The Latex Companion Author: Michel Goossens, et al Format: Trade Paperback Publication Date: January 1994 ISBN: 0201541998
A Guide to Latex: Document Preparation for Beginners & Advanced Users Author: Kopka, Helmut Format: Softcover Publication Date: 2/1/1999 ISBN: 0201398257
Latex for Everyone: A Reference Guide and Tutorial for Typesetting Documents Using a Computer Author: Jane Hahn Format: Paperback Publication Date: February 1993 ISBN: 0136059082