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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following minimal example:



% \crefname{lstnumber}{line}{Line}


% \section{Section}

Lorem ipsum@\label{lineref}@

See \cref{lineref}: line~\ref{lineref}.


Compiling this document (twice) produces the warning

LaTeX Warning: cref reference format for label type `' undefined on input line 16.

And the output is:

See ??: line 1.

If I uncomment the \section{Section} line, everything compiles, and the reference comes out as

See section 1: line 1.

It seems that cleveref is picking up on the closest ambient reference for some reason, and not referring to the line number. Note that, in longer examples, the \ref command always produces the right line number.

The version of cleveref I'm using shouldn't need a manual \crefname{lstnumber}{line}{Line}, and indeed, uncommenting that doesn't change anything.

The relevant information from my log file is:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2011.7.11)  21 APR 2012 21:29
File: lstmisc.sty 2007/02/22 1.4 (Carsten Heinz)
File: listings.cfg 2007/02/22 1.4 listings configuration
Package: listings 2007/02/22 1.4 (Carsten Heinz)
Package: cleveref 2012/02/15{} v0.18.4{} Intelligent cross-referencing
Package cleveref Info: `listings' support loaded on input line 2843.
Package cleveref Info: loaded `english' language definitions on input line 6732

Any thoughts on what's going on, or how to fix it?

share|improve this question
up vote 10 down vote accepted

Try with the latest version v0.18.5. The changelog says

Fix listings and algorithm package support, broken by change to local rather than global \cref@currentlabel denitions....

From Gonzalo Medina's comment it seems that this solved it, but if it hadn't I'd say you should write to Toby Cubitt, author of cleveref with your MWE. He is very helpful and quite likely to make a bugfix.

share|improve this answer
Perfect! I thought I had the most up-to-date version, but clearly should have checked more carefully. Thanks! – Antal Spector-Zabusky Apr 22 '12 at 2:46

Your Answer


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.