# algorithm2e, function, procedure, \par, error

This is fine:

\documentclass{article}
\usepackage[boxed]{algorithm2e}

\begin{document}

\begin{algorithm}
$x \gets x$\;
\caption{Identity}
\end{algorithm}

\end{document}


But this, which uses the predefined environment "function" (p. 4 of the manual)

\documentclass{article}
\usepackage[boxed]{algorithm2e}

\begin{document}

\begin{function}
$x \gets x$\;
\caption{Identity}
\end{function}

\end{document}


produces this error

Runaway argument?
Identity@\endcsname ##1{\FuncSty {\algocf@captname Identity@(}\ArgSty \ETC.
./sandbox.tex:10: Paragraph ended before \algocf@captname was complete.
\par
l.10

? r
OK, entering \nonstopmode...
./sandbox.tex:10: Missing \endcsname inserted.
\par
l.10

)
! Emergency stop.


I use TexShop which (I believe) compiles with

simpdftex latex --maxpfb --extratexopts "-file-line-error -synctex=1"


Any help would be appreciate, I am out of ideas.

This is explained in page 17 of the documentation (talking about the procedure environment, but the same remark applies to function):

the syntax of the \caption command is restricted as follow: you MUST put a name followed by 2 braces like this Name(). You can put arguments inside the braces and text after. If no argument is given, the braces will be removed in the title.

A complete example:

\documentclass{article}
\usepackage[boxed]{algorithm2e}

\begin{document}

\begin{function}
$x \gets x$\;
\caption{Identity()}
\end{function}

\end{document}


• Thanks, I totally missed that in the manual. However, my precise problem is that my algorithm makes recursive calls and I need to make this clear in the algorithm environment. In the very least I want to move the caption to the top but \usepackage[boxed]{algorithm2e} produces (bizarrely) LaTeX Error: Unknown option boxedruled' for package algorithm2e'. despite it also being a valid option from the manual. Jul 27, 2013 at 16:28