Colorado State Banner

Mak's Latex Tips

 

Home

Toolbox

Latex is a document processing system similar to the Hypertext Markup Language (HTML).  One creates a simple text file that is "rendered" using the basic Latex tools plus some special commands depending on the desired format of the final document.  

The simplest document you can create is an article and it looks like this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{latexsym}
\usepackage{graphicx}
\begin{document}
This is a simple latex document without a title.

\section{Introduction}
\label{intro}
\section{Body}
\section{Summary}
\label{summary}
%this is where the bibliography would go
\end{document}
Copy the contents of this file to a text file called sample.tex.  Now, to compile the document, run a series of commands.

	latex sample.tex 
latex sample.tex
You perform the command twice because latex creates temporary crossreferences the first time through then creates an intermediate document format the second time through. The intermediate format is called a DVI file; DVI files can be converted to a variety of formats including PS, PDF, and HTML.  To view the DVI document, type:   
	xdvi sample.dvi
This should bring up a DVI viewer that contains the document; it should look very similar to a PDF document format.  To convert the document to a PostScript file, you can type the command:
	dvips -Pcmz -Pamz -t letter -o sample.ps sample.dvi 
which you can view using the command:
	gv sample.ps
Finally, you can convert the document to PDF format with the command:
	ps2pdf sample.ps sample.pdf
and view the document with the command
	acroread sample.pdf
If you do a listing, you'll see that the latex program has created a host of additional files as it did its work.
I personally dislike all the extra files and will remove them with the command:
	rm -f *.log *.dvi *.lof *.toc

Saving yourself the headache of all those commands

At this point it is worth metioning that I never actually type all these commands in myself because I'm lazy.  I have two shortcuts that I use depending on my mood.  The first shortcut involves using two alias commands (I use tcsh so change this for your shell as needed):
	alias texbib2ps 'latex \!* ; latex \!* ; bibtex \!* ; /
latex \!* ; dvips -Pcmz -Pamz -t letter -o \!*.ps \!*.dvi ; /
\rm -f *.log *.dvi *.lof *.toc'

alias lt 'texbib2ps \!*; ps2pdf \!*.ps'

This way, I just type the command:
	lt sample 
and the ps and pdf files get created provided there aren't any errors in the TEX document.

A more robust method is to use a make file since each stage depends on the previous and the whole process will stop once an error is found.  To get the make file to work, I just put it in the same directory and then type
	make sample.pdf


Mathematics Symbols 

Probably the biggest reason to use latex besides its very professional output is the way it handles symbols.  Insert the following into your document and recompile it to see what I mean.
	We judge a test significant if $p<0.05$ and 
highly significant if $p \ll 0.001$.
it looks wierd in text, but absolutely wonderful in the final PDF document.

Tables and Figures

Another handy thing that latex allows you to do is create tables.  Copy the following into your document and recompile to see what I mean:
	\begin{table}
\begin{center}
\scalebox{0.9}{
\begin{footnotesize}
\begin{tabular}{|l|rrr|rr|}
\hline
\multicolumn{1}{|c|}{Domain}
&\multicolumn{3}{c|}{Problem Sets}
& \multicolumn{2}{c|}{Labels}\\
\multicolumn{1}{|c|}{ (Symbol)}
& H & \noH & \mOO & mType & hType \\
\hline
Assembly (AS) & 135 & - & - & M1 & HU \\
Blks-3op (B3) & 150 & - & - & M0 & HC \\
Tyreworld(TY) & 1 & 11 & - & MX & HH \\
TSP (TS) & 8 & - & - & MX & HH \\ \hline
TOTAL &1814 & 910 & 290 &\multicolumn{2}{c|}{}\\
\hline
\end{tabular}
\end{footnotesize}
}
\end{center}
\caption{A flattened representation of the domains and problems we
examine. The rightmost columns show the placement of each
domain into the appropriate ordered mType \{MX, M0, M1\} and
hType \{HC,HH,HR,HU\}. The second through fourth columns
list number of problems each domain contributes to the
problem sets. Note that \mOO is a subset of \noH.}
\label{tbl:problems}
\end{table}

Figures 

Naturally, you can embed other pictures and documents into your file to have them show up as part of the final document.  Place this file in your directory then copy the following into your document and recompile.
	\begin{figure*}[tbh]
\centerline{\includegraphics[scale=0.45]{busPortfolio3}}
\caption{Portfolio architecture}
\label{fig:port}
\end{figure*}

Cross referencing 

The internal prose of Latex documents can refer to labeled tables, figures, sections, pages in a dynamically growing document.  You set the reference once then never revisit it! You also don't need to bother with numbering as latex will do that for you (so long as you call latex twice to generate the document.  
	Figure~\ref{fig:port} shows our portfolio structure
while Table~\ref{tbl:problems} shows the problems we
used in our study.
Notice that we are referring to labels that were already placed in the tables, sections, and figures above -- now you know what those labels were for!

Bibliography 

You may have noticed that an additional set of commands in the make file and alias commands above: there was a call to a program called bibtex followed by another call to latex.  Acedemic integrity demands we cite other work upon which our work is based.  To do this in latex, we add a reference section by adding the following lines before the end of the document:
	\bibliographystyle{abbrv}
\bibliography{refs}
Then inside the text, we can cite any document from the refs.bib file:
	Linking search topology analysis with algorithm performance has
contributed to researchers' understanding of search algorithms and
heuristics. It leads to insights such as \emph{the search space for
an oversubscribed scheduling application is dominated by large
plateaus} \cite{barbulescuEtAl06.jair.understandingAlg}, \emph{the
search space of job shop scheduling is dominated by many small local
minima} \cite{watson03IJAR}, \emph{the search space of SAT depends on
the problem instance}
\cite{frankCheesmanStutz97.jair.whenGravityFails} , and in
domain-independent planning, \emph{the search spaces are often
trivial} \cite{hoffmann04.book.utilizingProbStructure}. Researchers
have used these insights to both construct simpler algorithms and
explain algorithm behavior. In some cases, the explanations reveal
how these algorithms yield such dramatic improvements while still
guaranteeing bounded computation
\cite{chen01formal,hoosStutzle04.book.SLS}.
You will also need to add the refs.bib file to your growing collection of files.  Open the file and you will note a very easy way to add references to the paper.  For more info on using Bibtex, see my bibliography notes.

General Tips

Use a good text editor that has syntax highlighting; lyx is okay for a quick document but it tends to produce awfully hard to read latex output.

Start with a basic document that is close to what you want then modify the document.

Add some good tutorials and informative documents  to your toolbox (you do have a toolbox, right?)

Keep a latex-one-liner.txt file so you can quickly access tricks you have already figured out.

Use a reference card for latex while you are learning. Otherwise you'll go nuts!

Compile frequently so bad changes are found quickly

Save often as you can (sometimes) blow away an entire section with some silly command that is difficult to debug.

As soon as you learn the bare minimum of latex commands, get on the net and find some examples of good documents.  Feel free to use an old copy of latex docuements.   You'll probably want to take some asprin before opening the tarball.