10

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?

migrated from stackoverflow.com Mar 15 '12 at 12:51

This question came from our site for professional and enthusiast programmers.

  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. 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
11

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}
\Procedure{YourFunction}{$x$}
  \State Do Something
\EndProcedure
\end{algorithm}
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}
  • Welcome to TeX.sx! Your answer was migrated here from Stack Overflow. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy