LaTeX is a language for specifying both the content of and the formatting directions for how a particular document should look. It is particularly useful when writing technical documentation because of the rich language it has for specifying equations. In what follows, some of the basic syntax is described (many of the examples, or slight modifications of them, are also realized in example.tex).
Probably the most efficient way to learn LaTeX in this class will be to:
cp /home/infosys/www/courses/2004/fall/cs140/homework/example.tex .or downloading from the link above. Also copy over the little script, make_doc, that I've written to Latex and convert a latex file into postscript:
cp /home/infosys/www/courses/2004/fall/cs140/homework/make_doc .To execute this, make sure it has executable permissions (you might need to chmod u+x make_doc). Then type:
make_doc exampleSince the example file has no syntax errors (I checked!), the script will end its run with:
Your file: example.tex has been converted into example.psTo view this file, type
gv example.psYou can print the standard way:
lpr example.ps
With respect to modifying a particular homework assignment, you can skip the gorey details that go along with initially setting up a LaTeX document. Simply modify the one that I used to create the assignment in the first place. This can be obtained by downloading from a web-browser here or issuing the appropriate copy command, e.g. if you wanted HW1a, you'd type:
cp /home/infosys/www/courses/2004/spring/cs140/homework/hw1a.tex .When modifying this file, don't forget to add your name! (One very good place to do this is between the "\begin{center}" and the next "\bf".)
\itemThen when you run the make command, you'll get
See the LaTeX manual or LaTeX Companion for explanation.
Type H return for immediate help.
...
l.6 T
his is just a stupid little LaTeX document.
?
What this tells you is that it thinks the problem is at the first "T" in line 6.
One point to take away from this is that LaTeX doesn't always identify perfectly
where the problem is. So if you get an error like this, you might have to
carefully think about what you've done to the file (and ask a LaTeX savvy friend
for help if you find yourself spending too much time). Usually, the problem will
be one of an ill-formed environment (described later), so that's the first thing
to carefully inspect. For now, however, I'll just tell you how to get out of
this mode. At the ?you want to type an
xThis will tell latex to quit. Find your error, fix it, and then reissue the do_make.
I often use commands that specify what font LaTeX should use. For instance, if you want to display a phrase in bold, you could use
{\bf A phrase}
Similarly, italics could be specified with
{\em Another phrase}
In these cases, the commands go inside the curly braces (and these
indicate the scope of words that should have a particular font).
Interestingly, "\\" is also a LaTeX command; it tells LaTeX to make a new line. It is also very useful to be able to skip downwards some fixed amount. For example,
\vspace*{3in} \\
will leave 3 inches of white space before continuing with the text.
In the past, students have used this command to allow them
to draw a figure by hand to accompany some homework solution writeup.
I encourage you to use pictures whenever they are useful in clarifying your
explanation.
It is essential that blocks be well formed -- i.e. they must indicate where their environment begins and ends. There is different syntax for doing this depending upon what you are trying to do. For newbies, the most frustrating part of using LaTeX is trying to find out why your document won't "parse" -- especially since LaTeX's comments are not always as useful as one might like. Usually, the culprit is an ill-formed environment. Should your document not compile, check carefully near the lines it is complaining about to see what scope you neglected to close.
The environments you'll most likely see in this course's LaTeX files are described in the following sections.
\begin{enumerate}
\item I'm the first item!
\item I'm the second.
\item and so on...
\end{enumerate}
Here "\begin" and "\end" define the environment.
A bulleted list is very similar:
\begin{itemize}
\item ...
\end{itemize}
Lists can be nested.
\sum \prod \infty \subset \subseteq \in \forall \exists \emptyset \Leftrightarrow \Rightarrow \rightarrow \leq \geq \Theta \OmegaI should also call your attention to the Functions Table provided in the above link. One that you will want to use is "\log". For example:
$\log(x)$is preferable to
$log(x)$because in the former, the "log" is treated as a function name (displaying it in Roman type), whereas in the latter case, LaTeX treats the "log" as a variable (italicizing it).
To use any of the math commands, you must first enter into the mathematics environment.
"$" is used to delimit the math environment within a current line (this allows an equation to occur within a block of text). For example,
...equation $x = y + z$ is very useful because...Note the "$" must occur twice; the first signifies the beginning of math mode and the second signifies its end.
If you wanted the equation to be centered on its own line, you'd use
\[ x = y + z \]
Another very powerful aspect of math mode is its ability to format symbols and text as sub- and super-scripts Algorithms-useful syntax includes:
\[ {x}_{i} = {z}^{y} \]
Here's another:
\[ x_i = z^y \]Now lets consider how to format the equation for specifying the Euclidean distance of some n-dimensional vector x:
\[ ( \sum_{i=1}^{n} (x_i)^2 )^{\frac{1}{2}} \]
Notice here that I used "\frac{1}{2}", which tells LaTeX
to display the fraction one-half (since this occurs as a super-script,
it is interpreted as the square-root).
\begin{verbatim}
...
\end{verbatim}
In particular, in this mode, text is formatted exactly as it appears in the LaTeX
file (white spaces, etc., are preserved).