This is an approach that works if hyperref
is used (and also if it is not used) and sets the counter name according to the content of \algorithmcfname
and links correctly.
Just define a counter, say heuristics
and a macro \heuristicsname
which contains Heuristics
. If the counter is named foo, \fooname
must be defined as well.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{algorithm2e}
\usepackage{hyperref}
\newcommand{\heuristicsname}{Heuristics}
\newcounter{heuristics}
\makeatletter
\AtBeginDocument{%
\@ifpackageloaded{hyperref}{%
\let\orighyper@refstepcounter\hyper@refstepcounter%
\newcommand{\specialhyper@refstepcounter}[1]{%
\orighyper@refstepcounter{\@specialcountername}%
\renewcommand{\@currentHref}{\@specialcountername.\csname the\@specialcountername\endcsname}%
}
}{%
\providecommand{\autoref}[1]{\ref{#1}}
\newcommand{\specialhyper@refstepcounter}[1]{%
}
}
\newcommand{\specialcountername}[1]{%
\def\@specialcountername{#1}
}
\AtBeginEnvironment{algorithm}{%
\specialcountername{heuristics}%
\edef\temp@@a{\csname\@specialcountername name\endcsname}
\edef\temp@@b{\algorithmcfname}
\ifx\temp@@a\temp@@b
\csletcs{c@algocf}{c@\@specialcountername}
\csletcs{thealgocf}{the\@specialcountername}
\let\hyper@refstepcounter\specialhyper@refstepcounter
\fi
}
}
\makeatother
\begin{document}
\listofalgorithms
See \ref{algo} and \ref{heu} or \autoref{heu}
\begin{algorithm}
\KwData{foo}
\caption{Foo Algorithm} \label{algo}
\end{algorithm}
\SetAlgorithmName{\heuristicsname}{}{}
\clearpage
\begin{algorithm}
\KwData{foo}
\caption{Foo Heuristics} \label{heu}
\end{algorithm}
\end{document}

Update with improved setup
Use \SetupForOtherCounter{foo}{Foo}
to define the new counter name and a new name for the environment caption.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{algorithm2e}
\usepackage{hyperref}
\makeatletter
\newcommand{\SetupForOtherCounter}[2]{%
\@ifundefined{c@#1}{%
\newcounter{#1}%
}{}%
\@ifundefined{#1name}{%
\expandafter\newcommand\csname #1name\endcsname{#2}
}{%
\expandafter\renewcommand\csname #1name\endcsname{#2}
}%
}
\makeatother
\SetupForOtherCounter{heuristics}{Heuristics}
\makeatletter
\AtBeginDocument{%
\@ifpackageloaded{hyperref}{%
\let\orighyper@refstepcounter\hyper@refstepcounter%
\newcommand{\specialhyper@refstepcounter}[1]{%
\orighyper@refstepcounter{\@specialcountername}%
\renewcommand{\@currentHref}{\@specialcountername.\csname the\@specialcountername\endcsname}%
}
}{%
\providecommand{\autoref}[1]{\ref{#1}}
\newcommand{\specialhyper@refstepcounter}[1]{%
}
}
\newcommand{\specialcountername}[1]{%
\def\@specialcountername{#1}
}
\AtBeginEnvironment{algorithm}{%
\specialcountername{heuristics}%
\edef\temp@@a{\csname\@specialcountername name\endcsname}
\edef\temp@@b{\algorithmcfname}
\ifx\temp@@a\temp@@b
\csletcs{c@algocf}{c@\@specialcountername}
\csletcs{thealgocf}{the\@specialcountername}
\let\hyper@refstepcounter\specialhyper@refstepcounter
\fi
}
}
\makeatother
\begin{document}
\listofalgorithms
See \ref{algo} and \ref{heu} or \autoref{heu}
\begin{algorithm}
\KwData{foo}
\caption{Foo Algorithm} \label{algo}
\end{algorithm}
\SetAlgorithmName{\heuristicsname}{}{}
\clearpage
\begin{algorithm}
\KwData{foo}
\caption{Foo Heuristics} \label{heu}
\end{algorithm}
\end{document}
algorithm
environment? Do you change the Algorithm name each time before?\SetAlgorithmName
is wrong!