4

What is the autoref command to reference a line number of an algorithm? I tried to define stepautorefname, linenoautorefname and alglinenoautorefname commands as shown below but they don't work like the algorithmautorefname command.

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}

\usepackage[hidelinks,
            colorlinks  = true,
            linkcolor   = blue,
            urlcolor    = blue,
            citecolor   = blue,
            anchorcolor = blue]{hyperref}


\newcommand{\algorithmautorefname}{Algorithm}
\newcommand{\stepautorefname}{Step}
\newcommand{\linenoautorefname}{Line}
\newcommand{\alglinenoautorefname}{ALine}

\begin{document}

\begin{algorithm}
\caption{Algorithm} \label{alg:A}
\begin{algorithmic}
\REQUIRE $Input$
\STATE A
\STATE B
\STATE C
\STATE D \label{step:A4}
\end{algorithmic}
\end{algorithm}


In \autoref{step:A4} of \autoref{alg:A}
\end{document}
2

The compilation log already gives a useful hint:

Package hyperref Warning: No autoref name for `ALC@unique' on input line 32.

So the command name prefix should be ALC@unique. We then only need to make sure the @ character is allowed in command names and can define

\makeatletter
\newcommand{\ALC@uniqueautorefname}{Line}
\makeatother

which yields the desired result.

enter image description here

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.