This Link provides an answer to the question how to make line-number referencing work with lstlisting. However, if I use \autoref it will only return the number and not something like Line 31.
Asked
Active
Viewed 1,160 times
7
1 Answers
6
The \autoref command can't 'know' the ref name for each counter, this has to be provided as a separate macro:
I used the listings example by Marco Daniel provided in the Link by the O.P. and found that listings uses lstnumber as counter, so
\newcommand{\lstnumberautorefname}{Line}
is the relevant macro name to be defined (i.e. counter name + autorefname as suffix.
'Only' the standard counters such as chapter, etc, figure, page, table etc. are predefined. For a full list see the hyperref manual. Other packages might define additional \...autorefname macros.
Please have a look on the cleveref package too.
\documentclass{article}
\usepackage{listings}
\usepackage{hyperref}
\newcommand{\lstnumberautorefname}{Line}
\begin{document}
\lstset{escapeinside={(*@}{@*)}}
\begin{lstlisting}
for i:=maxint to 0 do begin
{ comment }(*@\label{comment}@*)
end;
\end{lstlisting}
\autoref{comment} shows a comment.
\end{document}
-
-
The cleverref package looks great but at this point I am afraid to change my hyperref setup to a cleverref setup as I do not know how much work that will be. – NOhs Aug 10 '15 at 15:42
-
@MrZ: As long as you include
clevereflater thanhyperrefeverything should be alright anyway. – Aug 10 '15 at 15:43

\autorefcan't provide for any label/counter entity. – Aug 10 '15 at 15:04