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


\chapter{My chapter}
Take a look at the code in \autoref{lst:mylisting}.
  \caption{My listing}

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?


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


produces correct references.

  • 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 May 14 '13 at 11:56
  • This still seems to be necessary using MacTeX 2013 – Seán Labastille Aug 6 '13 at 9:56

Just for people that are using \usepackage{listings} instead of \usepackage{minted}. The following lines will do the following:


Will change both the caption to "Code 1.1: Blablabla" and the reference to "see foo in Code 1.1".


Will only change the reference to "see foo in code 1.1". While the caption remains unchanged, "Listing 1.1: Blablabla".

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.