# Auto recognize reference types [duplicate]

Possible Duplicate:
How to get more complete references

Is there a way to recognize cross-reference types automatically in LaTeX? For example, see the code below

\begin{lemma}\label{triangle}%

$a^{2}=b^{2}+c^{2}\text{.}%$

\end{lemma}

\begin{theorem}

\bigskip From \ref{triangle}, we have
$E=mc^{2}\text{.}%$

\end{theorem}


As you see, when I reference the lemma in the theorem, the LaTeX only displays the number of the lemma in the compiled pdf file. In fact, I hope LaTeX can recognize reference types. For e.g., when I reference a lemma, then LaTeX displays automatically both lemma and its number (such as lemma 2.1, not just the number 2.1 of this lemma) in the compiled pdf file; when I reference a theorem, then LaTeX automatically displays both theorem and its number (such as theorem 3.7, not just the number 3.7 of this theorem ) in the compiled pdf file.

-

## marked as duplicate by Roelof Spijker, Torbjørn T., Stefan Kottwitz♦Nov 30 '11 at 9:05

Better avoid empty lines before and after displayed equations, this can cause undesired additional vertical space. equation have already their own spacing, you don't need to break a paragraph by an empty line. –  Stefan Kottwitz Nov 30 '11 at 7:40
Looks like a dupe to me –  Joseph Wright Nov 30 '11 at 8:54
@user9701 Have a look at the question linkes by whlt3. Since it's very similar, we will close this question. In such cases a question can be reopened if it's edited with new, different information. –  Stefan Kottwitz Nov 30 '11 at 9:05

You could use the cleveref package for this. It is able to automatically determine the format of references according to the type of reference. By \crefname you can specify singular and plural versions of the name you would like to use.

\documentclass{article}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\crefname{lemma}{lemma}{lemmas}
\usepackage{amsmath}
\begin{document}
\begin{lemma}\label{triangle}%
$a^{2}=b^{2}+c^{2}\text{.}%$
\end{lemma}
\begin{theorem}
\bigskip From \cref{triangle}, we have
$E=mc^{2}\text{.}%$
\end{theorem}
\end{document}


-
I posted the answer before I noticed the duplicate. I still let it here for the OP for now. –  Stefan Kottwitz Nov 30 '11 at 9:08