1

In algorithm2e how can I use the function name (as printed/ style) in the caption and any other part of the document. I notice using the "\FUNNAME" ,in general, sometimes works and sometimes do not. In the example below using \GETMAX works in the document (sometimes) and does not work with the caption at all. Is there specific way to be able to resolve this issue ?

Example:

\documentclass{article}

\usepackage{epsfig}


\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\SetKwProg{Fn}{Function}{}{end}
\SetKwFunction{GETMAX}{getMax}
\begin{document}

\begin{algorithm}
\DontPrintSemicolon
\Fn{\GETMAX{atom, neighbour}} {
\KwIn{x }
\KwOut{max}
$max \gets x[1]$\;
\For{$i \gets 2$ \textbf{to} $n$} {
  \If{$x[i] > max$} {
    $max \gets x[i]$\;
  }
}
\Return{$max$}\;
}
\caption{\texttt{getMax}  isa  function }
\label{algo:getmax}
\end{algorithm}

Algorithm~\ref{algo:getmax} \GETMAX function I can not use same command inside the caption 



\end{document}
4

algorithm2e defines \GETMAX in a fragile way. This means that in commands which move their argument also to other places (the caption is move to the list of algorithm) it can break.

You should either protect the command:

 \caption{\protect\GETMAX  isa  function }

or make it robust:

 \usepackage{etoolbox}
 \robustify\GETMAX
  • many thanks that's work with me – AlKharusi Apr 20 '19 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.