# Cross-references Showing Part Number

Is there a way to make cross references write \part number like this?

Cf. above Part 1, Page 3.

I am currently using: \here{}\label{} and \footnote{Cf. \where{}. Page \pageref{}.}

So I need something that would check in which part the label is and than write the number of that part in the footnote.

Edit: I thought that is not important re \where and \here but I am adding code for that as requested.

\makeatletter
\newcount\here@undef
\newcommand{\here}[1]{%
\global\@namedef{here@#1}{}%
}
\newcommand{\where}[1]{%
\@ifundefined{here@#1}{%
below%
\@ifundefined{here@#1@undef}{%
\global\@namedef{here@#1@undef}{}%
}{}%
}{%
above%
}%
}
\AtEndDocument{%
\ifnum\here@undef>0
\GenericWarning{}{There were undefined above/below labels}%
\fi}
\makeatother%

• I think this is some job for zref and refcount ... – user31729 Jan 3 '17 at 18:12
• How or where are the \here and \where macros defined? Which document class do you use? Do you load any cross-referencing packages? – Mico Jan 3 '17 at 18:40
• I use scrbook and hyperref. – eklisiarh Jan 3 '17 at 19:29

The package zref is made for such tasks: Extraction of label data, if the relevant \zlabel etc. commands are used.

In order to provide the correct information, a 'property' has to be stored, in this case the property is the part number which should be connected to the label.

The command \here stores the label with the given name using \zlabel@byprops and \there extracts the information later on.

 \documentclass{scrbook}

\usepackage[counter,user,hyperref]{zref}

\makeatletter
\AtBeginDocument{%
}{
\providecommand{\phantomsection}{}
}

\zref@newlist{partpage}
\zref@newprop*{partprop}[-1]{\number\value{part}}
\zref@addprops{partpage}{partprop,page,anchor} % page is defined by default!

\newcounter{herecntr}

\newcommand{\here}[1]{%
\phantomsection% Needed for correct hyper links
\zref@labelbyprops{#1}{partprop,page,anchor}%
}

\newcommand{\there}[1]{%
}
}
\makeatother

\usepackage{hyperref}

\usepackage{blindtext}

\begin{document}
Now, let us see\footnote{You will find in \there{firstref} some important information, but in \there{secondref} the information is much more important. Give it a try, but do not forget the stuff in \there{somethingdifferent}}

\part{My wonderful first part}

\blindtext[6] firstref\here{firstref}

\part{My second and yet better part}

\blindtext[7] secondref\here{secondref}

\part{My third and yet even better part}

\blindtext[3] thirdref\here{thirdref}

\chapter{Foo}\here{somethingdifferent}

\blindtext[2]

\end{document}


Update With compressed references, i.e. the \there command does not print the part number if the reference is in the same part!

\documentclass{scrbook}

\usepackage[counter,user,hyperref]{zref}

\makeatletter
\AtBeginDocument{%
}{
\providecommand{\phantomsection}{}
}

\zref@newlist{partpage}
\zref@newprop*{partprop}[-1]{\number\value{part}}
\zref@addprops{partpage}{partprop,page,anchor} % page is defined by default!

%\newcounter{herecntr}

\newcommand{\here}[1]{%
\phantomsection% Needed for correct hyper links
\zref@labelbyprops{#1}{partprop,page,anchor}%
}

\newcommand{\there}[1]{%
\ifnum\value{part}=\zref@extract{#1}{partprop}\relax% Check whether the current part counter value is the same as the extracted part property from the label
\else% No, it is not the same!
\fi
}
}
\makeatother

\usepackage{hyperref}

\usepackage{blindtext}

\begin{document}

\part{My wonderful first part}

Now, let us see\footnote{You will find in \there{firstref} some important information, but in \there{secondref} the information is much more important. Give it a try, but do not forget the stuff in \there{somethingdifferent}}

\blindtext[6] firstref\here{firstref}

\part{My second and yet better part}

\blindtext[7] secondref\here{secondref}

\part{My third and yet even better part}

\blindtext[3] thirdref\here{thirdref}

\chapter{Foo}\here{somethingdifferent}

\blindtext[2]

\end{document}

• @eklisiarh: You're welcome! Happy TeXing – user31729 Jan 4 '17 at 16:38
• Is it posible to slightly modify this so that in case the footnote is in the part in which is referenced it produces different output? For example if the footnote is in part 1 and cross reference is also in part 1 it produces just "Cf. P. 3" but if the footnote is in part 2 it produces "Cf. part 2, page 3."? – eklisiarh Jan 4 '17 at 18:13
• @eklisiarh: You mean 'compressed' references? I think, this is possible – user31729 Jan 4 '17 at 19:15
• @eklisiarh: See the update at the bottom of the answer – user31729 Jan 4 '17 at 19:24
• The updated version works perfectly in the MWE but doesn't in my file. I must find out why and if I do I will get back to you. Tx. – eklisiarh Jan 6 '17 at 8:36