# How to make labels remember chapters?

I am using the amsbook package and the hyperref package. When say a definition is stated in Chapter 9, Section 3, Subsection 2, it is called "Definition 3.2", and when the hyperref package is used, it is recalled as "3.2" without mention to the chapter. How can I make it so the package recalls it as "IX 3.2"?

ADD It would be better if this is sensitive to the chapter we're in: if Definition 3.2 is recalled in section 5 of the same chapter, no distinction should be made, but if it is recalled anywhere in a different chapter, such distinction is needed.

MWE

\documentclass[a4paper,11  pt]{amsbook}
\usepackage[utf8x]{inputenc}
\usepackage{amsfonts,amssymb,amsmath}
\usepackage{hyperref}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lema}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem{deff}[theorem]{Definition}

\begin{document}
\chapter{Preliminaries.}
\section{Examples.}
\begin{deff}\label{def::connectedfoo} Define a foo to be connected if...
\end{deff}
\chapter{Stuff.}
In ~\ref{def::connectedfoo} we defined what a connected foo is. This will be of great use in...
\end{document}

• This type of question has been asked before. Regardless, can you provide the community with a minimal example that replicates your current behaviour? – Werner May 20 '16 at 19:07
• @Werner My apologies. If you want to, please link to a duplicate. – Pedro Tamaroff May 20 '16 at 19:08
• Here is a possible duplicate: Cross-referencing in multiple chapters If, for whatever reason, it doesn't work for you, provide the community with a MWE that supports that. – Werner May 20 '16 at 19:11
• @Werner I added a MWE. – Pedro Tamaroff May 20 '16 at 19:21

Use \p@theorem, the “prefix” to the reference number.

\documentclass[a4paper,11  pt]{amsbook}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\usepackage{hyperref}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lema}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem{deff}[theorem]{Definition}

\makeatletter
\renewcommand{\p@theorem}{\ref@chapter{\arabic{chapter}}}
\protected\def\ref@chapter#1{%
\ifnum#1=\value{chapter}%
\else
\@Roman{#1}\,%
\fi
}
\makeatother
\renewcommand{\thechapter}{\Roman{chapter}}

\begin{document}

\chapter{Preliminaries}
\section{Examples}
\begin{deff}\label{def::connectedfoo}
Define a foo to be connected if...
\end{deff}

Definition~\ref{def::connectedfoo} is nice.

\chapter{Stuff}

In~\ref{def::connectedfoo} we defined what a connected foo is. This will be of great use in...

\end{document}