Workin' It: Packages
Need more features? LaTeX is expandable. There are a lot of additional features (commands) that come with MiKTeX, but to use them, you have to warn LaTeX with the \usepackage command. For example, if you want to use AMS symbol codes like \blacksquare, then you need to add\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
to the header. Of course, you can
add all four of these at once with
\usepackage{amsfonts,amsmath,amssymb,amsthm}
Other useful packages allow you to
set page margins easily (geometry),
double space (doublespace),
change to any size font (scalefnt),
wrap text around figures (wrapfig),
make a patch of graph paper (graphpap),
and draw big circles (bigcircle).
There are lots of other packages. Many packages come with a basic installation or are installed as needed, but some need manual installation.
Set page margins easily (geometry)
To get the standard "1 inch margins" put this in your header:\usepackage[margin=1in]{geometry}
This package lets you do fancier things relating to margins and page dimensions, so it's
worth checking out the documentation (click on the 'geometry' link above and check out
the manual.
Double space (doublespace)
Put this in your header:\usepackage{setspace}
Then put \doublespace to start double-spacing, \onehalfspace to start
one-and-a-half spacing, and \singlespace to return to normal spacing.
Change to any font size (scalefnt)
First add this to your header:\usepackage{scalefnt}
To make text twice the base size (10, 11 or 12 pt) add \scalefont{2}.
To change it back, add \scalefont{.5}. For example,
This text is normal. \scalefont{2} This text is
large. \scalefont{.5} This text is again normal.
Note that to get back to the base font size you do not add scalefont{1},
which does nothing. This presents problems if you change to a size that does not have a
nice decimal reciprocal. For example, \scalefont{3} then \scalefont{.33}
do not get you back to exactly the same size as the base font. Over repeated changes
this can mess up the document's font size.
The sure way to get back to the base font size exactly is to use \normalsize. For example,
This text is normal. \scalefont{3} This text is
large. \normalsize This text is again normal.
Wrap text around figures (wrapfig)
Usually a figure or table is given the entire width of the page, but sometimes you want to have text wrap for several lines next to a figure before the text continues below. This package enables this feature. Take a look at the contents of the style file. There are brief instructions at the top of the file, then a lot of programming gibberish, but the last half of the file are some reasonably readable and detailed directions. If you want to use this, I'd take a look there.A related topic is letting tables and figures "float" to the tops of pages and to have LaTeX automatically number them and preserver references to them. Other pages on this site discuss floats and references.
Graph Paper (graphpap)
For example, if you want to generate a grid like on graph paper, insert the line\usepackage{graphpap}
in the header. This allows you to add a
block of nicely labeled graph paper using just the code
\setlength{\unitlength}{3mm}
\graphpaper[5](-5,-10)(30,20)
This will draw
The \setlength line specifies how big each unit is. The [5] indicates how often to draw darker lines, the (-5,-10) sets the lower left corner, and the (30,20) sets the overall width and height.
Draw big circles (bigcircle)
There are good tools like jPicEdt for drawing pictures that you can easily embed in LaTeX, but I have found it useful sometimes to create figures natively in LateX's picture environment. It has a circle command, but it does not support drawing circles larger than about 3 cm (1 in). On the source samples page you can download (surprise!) sample code for using this bigcircle package I wrote. It allows you to draw a circle by setting the x and y-value of the center and the radius.Other packages are available, including:
- multicol: introduces the environment multicols which switches to multi-column output without a page break.
- longtable: makes tables that extend over several pages, with breaks occuring automatically
- array: adds features to the tabular environment (used to make arrays)
My favorite extra environments include:
- diagrams: One of several great packages for drawing simple or very complicated commutative diagrams. If you want to draw commutative diagrams, check out this article comparing different packages for doing so.
- qed: Inserts the symbols we use at the end of proofs -- somehting you would think would be easy.
Installing packages
A package usually consists of a style file. For example, the "foo" package would be a file foo.sty and perhaps another file or two. Usually all you need is the style file.To use it, you can just have it in the same directory as your LaTeX source file, but this gets tiresome keeping multiple copies everywhere. You can put it in one place and have it available to every document on your computer.
Where do I put it? Find the directory where you installed MiKTeX. If you accepted the default location, you will have a directory named C:\TEXMF\. Where ever it is, look for the directory TEX, then under that find LATEX. Again, the default would be C:\TEXMF\TEX\LATEX\. In that LATEX directory, create a directory with the same name as the package. (It's not necessary that it have the same name, but it keeps things neat.) Put the style file (and any accompanying files) in that directory. For example, for the foo package in a default installation I would create the directory C:\TEXMF\TEX\LATEX\FOO\ and put foo.sty in there with any accompanying files.
How do I make MiKTeX see this new package? Now under the Start Menu and in some subfolder with the rest of the MiKTeX stuff is a program called "MiKTeX Options." Run this. Under "File name database" there is a button, "Refresh Now." This will take a minute or so, but once it's done, the package is installed.
Now what? How do I use it? Each package has its own instructions, but usually all you have to do is include a line like this
\usepackage{foo}
to be able to use commands from the foo package.