1 Using L^{A}TEX

1.1 Introduction

L^{A}TEX is not a word processor, but a technical typesetting system. If you use a word processor, you see the effects of typing something immediately. The way L^{A}TEX works is more like writing computer programs. You have a text file containing your text and typesetting commands, and your output is obtained by “compiling” the input file. On a PC or dumb terminal this process can be very frustrating. On a workstation, as described below, it isn’t nearly as bad, but it takes some getting used to.

Learning L^{A}TEX takes a while, and it can be very frustrating in the beginning. At this point, you are likely to ask “Why bother?”. Some of the reasons I can offer are given below.

1. The output is better than any word processor is capable of.

2. L^{A}TEX isn’t quite free, but is freely available on most platforms at no cost. Thus, wherever you go you are likely to have access to L^{A}TEX.

3. L^{A}TEX input files are just text (ASCII) files. They can be mailed easily, and transported from platform to platform without loss of information.

Some of things that L^{A}TEX can do are listed below.

• Format complicated mathematical equations.

• Automatically number equations, figures and tables.

• Generate a table of contents.

• Import pictures produced by Maple, xfig, or other programs directly into your document.

• Make forms for surveys. (Lots of IQP projects involve surveys.)

• Include a program listing or sequence of Maple commands into your document.

• Make lists or outlines.

1.2 L^{A}TEX under UNIX/X

To use L^{A}TEX under UNIX/X, you will usually be using three windows at once.

1. A text editor window. In this window you create a file with your text and L^{A}TEX commands to format your document and typeset equations, etc. The name of this file has to have the format name.tex, where name is a name that you choose. We will refer to this file as your input file.

2. A previewer window. Under UNIX, the command for the previewer is xdvi. This program will let you see what your report will look like without printing it out.

3. A terminal window. Use this window to start up your text editor, previewer, and to issue the latex command to process your file. It makes sense to run the editor and previewer in the background so that this terminal window is still available for issuing commands.

1.3 An Example

To get started, copy the file /home/bfarr/test.tex to your home directory. Then start up your favorite text editor, using this file as input and running your editor in the background by using & at the end of your command.

Look at the file test.tex. Everything before the \begin{document} command is called the preamble. This is where you set up things like type size, margins, and document style. All of your text and equations must go between the \begin{document} and the

\end{document} commands.

To process your file, issue the command

latex test.tex

in your terminal window. You will see some messages appear as your file is processed. The result of running this command will be a file called test.dvi.

To view your file, type the command

xdvi test &

which will bring up the previewer. The buttons on the right-hand side can be used to navigate around in your document. There are also equivalent keyboard commands listed below.

• d will move down the page

• u will move up the page

• n will show the next page

• p will show the previous page

• q will quit the previewer

• ns, where n is an integer will zoom in or out. The default is 4s.

The mouse can be used to zoom in on any area in the previewer window. Just move the mouse cursor to the region you want to zoom in on and click any of the mouse buttons. For more information on the previewer, type man xdvi in a terminal window.

Try typing your own text in the file, saving the result, and running the command latex test again. If you make the previewer window your active window again, it will read in the new version of the dvi file.

Note that L^{A}TEX does its own line breaks and ignores any carriage returns in your input file. To force a line break you can use the \\ command. You indicate the end of a paragraph by putting a blank line in your input file.

1.4 Special Characters

The ten characters

# $ % & _{ } ~ ^\

have special meanings in L^{A}TEX and must be used with care. That is, if you use one of these characters in your input file it will not be printed, but will be interpreted as a command! The first seven characters can be printed with the commands

 \#, \$, \%, \&, \_, \{, \}

but the remaining three require special tricks, to be described later, to print them.

1.5 L^{A}TEX Commands, Environments, and Modes

L^{A}TEX commands almost always begin with the backslash character \, followed by a word. There are a few exceptions, but they are only rarely encountered. Many commands take arguments, which are usually enclosed in curly braces, like \pagestyle{empty} or begin{document}, unless they are optional arguments, in which case they are enclosed

in square brackets, like \documentclass[12pt]{article}.

