[Tex/LaTex] Change name of algorithm

algorithmsnaming

I've been trying to use this answer Changing label name for algorithm to no avail. I use the packages:

\usepackage{algorithm}
\usepackage{algpseudocode}

And this code for defining new environment:

\newenvironment{megaalgorithm}[1][htb]{
    \renewcommand{\algorithmcfname}{MegaAlgorithm}% Update algorithm name
   \begin{algorithm}[#1]%
  }{\end{algorithm}}

But then it tells me that there is an error:

Latex Error: \algorithmcfname undefined

I can't use algorithm2e as in previous example as it breaks my current code.

Best Answer

The right one when using the algorithm package is \ALG@name and not \algorithmcfname.

So you have to define your new environment as

\makeatletter
\newenvironment{megaalgorithm}[1][htb]{%
    \renewcommand{\ALG@name}{MegaAlgorithm}% Update algorithm name
   \begin{algorithm}[#1]%
  }{\end{algorithm}}
\makeatother

MWE

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

\makeatletter
\newenvironment{megaalgorithm}[1][htb]{%
    \renewcommand{\ALG@name}{MegaAlgorithm}% Update algorithm name
   \begin{algorithm}[#1]%
  }{\end{algorithm}}
\makeatother

\begin{document} 

\begin{megaalgorithm}
\begin{algorithmic}
\State Hello
\end{algorithmic}
\caption{A mega algorithm}
\end{megaalgorithm}

\end{document} 

enter image description here


In algorithm.sty (part of the algorithms bundle) you can find:

\newcommand{\ALG@name}{Algorithm}

and

\floatname{algorithm}{\ALG@name}

So, another option is to define your new environment as

\newenvironment{megaalgorithm}[1][htb]{%
    \floatname{algorithm}{MegaAlgorithm}% Update algorithm name
   \begin{algorithm}[#1]%
  }{\end{algorithm}}

The first method is taken directly from the style file, while the latter can be found in subsection 4.4, "Customization", of the algorithms documentation