# Cross reference lemma from one chapter in another chapter with the cleveref package

I tried

\documentclass[10pt]{amsbook}
\usepackage[francais,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}

\usepackage{xparse}
\usepackage{hyperref}
\usepackage{cleveref}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@thm}{\thm@notefont{\fontseries\mddefault\upshape}}{}{}{}

\usepackage{eufrak}
\usepackage{mathrsfs}

\theoremstyle{plain} %% This is the default, anyway
\newtheorem{thm}[equation]{Theorem}
\counterwithin*{equation}{subsubsection}

\renewcommand{\theequation}{%
\printuptozero{chapter,section,subsection,subsubsection}{equation}%
}

\newtheorem{lem}[equation]{Lemma}
\newtheorem{prop}[equation]{Proposition}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\printuptozero}{mm}
{
\clist_map_function:nN { #1 } \ujs_printuptozero:n
\arabic{#2}
}

\cs_new:Nn \ujs_printuptozero:n
{
\int_compare:nTF { \value{#1}>0 } { \arabic{#1}. } { \clist_map_break: }
}
\ExplSyntaxOff

\begin{document}

\chapter{First Chapter}

\section{First Section of First Chapter}

\begin{lem}\label{lemma_s_label}
stuff
\end{lem}

\chapter{Second Chapter}

\section{First Section of Second Chapter}

blah

\section{Second Section of Second Chapter}

blah blah

\begin{prop}
As we saw in \ref{lemma_s_label}
\end{prop}

\end{document}


which gives :

and :

I would have preferred something like As we saw in Chap. 1, Section 1, 1.1.1 rather than As we saw in 1.1.1 which is not helpful. Is there a way to achieve that with cleveref, or with other means that do not clash with the use of cleveref ?

• Al always on this site you are much more likely to get help if you provide a full but minimal self contained example, including document class, preamble etc. Basically such that others have something to copy and test as is. Here we have to guess, and that seldom goes well. Oct 14 '19 at 14:43
• @daleif I provided a minimal complete code. Oct 14 '19 at 15:01
• As a reader, I would find "As we saw in Chap. 1, Section 1, 1.1.1 ..." unbelievably tedious to read. I would much prefer to have to read either "As we saw in Lemma 1.1.1 ..." or (if can't be trusted to figure this out on my own...) "As we saw in Lemma 1.1.1 back in Chapter 1, Section 1, ...". What do you expect readers to get out of the "in Chapter 1, Section 1" affix? Are you anticipating that they'll understand the Lemma any better than without the affix?
– Mico
Oct 14 '19 at 15:09
• Have a look at Grothendieck's EGA's that you may have heard of, labels there are expressed in this fashion when they point to another chapter (i.e. a chapter different from the ambient one), and they are in fact expressed in an even more compact way. I don't find it tedious to read. (You expressed your opinion, I expressed mine, fantastic.) (Note that such references are inherently rare compared to others references, i.e. references points inside the ambient chapter.) Regarding your last question : yes I anticipated that they will understand the lemma better with the affix. (I am kidding.) Oct 14 '19 at 15:24