4

I'm using the package algorithm2e and create a list of algorithms with \listofalgorithms. My problem is that not only the algorithms (algorithm), but also the functions (function) are displayed in the list of algorithms.

Is it somehow possible that the function func() (see the following example) is not shown in the list of algorithms?

\documentclass{scrreprt} 

\usepackage{algorithm} 
\usepackage[ruled,algosection,algo2e]{algorithm2e} 

\begin{document} 

\begin{algorithm} 
\caption{Foo bar} 
 ... 
\end{algorithm} 

\begin{function} 
\caption{func()} 
... 
\end{function} 

\newpage 
\renewcommand*{\listalgorithmname}{Algorithmenverzeichnis} 
\listofalgorithms 
\clearpage 

\end{document} 
2

1 Answer 1

4

This behaviour is descriped in the documentation at page 17:

label now puts the name (the text before the braces in the caption) of the procedure or function as reference (not the number like a classic algorithm environment).

You can change it by redefining some internals of the package:

\makeatletter
\long\def\algocf@caption@proc#1[#2]#3{%
  \ifthenelse{\boolean{algocf@nokwfunc}}{\relax}{%
    \SetKwFunction{\algocf@captname#3@}{\algocf@captname#3@}%
  }%
  % we tell hyperref to use algocfproc as category and to take the appropriate ref.
  \ifthenelse{\boolean{algocf@func}}{\def\@proc@func{algocffunc}}{\def\@proc@func{algocfproc}}%
  \@ifundefined{hyper@refstepcounter}{\relax}{% if hyper@refstepcounter undefind, no hyperref, else...
    \ifthenelse{\boolean{algocf@procnumbered}}{% 
      \expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%if procnumbered, take \thealgocf as ref
    }{%
      \expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%else take procedure or function name
    }%
    \hyper@refstepcounter{\@proc@func}%
  }%
  \ifthenelse{\boolean{algocf@procnumbered}}{\relax}{%
    \addtocounter{algocf}{-1}% \caption do a refstepcounter, so we restore the precedent value
    \gdef\@currentlabel{\algocf@captname#3@}% let the label be the name of the function, not the counter
  }%
  \ifthenelse{\equal{\algocf@captparam#2@}{\arg@e}}{% if no paramater, we remove the ()
    \algocf@latexcaption{#1}[\algocf@captname#2@]{#3}%
  }{%                                                 else we give the complete name
    \algocf@latexcaption{#1}[#2]{#3}%
  }%
}%
\makeatother

I removed the following statement:

\algocf@procname\nobreakspace

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .