This question already has an answer here:

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.

\theoremstyle{plain}% default









  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$.

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.

  \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$.

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

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 6
    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,…. The advantage of \autoref is that the arxiv accepts it. – Andrew May 7 at 9:41
  • Thanks for mentioning cleveref. I'll pose more specific questions about it separately. – Jim Newton May 7 at 13:59