Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to use autoref from the hyperref package to create a reference to a floating listing as provided by minted. This code

\documentclass[a4paper]{book}
\usepackage{minted}
\usepackage{hyperref}

\begin{document}
\chapter{My chapter}
Take a look at the code in \autoref{lst:mylisting}.
\begin{listing}[htb]
  \begin{minted}{erlang}
    foo
    bar
  \end{minted}
  \caption{My listing}
  \label{lst:mylisting}
\end{listing}
\end{document}

should produce something like Listing 1.1 with a link around it. I don't want to use Listing~\ref{lst:mylisting}, because it wouldn't be consistent with all the other links produced by autoref.

Any ideas?

share|improve this question

1 Answer 1

up vote 11 down vote accepted

The trick is to define a macro called \listingname or \listingautorefname which stores the name hyperref should use for the reference. In your case, adding the line

\providecommand*{\listingautorefname}{Listing}

produces correct references.

share|improve this answer
    
Works like a charm! Thanks a lot! –  3lectrologos Mar 17 '11 at 23:22
    
This doesn't seam to be necessary anymore –  white_gecko May 13 '13 at 14:20
    
sure? I had the exact same problem and my environment is up to date. –  Marc Mosby May 14 '13 at 11:56
    
This still seems to be necessary using MacTeX 2013 –  Seán Labastille Aug 6 '13 at 9:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.