# how to reference problems by the text label in an exercise envioronment

I am using the exercise package, as illustrated in the following example:

\begin{Exercise}[
title={blah},
label={modernOpticsLecture2:pr2}
]
foo
\end{Exercise}


I can put a reference to this problem by doing something like:

In \ref{modernOpticsLecture2:pr2} we show that


which shows up with a 2.2 hyperlink:

In 2.2 we show that


but would prefer the reference include a bit more text (i.e. prefixed by exercise) like so:

In Exercise 2.2 we show that


For now I've just prefixed by \ref with the text 'Exercise', but noticed that in my .aux file I have something like:

\newlabel{modernOpticsLecture2:pr2}{{2.2}{38}{Problems\relax }{Exercise.2.2}{}}


which seems to imply that there's probably a way to directly reference this by the Exercise.2.2 name that's tucked away in the .aux file encoded using this \newlabel command.

I was wondering how that would be done?

-
I've updated my answer showing how to use cleveref together with the exercise package. –  Gonzalo Medina Oct 8 '12 at 3:47

The cleveref package automatically generate this kind of format for cross-references. Instead of using \ref, you now use \cref (or \Cref at the beginning of a sentence.)

You have to make cleveref aware of the Exercise environment from the exercise package; this can be done using the \crefname (for \cref) and \Crefname (for \Cref) commands:

\crefname{<type>}{<singular>}{<plural>}
\Crefname{<type>}{<singular>}{<plural>}


A little example:

\documentclass{article}
\usepackage{exercise}
\usepackage{cleveref}

\crefname{Exercise}{Exercise}{Exercises}
\Crefname{Exercise}{Exercise}{Exercises}

\begin{document}