[Tex/LaTex] Write Procedure Name correctly formated in algorithm environment

algorithms

I want to call a function in an algorithm environment.

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
\caption{Recursion}

\begin{algorithmic}[1]
\Procedure{Recursion}{$a$}
    \State $a\gets Recursion(a)$ \Comment{Call Recursion again}
    \State \textbf{return} $a$ 
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}

What do I have to do to get the "correct" style for the word "Recursion" in the line \State $r\gets Recursion(a)$?

I tried something like \State $r\gets \Procedure{Recursion}{a}$, but only received errors.
The official documentation has no exmple regarding this problem.

Best Answer

I don't think that you can print the content of your procedure somewhere else as you have tried by \State $a\gets \Procedure{Recursion}{a}$.

You could do this by styling manually. You may use \textsc in math mode to do so. You can also add a \Comment (see in the example I provided). Instead of \textsc you may also use \Call. Sometimes either \textsc or \Call will not behave as expected.

% arara: pdflatex

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm}
\caption{Recursion}
\begin{algorithmic}[1]
\Procedure{Recursion}{$a$}
    \State $a\gets\Call{Recursion}(a)$ \Comment{Call Recursion again}
    \State \textbf{return} $a$ 
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

enter image description here