15

I am trying to define a function in LaTeX pseudocode, as shown below.

\begin{algorithm}
\begin{algorithmic}[1]
\Function{Increment}{$a$}
.....
\EndFunction
\end{algorithmic}
\end{algorithm}

However, when I compile, I get the error, undefined control sequence \Function{Increment}{$a$}. What mistake am I doing here and how can I solve it?

Werner
  • 603,163
  • Welcome to TeX.sx! Your question was migrated here from [so]. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Werner Mar 15 '12 at 15:35

2 Answers2

13

Like Vikram said: use algpseudocode from the algorithmicx package, it’s superior to the other pseudocode packages.

Then you can do the following:

\begin{algorithm}
\begin{algorithmic}
\Procedure{YourFunction}{$x$}
  \State Do Something
\EndProcedure
\end{algorithmic}
\end{algorithm}
Konrad Rudolph
  • 39,394
  • 22
  • 107
  • 160
5

use this:

\usepackage[noend]{algpseudocode}

or try the following:

\documentclass{beamer}
\usepackage{algorithmic}

\begin{document}

\begin{frame}
\begin{algorithmic}[1]
    \STATE Function\{Increment\}\{\$b1\$}
     .....
    \STATE EndFunction
\end{algorithmic}
\end{frame}

\end{document}
Vikram
  • 159
  • Welcome to TeX.sx! Your answer was migrated here from [so]. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or edit your answer. – Werner Mar 15 '12 at 15:35