Theorem~\ref{thm} states blahblah.


The problem here is that I have to manually type Theorem~. Almost always I have to type some name (Theorem, Lemma, Figure, etc.), which LaTeX can generate by itself in the point of definition. Is there a way to make latex write Theorem~ (and others) by itself?

\smartref{thm} states blahblah.

I don't want


, since I'll have to define similar macros for other types.

It's completely possible that I miss something obvious, but I had no success in googling.

  • 4
    Welcome to TeX.SX! I think you're looking for the cleveref package and \Cref{thm} states blahblah. Sep 27 '19 at 21:12
  • @PhelypeOleinik, thank you very much! Seems to work exactly like I want. By any chance, are you aware of any side effects / compatibility issues?
    – user181451
    Sep 27 '19 at 21:16
  • @PhelypeOleinik, never mind, this doc seems to cover it: tug.ctan.org/tex-archive/macros/latex/contrib/cleveref/…
    – user181451
    Sep 27 '19 at 21:17
  • 3
    Other than the fact it should be the last package to be loaded, none that I know of. The package it pretty good :-) Sep 27 '19 at 21:17

You have two main options: \cref (provided by the cleveref package) and \autoref (provided by the hyperref package).

Aside: If you don't want to make the cross-references into hyperlinks to their linked-to objects, just write \Cref*{...} and \autoref*{...} instead of \Cref{...} and \autoref{...}.

enter image description here

% 1. load 'hyperref' after `amsthm` but before 'cleveref' 
% 2. execute all `\newtheorem` statements *after* loading `cleveref`
\usepackage{amsthm} % or: \usepackage{ntheorem}

\setcounter{section}{2} % just for this example

\begin{theorem}\label{thm:bla} blah blah \end{theorem}

\Cref{thm:bla} states that \dots

As shown in \autoref{thm:bla}, \dots
  • Thank you! autoref doesn't seem to work for Lemmas: pastebin.com/3fzMxTSS
    – user181451
    Sep 27 '19 at 21:32
  • @dyukha - For theorem-like objects (such as lemma) whose labels are not yet defined by the hyperref package, just add an instruction such as \newcommand\lemmaautorefname{Lemma}, in the preamble.
    – Mico
    Sep 27 '19 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy