[Tex/LaTex] Procedure name with small caps in algorithm2e

algorithm2ealgorithmscaptionsformatting

I know that procedure in algorithm2e only allows captions like \caption{ProcedureName()}.

However, I'd like my procedure to appear in small caps:

\documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[algosection, boxruled, linesnumbered]{algorithm2e}

\begin{document}
\begin{procedure}

    \SetKwInOut{Input}{input}
    \SetKwInOut{Output}{output}
    \Input{Graph $G = (V,E)$}
    \Output{}
    \ForEach{node $v \in V$}
    {
        \lIf{$v$ is marked}{remove $v$}
    }

    \caption{\textsc{removemarked()}}
    \label{alg:removemarked}

\end{procedure}
\end{document}

Which of course gives error

Paragraph ended before \algocf@captname was complete

Instead of procedure, if I use \begin{algorithm} ... \end{algorithm}, then it forks fine.
Is there a way to make it work in procedure as well?

Best Answer

It's not really well documented in algorithm2e manual, but to achieve what you want, you have to issue the command

\SetProcNameSty{textsc}

The argument of \caption when using the procedure environment can only contain something like name(arg).

In the following MWE I've also added

\SetProcArgSty{textsc}

just in case you are using procedure captions with arguments:

\documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[algosection, boxruled, linesnumbered]{algorithm2e}

\SetProcNameSty{textsc}
\SetProcArgSty{textsc}

\begin{document}
\begin{procedure}

    \SetKwInOut{Input}{input}
    \SetKwInOut{Output}{output}
    \Input{Graph $G = (V,E)$}
    \Output{}
    \ForEach{node $v \in V$}
    {
        \lIf{$v$ is marked}{remove $v$}
    }

    \caption{removemarked()}
    \label{alg:removemarked}

\end{procedure}
\end{document} 

Output

enter image description here