# Can cross references automatically include the environment type? [duplicate]

In my LaTeX document I've defined several environments for various types of entities: theorem, lemma, corollary, definition, notation, and example.

And in the text when I reference one of them I have to add a descriptive word such as the following.

As we see in Lemma~\ref{lemma.100} and Theorem~\ref{theorem.105}, any such set is finite.


The problem is that from time to time, I change my mind about whether a certain entity should be a lemma or a theorem or a corollary etc. I can easily change the definition site from \begin{lemma}...\end{lemma} to \begin{theorem}...\end{theorem}, but then I need to change all the use-sites as well.

Is there a better way? Can I somehow define my lemma, theorem etc environments so that I can use a reference such as \envref{ent.100} and that will expand to Lemma~\ref{ent.100} if ent.100 is a lemma, but expand to Theorem~\ref{ent.100} if ent.100 is a theorem?

The same problem exists for tables and figures, but somewhat less often.

I'm not sure if it is important, but here is how I'm defining my environments currently.

\documentclass[a4paper]{article}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{framed}
\theoremstyle{plain}% default
\newtheorem{prototheorem}{Theorem}[section]

\newenvironment{theorem}

\newtheorem{protolemma}[prototheorem]{Lemma}
\newenvironment{lemma}

\newtheorem{protocorollary}[prototheorem]{Corollary}
\newenvironment{corollary}

\theoremstyle{definition}
\newtheorem{protonotation}{Notation}[section]
\newenvironment{notation}

\newtheorem{protoexample}{Example}[section]
\newenvironment{example}

\newtheorem{protodefinition}{Definition}[section]
\newenvironment{definition}

\begin{document}

\section{Introduction}

\begin{lemma}
\label{ent.201}
If $V$ is a set of subsets of $U$, and $\exists X_0 \in V$ such that
$X \in V$ implies $X_0 \subseteq X$, then $X_0 = \bigcap V$.
\end{lemma}

Intuitively, Lemma~\ref{ent.201} says that given a set of subsets,
if one of those subsets happens to be a subset of all the given
subsets, then it is in fact the intersection of
all the subsets.

\begin{theorem}
\label{ent.188}  %% used
If $V \subseteq U$, and if $F$ is a set of binary functions defined on
$U$, then there exists a unique $clos_F(V)$, and it is closed under $F$.
\end{theorem}

We can see from Lemma~\ref{ent.201} and also from
Theorem~\ref{ent.188} such sets are always finite.
2
\end{document}


## marked as duplicate by Mico, Kurt, Sebastiano, Stefan Pinnow, Phelype OleinikMay 7 at 10:59

• The cleveref package is done for that. It defines a \cref and a \Crefcommands and manages ranges of references. Note it must be loaded after hyperref. – Bernard May 7 at 8:51
• The other option is to use \autoref from \hyperref. See, for example, tex.stackexchange.com/questions/46258/…. The advantage of \autoref is that the arxiv accepts it. – Andrew May 7 at 9:41