# Include Chapter number in reference if target is in different chapter [duplicate]

I'm using a setup where the chapter numbers are in Roman and the normal referencing commands do not include a chapter reference:

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}


As long as I'm referencing content in the same chapter everything is fine, however, sometimes (not very often) I reference content from a different chapter. In these rare cases I manually add in \Cref{chap:Chapter-Ref} to the reference. Obviously this is both cumbersome and prone to error!

As you can already see, I'm using cleveref, however, it appears it is not clever enough to automagically detect that it should insert a chapter reference when I'm referencing cross-chapter. I would assume that it has all the required information buried somewhere deep in its internals. After reading its documentation I am no wiser nonetheless: If there is some solution apparent in there, I missed it.

How can I [read: you ;-) ] change the reference command such that it inserts a chapter reference whenever the target of a reference command is in a different chapter?

I have tried to obtain a first solution using the mechanisms provided by the zref package, however, I failed miserably.

Below you'll find a tiny MWE for convenience :-)

\documentclass{scrbook}

\usepackage{hyperref}
\usepackage{cleveref}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}

\begin{document}
\chapter{First Chap}
\label{chap:foo}
\Cref{chap:foo} should print \textit{Chapter I}. \Cref{chap:foo} should print \textit{Chapter II}. \Cref{sec:foo} should print \textit{Section 1}.
\section{A Section}
\label{sec:foo}

\chapter{Scnd Chap}
\label{chap:bar}

\Cref{chap:foo} should print \textit{Chapter I}. \Cref{chap:foo} should print \textit{Chapter II}. \Cref{sec:foo} should print \textit{Section 1 in Chapter I}.

\end{document}

• Indeed a duplicate although this one is much older than the duplicate ;-) – elemakil Feb 6 '17 at 15:01