My LaTeX Notes


WHERE TO FIND LATEX PACKAGES:

There are many, many latex packages available on the web. If you're looking for a way to do something in latex, chances are you can find the package at ctan.org or a mirror site.

LOCAL DOCUMENTATION:

To see if a latex package is installed on your system, look for <package name>.sty. Oftentimes there is a corresponding DVI documentation file; look for <package name>.dvi or <package name>.dvi.gz.

USEFUL LATEX PACKAGES:

enumerate   [example]
Allows for different numbering styles for enumerated lists. The style is specified as an optional argument to the enumerate command.

longtable   [example]
Does page breaking for tables that span more than one page. Syntax is similar to regular tables except that you also specify a header and a footer for each page.

pseudocode   [example]
For displaying formatted pseudocode. I modified the pseudocode style file to give it a format that I found to be better. You can get this file from here.

rotating
Provides the commands sidewaysfigure and sidewaystable which work the same as figure and table respectively except that they print the figure/table in landscape rather than portrait mode. Note that the captions won't show up rotated in the DVI file but will in the postscript file.

subfigure
Provides the command subfigure which can be used within the figure environment.

url
Performs appropriate line breaking for urls. Doesn't always work great, but does a pretty decent job.

Example:
 \url{http://www.npaci.edu/Horizon}

xspace   [example]
Use at the end of a macro. It adds a space unless the macro is followed by specific punctuation characters.

WRITING LATEX COMMANDS:

Defining a command:

A latex command can be defined as follows:

\newcommand{\<name of command>}{<body>}

For example,

    \newcommand{\twok}{$2k \times 2k$\xspace}
    

See above for explanation of xspace. Or

    \newcommand{\starttext}
    {
      \pagenumbering{arabic}
      \setcounter{page}{1}
      \pagestyle{plain}
    }
    
Using a command:

To use a command that you defined, just type

\<name of command>

within the text. For example,

        for the \twok experiments.  We also found that the
        
or
        \starttext
        
Arguments:

You can also have arguments in your commands like a function. You specify the number of arguments as an optional argument to \newcommand. You can then access them using #<arg_num>. For example,

\newcommand{\setcenterfigwidth}[1]
{
  \renewcommand{\@fig@spec}{width}
  \setlength{\@fig@scalar}{#1}
}
           

You can also have one optional argument. To specify, use the second optional argument to \newcommand. This also allows you to specify the default value of the optional argument. For example,

\newcommand{\landscapefig}[4][width=\textheight]
{
  \begin{sidewaysfigure}[htbp]
  \centering
  \epsfig{file=figures/#2.eps,#1}
  \caption[#4]{\label{#2}#3}
  \end{sidewaysfigure}
}
           

The first argument (i.e. #1) will be the optional argument. The required arguments follow in order.

MY FIGURE PACKAGE:

I wrote a small package that simplifies the use of figures for me. It is available here. It provides the following commands:

setfiguredirectory

\setfiguredirectory{DIRECTORY} sets the figure directory to DIRECTORY. This package will then look for all figures in DIRECTORY. The default figure directory is '.'.

centerfig
  [examples]

\centerfig[OPT]{FILENAME}{CAPTION}{TOC CAPTION} centers a eps figure. The label for the figure will be FILENAME.

OPT is a spec string argument to epsfig. E.g. width=4in, height=5in. Note that OPT will overide the default spec string 'height=3.65in'

FILENAME is the name of the eps file without the .eps. Default is to look for the figure in the current directory unless it has been reset with \setfiguredirectory.

CAPTION is the caption for the figure.

TOC CAPTION is the caption that will be displayed in the document's table of contents

pairfig
  [example]

\pairfig{FILENAME1}{FILENAME2}{CAPTION}{TOC CAPTION} inserts a a pair of figures on a single page one on top of the other. The figures will have sublabels (a) and (b) respectively.

FILENAME1 is the name of the first eps file without the .eps.

FILENAME2 is the name of the second eps file without the .eps.

CAPTION, and TOC CAPTION are described in centerfig.