Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

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
add comment

2 Answers

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}
share|improve this answer
    
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
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.