Some simple examples are provided by the commands to change font styles. Most are of the form \textxx{text}, where xx is a two-letter mnemonic of the font style. Examples are given below.

• \emph to produce emphasized or italic text. For example, \emph{emphasize} produces emphasize.

• bf for bold font style.

• sf for sans serif font style.

• sl for slanted font style.

• sc for small caps font style.

• tt for typewriter font style.

Changing font sizes follows a different model, in that the command appears inside the curly braces along with the text whose size is being specified. For example, the command {\tiny this is a tiny font} produces the output this is a tiny font.

An environment is a special form of a L^{A}TEX command structure. An environment structure has the form

\begin{environment}
(text to be formatted}
\end{environment}

Some of the most common environments are listed below.

• itemize for producing a list with items identified by “bullets”.

• enumerate for producing a numbered list.

• description - another list environment. See the manual for details.

• tabular for lining things up in columns and making pretty tables. See the manuals for examples.

• verbatim for putting in program fragments.

• quote for short quotations or a series of short quotations.

• quotation for longer quotations.

The first three environments are examples of list-making environments. Each item in the list is introduced with the command \item.

1.6 Equations

L^{A}TEX has special environments for entering mathematical expressions.

• To include an expression in a line of text, you use $ to mark the beginning and end of your expression. For example, to produce the equation f(x) = x + 1 you would type $f(x)=x+1$ in your input file. Note that L^{A}TEX puts in spaces where it wants to in math mode, and generally ignores any spaces that you put in.

• To put a longer expression on a line by itself, you use \[ to mark the beginning and \] to mark the end of the expression. For example, putting \[f(x)=x+1.\] in your input file produces the output

f(x) = x + 1.

• To produce a single numbered equation, you have to put your formula inside an equation environment, as follows.

  \begin{equation}
  f(x)=x+1
  \end{equation}

The result of this series of commands is shown below.

f(x) = x + 1  (1)

Note that L^{A}TEX does not break lines inside an equation environment. If you have a formula that is too long to fit on one line, you will need to use one of the multi-line environments below.

• If you have a multi-line formula, then you need to use the eqnarry environment to get numbered formulas or the eqnarray* environment to produce multi-line formulas without numbers. See the following two examples.

\begin{eqnarray}
f(x) & = & x+1 \\
g(x) & = & 2-x \\
h(x) & = & x^2
\end{eqnarray}

produces

f(x) = x + 1  (2)
g(x) = 2 − x  (3)
h(x) = x^{2}  (4)

while

\begin{eqnarray*}
f(x) & = & x+1 \\
g(x) & = & 2-x \\
h(x) & = & x^2
\end{eqnarray*}

produces

f(x) = x + 1
g(x) = 2 − x
h(x) = x^{2}

The & characters line things up in columns, and the \\ commands are line breaks. Note that the last equation should not have \\ after it.

1.7 Printing

To print out the first example L^{A}TEX document, use the command

dvips -Pprintername test,

where printername is a valid name for a printer. To find out more about dvips type man dvips in any terminal window, or consult the on-line documentation.

1.8 L^{A}TEX errors

If you make a mistake in your input file, then you will get an error during the processing of your input file. It is usually obvious when you get an error: a ? prompt appears below a more-or-less helpful description of the error. The last line of this description includes the line number of the offending command and the actual fragment from your input file that caused the error. At this point you can do several things.

• Press return, and processing of your file will continue. If your error wasn’t serious this will work ok. If you are working on a DECstation then check the line in your file that the error refers to and try to fix it before pressing return. This won’t fix the error, but it will prevent the error from recurring.

• Type h to see what kind of help L^{A}TEX offers. Maybe the message will help you realize what is wrong with your input file.

• Type x to stop processing your file. This will return you to the system prompt. You should avoid doing this unless L^{A}TEX seems to be stuck at some point in your input file and can’t go any further. Since L^{A}TEX takes a while to get started, it makes sense to find and correct as many errors as you can in each pass.

1.9 Including Maple commands and output

This section describes a technique for including all or a part of a Maple worksheet in a L^{A}TEX document. It requires the use of the mapleenv package, which you must load with a \usepackage command in the preamble of your document as in the following example.

