# autoref for algorithms

\usepackage{algorithm,algpseudocode}
\usepackage{hyperref}


So when I

\begin{algorithm}
\caption{Baseline}\label{ALG_baseline}
\begin{algorithmic}[1]
...
\end{algorithmic}
\end{algorithm}


the output will look somewhat like this:

--------------------------------------
Algorithm 1: Baseline
--------------------------------------
...
--------------------------------------


So obviously, there IS a counter, already.

But

\autoref{ALG_baseline} is simply linked to with a number.


will result int

[1] is simply linked to with a number.


How can I make autoref output

[Algorithm 1] is ...


• \newcommand{\algorithmautorefname}{Algorithm}, assuming that the counter is named algorithm. Please post a compilable document, not just fragments.
– user31729
Jun 7 '16 at 12:23

\autoref does only work completely with a corresponding \....autorefname macro, i.e. \sectionautorefname etc.

hyperref extracts the reference information from its specific label information, where the relevant counter name is stored as well.

This means, if the counter is named foo, \fooautorefname must exist -- otherwise it's ignored (and a warning shipped to the console).

The algorithm environment has a counter of the same name, so

\newcommand{\algorithmautorefname}{Algorithm}


will provide hyperref with the correct information.

\documentclass{article}

\usepackage{algorithm,algpseudocode}
\usepackage{hyperref}

\newcommand{\algorithmautorefname}{Algorithm}

\begin{document}
\begin{algorithm}
\caption{Baseline}\label{ALG_baseline}
%\begin{algorithmic}[1]
%
%\end{algorithmic}
\end{algorithm}

\autoref{ALG_baseline} is simply linked to with a number.

\end{document}


Please note, that cleveref package provides a similar feature, however, the names must be setup as well, with \crefname{algorithm}{algorithm}{algorithms} etc.

Update

This addresses the comment by the O.P. about detecting names of counters.

An excerpt of the .log file:

The counter definitions are written to the .log file as c@foo=\countY, where Y is the number of a free counter register and not really important (apart from few exceptions.)

\@float@every@algorithm=\toks16
\c@algorithm=\count88


Later on, we find

\c@ALG@line=\count89
\c@ALG@rem=\count90
\c@ALG@nested=\count91
\ALG@tlm=\skip43
\ALG@thistlm=\skip44
\c@ALG@Lnr=\count92
\c@ALG@blocknr=\count93
\c@ALG@storecount=\count94
\c@ALG@tmpcounter=\count95
\ALG@tmplength=\skip45


This means, that ALG@line is (very likely) the line number counter.

However, it's a 'hidden' counter, due to @ usage in the name!

• Thank you. You say "the algorithm environment has a counter of the same name". How/Where do I find this information? Where would I find the name of the line-counter mentioned in its documentation? mirror.utexas.edu/ctan/macros/latex/contrib/algorithms/… Jun 7 '16 at 12:39
• @User1291: Look for \newcounter statements in the .sty file or have a look on the .log file , see my edits to my answer at the end, please
– user31729
Jun 7 '16 at 12:45
• +1. The cleveref package has known about the algorithm package since version 0.17. (Current version: 0.19 or so.) Both \Cref{ALG_baseline} and\cref{ALG_baseline} work right away -- no need for \crefname{algorithm}{algorithm}{algorithms}, etc.
– Mico
Jun 7 '16 at 13:15
• @Mico: Thanks, I should have looked into cleveref.cfg The better, others do not have to define the \crefname then
– user31729
Jun 7 '16 at 15:05
