# Referencing theorems (while including the theorem caption)

I would like to cite my Theorems with the kind of Theorem (Corollary, Proposition, etc...). Actually when I refer to a theorem I have to type Theorem \ref{name}. I have seen in few papers that it is possible to avoid 'Theorem' and juste type \ref{name}. Cleveref doesn't work well since I use ntheorem.

But I found a solution here cleveref for theorems with same type

for the users of ntheorem. However it doesn't work well in the following minimal example and I'm not able to find the error.

\documentclass[10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{mathptmx} % Times
\usepackage[scaled=0.90]{helvet}  % Helvetica, scaled 92%
\usepackage{courier}
\setlength{\parindent}{0cm}
\usepackage[all]{xy}
\usepackage{enumitem}
\usepackage[a4paper,twoside]{geometry}
\usepackage{amsmath,amssymb,mathrsfs}%symboles maths,polices loc différentes

%Théorèmes
\usepackage[hyperref]{ntheorem}

\theorembodyfont{\itshape}
\theoremindent0cm
\theorempreskip{0.8cm}
\theorempostskip{0.8cm}
\newtheorem{theo}{Theorem –}[section]
\crefname{theo}{Theorem}{Theorems}
\crefalias{theo}{Theorem}}

\begin{document}

\begin{theo}[Existence and uniqueness (1)]\label{existuniq1}
Let $m >1$.

\end{theo}

\cref{existuniq1}

\end{document}


Astonishingly, it seems that this very basic question has not been asked in this form here yet. So here is an answer:

A choice might be the cleveref package.

The cleveref package enhances LATEX’s cross-referencing features, allowing the format of cross-references to be determined automatically according to the “type” of cross-reference (equation, section, etc.) and the context in which the cross-reference is used.

(from the package documentation)

The cleveref package might even be the best choice. It behaves well in most situations and, for instance, the issue mentioned by @barbarabeeton is easily fixed using cleveref.

Assuming you set up a theorem environment like

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}


then you would reference it (getting the theorem caption "for free") with the \cref command. (The theorem environment can be also defined via ntheorem.)

\begin{theorem}\label{thm:foo}
Foo bar.
\end{theorem}

\cref{thm:foo}


The cpation is typeset uppercase when toggling the 'capitalize' option. The links are produced employing hyperref with options 'colorlinks' and 'linkcolor=DeepSkyBlue2' where 'DeepSkyBlue2' is a x11names color from xcolor. You finally need to specify the 'nameinlink' option in cleveref to get the reference colored completely.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\usepackage[x11names]{xcolor}

\begin{document}
\begin{theorem}\label{thm:foo}
Foo bar.
\end{theorem}

\cref{thm:foo}
\end{document}


That's not exactly a minimal working example... (See [1].)

Anyway, the problem is that you enclosed the lines

{\theoremheaderfont{\scshape}
\theorembodyfont{\itshape}
\theoremindent0cm
\theorempreskip{0.8cm}
\theorempostskip{0.8cm}
\newtheorem{theo}{Theorem –}[section]
\crefname{theo}{Theorem}{Theorems}
\crefalias{theo}{Theorem}}


in curly brackets, thus forming a group. This means that any definitions made within this group will be local (i.e. only visible within the group), unless it is specified that the definition should be global. [2]

The above refers to bare TeX definitions, i.e. \def, \edef, \let and such. More advanced LaTeX commands from included packages can also define various macros, which might be local or global, depending on the implementation of the package. Apparently commands like \newtheorem are global, but \crefname is local.

Remove the curly brackets to get the code working:

\theoremheaderfont{\scshape}
\theorembodyfont{\itshape}
\theoremindent0cm
\theorempreskip{0.8cm}
\theorempostskip{0.8cm}
\newtheorem{theo}{Theorem –}[section]
\crefname{theo}{Theorem}{Theorems}
\crefalias{theo}{Theorem}