[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lecture 11 Notes



These are the notes for lecture 11

Mark

-- 
Today's fortune:

	Sherry [Thomas Sheridan] is dull, naturally dull; but it must have taken
	him a great deal of pains to become what we now see him.  Such an excess of
	stupidity, sir, is not in Nature.
			-- Samuel Johnson
Title: Math 481/581 Lecture 11: LaTeX Part II

Math 481/581 Lecture 11: LaTeX Part II

© 1998 by Mark Hays <hays@math.arizona.edu>. All rights reserved.


This continues the discussion of LaTeX. In this part, we'll cover running LaTeX, viewing and printing LaTeX documents, TeX resources on the WWW, and the basics of typesetting mathematical formulae.


LaTeX vs. TeX

LaTeX is a typesetting system developed by Leslie Lamport. LaTeX commands are implemented in TeX, a typesetting language developed by Donald Knuth.

Writing documents in LaTeX versus TeX is a lot like programming in C versus Matlab. Like C, TeX gives you a lot more flexibility than Matlab (or LaTeX). On the other hand, some things are much easier in LaTeX. For example, TeX provides no means for automatic equation numbering and referencing these numbers.

I won't say any more about it, but remember two things:

If you are going to be something other than an occasional LaTeX user, you will definitely want to buy a reference book on the subject. Here are a couple that should be available in the ASUA bookstore (2nd floor):

SubjectTitle
TeXThe TeX Book by Donald Knuth
TeXThe Joy of TeX
LaTeXLaTeX: A Document Preparation System by Leslie Lamport
LaTeXThe LaTeX Companion


Running LaTeX

Last time, we dissected a LaTeX input file alongside the corresponding printed output. Let's briefly go through the steps necessary to get from the LaTeX file to the hardcopy.

Once you are ready to test out your LaTeX code, you need to process it using the latex command. Assuming that your file is called file.tex (you should use the .tex suffix for all LaTeX source files), you'd use something like:

  > latex file.tex
  [... diagnostic output ...]
  >
NOTE
You may have to type setup tetex on the u.arizona.edu system before you can run LaTeX.
If all goes well, you should end up with a DeVice Independent, or "DVI" file named file.dvi in your CWD. DVI files act as an intermediary between the LaTeX source code and a printer-specific data format. DVI files are binary files -- remember this if you need to FTP a DVI file.

There are many kinds of printers, and, in general, each type of printer uses a different method of encoding the sorts of graphics produced by LaTeX (LaTeX requires graphics output because the mathematical symbols it produces are not part of the standard ASCII character set). PostScript printers speak PostScript, HP printers speak PCL, and Epson dot-matrix printers have their own special format. LaTeX includes a number of special programs that convert DVI files into formats that printers can deal with directly.

Why have the DVI file at all? There are at least two reasons. First, there is a program that can display a DVI file on your screen. This is useful because it lets you see a preview of what the printed output will look like without actually having to print it. We'll look at this in more detail in a moment.

Second, DVI files are portable (even more portable than LaTeX source code). You can give someone a DVI file and they can preview it or print it without having to possess your LaTeX source code (there are a number of situations in which this is desirable). Without the DVI file, you would either have to make your source available or be prepared to provide copies of your document in every conceivable printer format.

Now that you have a DVI file, there are two or three things that you can do with it. Assuming that you are running LaTeX on a UNIX system and are in the midst of an X-windows session, you can use the xdvi program to view the DVI file with:

   > xdvi file.dvi
A window will pop up and show you the first page of the "final product". You can control the document scaling and switch between pages using the buttons on the right side of the window. Clicking a mouse button on a visible part of the document brings up a temporary zoom of the area surrounding the mouse pointer. If you make changes to your LaTeX code and rerun latex on your file, the xdvi window will be updated the next time you click a mouse button in the window; ie, it isn't necessary to explicitly reload the modified DVI file.

You can also convert the DVI file to a format suitable for printing (you cannot directly print a DVI file by itself). If you want to generate a PostScript version of your document, you can use the dvips program like so:

   > dvips -o file.ps file.dvi
   [... diagnostic output ...]
Here, the filename following the -o option determines the output filename. If you want to create an HP-PCL version, you can use the dvilj command:
   > dvilj file.dvi
   [... diagnostic output ...]
In this case, you'll end up with file.lj in your CWD.

Why do you need the -o option for dvips? Well, you don't, necessarily; however, oftentimes dvips will be configured to send its output directly to a printer unless you explicitly redirect the output to a file, as above. In other words, typing "dvips file.dvi" will not generate "file.ps" -- it will instead send your document to the printer (this is the case for Math department machines).

If you do create a PostScript file and want to print it out, you can normally do so by using either the lpr or lp commands. The command you use depends on whether your system is set up for Berkeley printing or System V printing. If you aren't sure, you should ask your system administrator for assistance. At the Math department, we use Berkeley printing and so you'll use the lpr command:

   > lpr file.ps

Many UNIX systems expect either plain ASCII text or PostScript. Sending PCL or other binary data to a PostScript printer will likely fail. Or cause several hundred pages of gibberish to emerge from the printer. Remember: CCIT charges by the page. On your shiny new CatCard. The point is that you need to know what type of data the printer is expecting. All UNIX print queues in Math department labs will handle ASCII text or PostScript.

Now the important part: where does the thing physically print out? The answer depends on where you printed it from. Here is a table to help you navigate a few local systems:

Print fromPrintout appears
Math 225Math 225 NW
Math 226Math 226 SW
Math 514Math 514
ame2.math.arizona.eduMath 514
u.arizona.eduCCIT -- Speedway and Mountain

If your system uses Berkeley printing, there are a couple of other handy commands to know about. First, the lpq command shows the status of the default print queue:

  > lpq
  Rank   Owner      Job  Files              Total Size
  1st    hays       1    (standard input)   5 bytes
  2nd    hays       2    (standard input)   7 bytes
This command shows all print jobs currently in the queue. The other interesting command is lprm which you can use to remove (your) print jobs from the queue. To use it, first run lpq and note the job ID (third column) of the job you'd like to cancel. To, for example, cancel job number 2, type:
  > lprm 2
  dfA002Aa05940 dequeued
  cfA002Aa05940 dequeued
  > lpq
  Rank   Owner      Job  Files              Total Size
  1st    hays       1    (standard input)   7 bytes
To cancel all of your print jobs, you can do "lprm -".


LaTeX Error Messages

If you use LaTeX for any length of time, you will come across one or more of LaTeX's wonderful error messages. You will observe such messages when there is a problem in your LaTeX source code. In many cases, the problem is a simple typographical error and is easily corrected. In other cases, it can take a significant amount of time to track down the exact source of the error.

To be concrete, suppose you have the following LaTeX code:

 1:   \documentclass{article}
 2:
 3:   \begin{document}
 4:
 5:   \begin{itemize}
 6:   \item This is the first item.
 7:   \item Item \#2
 8:      \begin{enumerate}
 9:      \item This is the first enumerated item.
10:   \end{itemize}
11:
12:   \end{document}
The problem with this code is that I've forgotten the innermost \end{enumerate}. When you run LaTeX on this code, you'll get something like:
   > latex errs.tex
   This is TeX, Version 3.14159 (C version 6.1)
   (errs.tex
   LaTeX2e <1996/06/01>
   Hyphenation patterns for english, german, loaded.
   (/usr/lib/texmf/texmf/tex/latex/base/article.cls
   Document Class: article 1996/05/26 v1.3r Standard LaTeX document class
   (/usr/lib/texmf/texmf/tex/latex/base/size10.clo))
   No file errs.aux.

*  ! LaTeX Error: \begin{enumerate} on input line 8 ended by \end{itemize}.

   See the LaTeX manual or LaTeX Companion for explanation.
   Type  H   for immediate help.
    ...                                              
                                                  
*  l.10 \end{itemize}
                 
*  ? 
The lines marked with a "*" are the important ones. The first such line gives the biggest clue -- in this case, LaTeX can tell you exactly what it is confused about. Most often, this will not be the case. The second *'ed line tells you the line number at which latex became confused. In our example, line 9 is the \end{itemize} command that should have been a \end{enumerate}. LaTeX errors occur on of before the line specified by the "l.NNN" line -- never after.

The last *'ed line is LaTeX's "?" prompt. There are normally two things you can do at the "?" prompt:

It is generally worthwhile to attempt to continue processing; however, if an error occurs at the same line number more than a few times, you're better off calling it quits with "x".

Every now and again you will get the (TeX) prompt

    *
The recommended thing to do here is type CTRL-D.

Lamport's LaTeX book gives detailed descriptions of most commonly encountered error messages. For the most part, such descriptions aren't too useful because you're still faced with the task of locating the source of the error and correcting it. The best rule of thumb I can give is to start at the designated line number and work your way backwards until you've got it.


TeX Resources On The WWW

If you go to the SWIG page, you will find a page on LaTeX 2e in the online documentation section. This is a good place to get started.

At the bottom of this page is a list of links to relevant LaTeX information; in particular, the link to the Comprehensive TeX Archive Network (CTAN) is a central repository for all things TeX. The CTAN address is:

http://tug2.cs.umb.edu/ctan

If you are interested in getting LaTeX running on your Windows machine at home, go to the top-level of the archive and proceed to systems/win32/miktex. Miktex is a nice version of LaTeX for Win32 systems (ie, Win95, Win98, and WinNT).

You may also want to grab a copy of ghostscript to preview PostScript files. The Aladdin Ghostscript page is at

http://www.cs.wisc.edu/~ghost

Ghostscript lets you view Postscript files on your screen; it also lets you convert PostScript to other formats for printing.

If you have something other than Win32 or UNIX at home (eg, Mac, DOS, OS/2, etc), the CTAN probably has a distribution of LaTeX that will run on your machine. Ghostscript runs on most platforms, too.


Mathematical Symbols And Examples

The following document is a more or less comprehensive listing of the mathematical symbols available in LaTeX. It also includes typesetting examples of varying degrees of complexity.

http://www.math.arizona.edu/~hays/latex/syms/syms.html

If you buy a book on LaTeX, it should contain tables of all of these symbols.


Typesetting Mathematical Formulae

The following is a LaTeX document about using LaTeX math mode. It has been converted to HTML using latex2html.

http://www.math.arizona.edu/~hays/latex/ts/index.html