The Very Basics of TeX
TeX is a typesetting programming language. The most important thing
to know if you want to write your problem sets in TeX is that it runs
in two modes: normal mode and math mode. In normal mode, only text is
handled. You can alter the text (for example, making it bold-face or
italic) but generally you can't use any fancy characters or typsetting
in normal mode. A new paragraph is started when you leave a blank line
in the TeX file.
Some normal-mode commands to know:
- "{\bf TEXT}" puts TEXT in bold face.
- "{\it TEXT}" or "{\em TEXT}" puts TEXT in italics.
- "\smallskip", "\medskip", and "\bigskip" insert various small
amounts of whitespace, in between paragraphs for example.
- Put "\begin{enumerate}" if you want to give a numbered list.
Start each element in the list with "\item", and when the list is
finished, put "\end{enumerate}"
- "\begin{itemize}" with "\item" will do the same thing without
numbering the items.
In math mode, letters are written in italics (they are assumed to be
variables or functions, not words), and more advanced typsetting is
allowed. In order to switch back and forth between math mode and
normal mode, you use the $ character. That is, if you add "$x^2$" in
the middle of a bunch of normal mode text, the first '$' changes the
mode to math mode, the 'x^2' is interpreted and typset correctly, and
then the second '$' changes the mode back to normal mode.
Some math-mode commands to know:
- $x^a$ will put "a" as an exponent of x.
- $x^{abc}$ will put "abc" as an exponent of x. If you put $x^abc$
you will get output that looks wrong.
- $x_a$ will put "a" as a subscript of x. Similarly, $x_{abc}$
should be used for longer subscripts.
- $x^{y^a}$ and $x^{y_b}$ work, et cetera.
- $\alpha$ will produce an alpha character. Give the name of a
greek letter after a '\' (the command character) to get that greek
letter.
- $\ldots$ will produce the '...' such as in "1 + 2 + ... + n"
- '{' and '}' are special characters. To get '{' or '}' to show
up, use '\{' and '\}'.
There are many other commands you can use in math mode. For a more
extensive LaTeX reference online, try The
Not So Short Introduction to LaTeX 2e, especially the List
of Mathematical Symbols, also found here (PDF).
One final word about math mode: When you use the single '$' to go into
math mode and then back out, this inserts your mathematical type in
the middle of the paragraph. If what you want is to give an equation
or mathematical phrase on its own, go into math mode with a double
'$$' and back out the same way. This will put that incident of math
mode on its own line, centered. Some commands will come out looking
different if you put them on their own line. For instance, if you use
$\sum_{i=0}^{n} i$, the limits on the sum will be to the right of the
sum symbol. However, if you use $$\sum_{i=0}^{n} i$$, the limits will
be on the top and the bottom.
Debugging
When you have finished writing your .tex file, run "latex ps1.tex"
from the unix prompt. If you had no bugs in your TeX
code it'll go right through and give you a prompt again.
However, you will probably have some errors. Most errors fit into one
of these few categories:
- You forgot to close something you opened. You forgot to put
enough close parentheses or curly braces, or you left off the closing
$ to go out of math mode. You may also have forgotten to put
"\end{enumerate}" after your numbered list was finished. Remember that if
you use $$ to put a math mode block on its own line, you must close with a
$$. If you close with a single $, it will cause an error.
- Similar to the above, you forgot to open something you closed.
- You used a non-existant command.
- You used a command in normal mode that is only supposed to be
used in math mode. Sometimes this can look like a #3-type problem.
Feel free to ask me questions about TeX over email; I'll help you if I
can. I'm not particularly good at things like importing graphics or
matrix layouts, but I get by pretty well generally.
.Dvi? What's that?
When your "latex file.tex" command goes through, it creates a file
called "file.dvi". This can now be printed by typing "dvips file.dvi"
- this will print to the default printer. DVI files can
also be used to produce postscript files. To make file.dvi
into file.ps, run "dvips file.dvi -o file.ps"
To make file.dvi into file.pdf, run "dvipdfm file". Dvipdfm is
superior
to dvipdf; it runs faster and produces better results.
If you want to check over your file to make sure it looks right
(without printing it), you have two options. First of all, you can
use the above instructions to create a postscript file, and use
ghostview ("gv file.ps &") to view it. Or, more simply, you can just
run "xdvi file.dvi &" to view your .dvi file without changing it to
postscript. Please be sure to do this, as some errors may result
in no complaints, but produce a very strange-looking file.
Figures
Figures can be a pain to draw just to hand in a problem set. If you want
the easy shortcut, put in "\vspace{3in}" which will leave you a good
amount of space to draw your figure in (you can adjust the amount of
space).
If you want to do things the best possible way, TeX files can easily be
made to include .eps diagrams. To include a .eps figure, make
sure that the line "\usepackage{epsfig}" appears at the top of your file
somewhere. Then, where you want to insert the image, use the command
"\centerline{\epsfig{figure=FILENAME.eps, height=2in, width=2.5in}}"
You might want to surround that with "\vskip 0.4cm" on both sides to
give
some margins. .eps files are "encapsulated postscript files." You
probably don't have an editor that works with this kind of file, but I
mention this because there is one you can use in unix: it's called xfig.
To run it, type "xfig [filename]" and a blank figure file will open up;
the interface is pretty self-explanatory, but you need to be using a
3-button mouse for things to work well. Once you've saved your file, you
can "export" it, which produces an .eps file.
However, xfig is a pain to use sometimes, so you may prefer to work
with a
different utility. The good news is that you can use a different package
to include other types of graphics, including PDF diagrams, but also .png,
.jpg, and .gif image files. If you do this, you'll only be able to make a
.pdf file in the end, not a .ps file.
To do this, make sure your file has "\usepackage{graphicx}" somewhere
at
the top (and remove "\usepackage{epsfig}" if it's there, since you only
need one). Then, to include an image somewhere, you can use
"\begin{center}\includegraphics[height=2in,width=2.5in]{FILENAME}\end{center}"
where FILENAME includes the extension here. Again, you might want to
add
space on either side.
home