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 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?

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

1 Answer 1

up vote 4 down vote accepted

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}

The reader is asked to demonstrate this fact in~\cref{modernOpticsLecture2:pr2}.
\begin{Exercise}[
title={Some exercise},
label={modernOpticsLecture2:pr2}
]
Test exercise
\end{Exercise}

\end{document}

enter image description here

share|improve this answer

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.