# How to compile pseudocode into pdf without margins?

I want to compile a pseudocode for an algorithm into a separate pdf and then include it into my main document as a figure. However, the compiled pseudocode gets compiled into a pdf with margins and I have not been able to crop it (other than manually) to fit into a tighter box. I used pdfcrop to try to get rid of the white space, but it only removes white space at the top, left, and right, but not the bottom. I would like to be able to compile it so that it has no margins and not to have to do it manually every time I change a comma in the pseudocode.
Here is an example:

\documentclass[10pt]{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[h!]
\begin{algorithmic}
\caption{Precomputing densities}
\label{alg:densities}
\FOR{$i = 1 \to n$}
\STATE $\mathrm{sums}[i][i] \gets 0$
\ENDFOR
\end{algorithmic}
\end{algorithm}
\end{document}


-
Does this post help? –  cmhughes Nov 3 '11 at 15:45
Tried using preview: produces an "Undefined control sequence." on the line with \begin{algorithm}. –  lynxoid Nov 3 '11 at 15:49
Your trimming via pdfcrop probably includes the page number. Use \pagestyle{empty} for such stand-alone instances. –  Werner Nov 3 '11 at 15:53
That's it - removing the page number allows pdfcrop to crop it properly! Thanks a lot! –  lynxoid Nov 3 '11 at 15:57
My hunch was to instead use the document class standalone but when I try it I get "LaTeX Error: Not in outer par mode." –  N.N. Nov 3 '11 at 16:00

\pagestyle{emtpy}

just below \begin{document}? This may get rid of something in the footer that pdfcrop is having trouble with.