views:

45

answers:

1

Hi,

Im trying to write an algorithm using the algorithm package, but when I use any keyword (if, while, state, etc) it won't compile

Here's what I type in (snippet)

\documentclass[9pt]{article}
\usepackage{algorithm}
\begin{document}

\begin{algorithm}
\caption{Calculate $A_{nxn}$}
\label{Algorithm 1}

\IF{$n<0$}
\STATE $x \leftarrow X$
\ENDIF


\end{algorithm}

\end{document}

geometry auto-detecting driver *geometry detected driver: pdftex* (/usr/share/texmf/tex/context/base/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] ! Undefined control sequence. l.94 \IF {$n<0$} ? q

update

These are all the packages i'm using.

\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{url}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{algorithm}

\usepackage{multicol}
\usepackage{algorithmic}

\usepackage{fancyhdr}

Any thoughts? I'm kind of lost.

Thanks in advance.

+6  A: 

Take a peek here: http://en.wikibooks.org/wiki/LaTeX/Algorithms_and_Pseudocode

Are you missing a \begin{algorithmic} declaration, perhaps? From the examples, it appears that \begin{algorithm} is a container for the actual algorithmic environment where the work takes place...

\documentclass[9pt]{article} 
\usepackage{algorithm} 
\begin{document} 

\begin{algorithm} 

\caption{Calculate $A_{nxn}$} 
\label{Algorithm 1} 

\begin{algorithmic}

\IF{$n<0$} 
\STATE $x \leftarrow X$ 
\ENDIF 

\end{algorithmic}
\end{algorithm} 

\end{document}

That wiki page also includes a link to the official algorithms manual (PDF).

djacobson
Thanks, will turn on my brain next time before asking.
Tom
Could you tell us exactly which package you are using (e.g., provide a URL)? I would originally have given you an answer along the lines of @djacobson's answer, and I'm not sure which other algorithm-related package you are using.
Andrew
Andrew, I'll list all of the packages im using in my question.
Tom