\documentclass{article}
\usepackage{mapleenv}

Before you can include all or a part of a Maple worksheet in a L^{A}TEX document you must first save your worksheet in L^{A}TEX format. To do this, load your worksheet into Maple, and then choose the Export as LaTeX... item from the File menu. This will bring up the LaTeX Setup dialog box. By default, Maple will construct a name for the file by taking the name of the worksheet and replacing the .ms extension with .tex. For example, suppose your worksheet’s name is lab1.ms. Then the default name when you export your worksheet as a L^{A}TEX file would be lab1.tex. You can, of course, type in any file name you choose in the dialog box, but you should use the .tex extension to end the name. The LaTeX Setup dialog box also has a text window for setting the maximum display width for equations. The default value of 5 inches works well, so only change it if you have problems.

1.9.1 Including the whole worksheet

This is the easiest way to include your entire worksheet in a L^{A}TEX document. If you only want to include parts of it, or you need to break it up into pieces, see the next section.

Including your entire worksheet is a two-step process. The first step is to edit your exported worksheet and remove the first three lines and the last two lines from the file. The first three lines (i.e. the ones to remove) will look like the following

%% Created by Maple V Release 3
\documentstyle[maplems]{article}
\begin{document}

and the two lines at the end you should remove are the following.

\end{document}
%% End of Maple V Session Output

The second step is to indicate in your main L^{A}TEX file where you want the worksheet to appear. This is done by putting a \input or \include command in your main L^{A}TEX file. For example, suppose the name of the file containing your exported worksheet was lab1.tex. Then the command to use to include your entire worksheet would be either

\include{lab1}

or

\input{lab1}

The difference between these two commands is that the \include command will start the included worksheet on a new page while the \input command will not start a new page.

1.9.2 Including parts of a worksheet

This process is more flexible, but also trickier than including a whole worksheet. Basically, you have to copy parts of the exported worksheet and paste them into your main L^{A}TEX file. This means you have to be able to identify the L^{A}TEX commands that generate the Maple worksheet items that you want to include. The following three rules should help you.

1. Maple input regions are enclosed in mapleinput environments. That is, each Maple

     input command appears between a \begin{mapleinput} – \end{mapleinput}

pair.

2. The \maplesepline command produces a horizontal separator line.

3. Maple output regions are enclosed in maplelatex environments for equations and maplettyout environments for text output.

1.9.3 Including Maple Plots

You can also easily include plots generated by Maple in L^{A}TEX documents with the following two step process.

1. Generate the plot, and save it to a file, for example fig1.ps.

2. Use the following command to include the picture in your document.

     \mapleplot{fig1.ps}

1.10 Including Encapsulated PostScript graphics

There are actually several ways to do this. The first method described here uses the epsfig package. To use this package, you must load it with a \usepackage command, as in the following example.

\usepackage{epsfig}

The epsfig macros allow you to scale, crop, and rotate the picture. Note that if you load the mapleenv package, the epsfig package is also loaded, so attempting to load it again will give an error.

There are really two steps to this process.

1. Generate the graphic, and save it to a file, for example fig1.ps.

2. Use the following sequence of commands to include the picture in your document.

     \begin{figure}[htb]
     \centerline{\psfig{file=fig2.eps,height=3.0in,angle=-90}}
     \vspace{.2in}
     \caption{\label{lab}Caption text}
     \end{figure}

These commands center the graphic, and also put it inside of a figure environment which allows you to use a caption and label to describe and refer back to the graphic. The angle=-90 argument is needed if the graphic was created by Maple.

Another way to include graphics is to use the graphicx package. This package can be loaded with the following command.

\usepackage{graphicx}

The commands to include a PostScript file fig1.ps in your L^{A}TEX document using the graphicx package L^{A}TEX document are shown below. These commands mimic what we did above using the epsfig package and will give the same results.

\begin{figure}[htb]
\centerline{\includegraphics[height=3.0in,angle=-90]{fig1}}
\vspace{.2in}
\caption{\label{lab}Caption text}
\end{figure}