I am using cleveref pointing to equations within my document, as well as to a technical appendix in a separate file (loaded by \externaldocument)
Setup
Lets that the the first file was in main.tex
, compiled, etc.
\documentclass{article}
\usepackage[capitalise,noabbrev]{cleveref}
\crefname{equation}{}{}
\newtheorem{proposition}{Proposition}
\begin{document}
\section{MyTitle}\label{sec:mytitle}
\subsection{MySub}\label{sec:sub}
\begin{equation}
A = b\label{eq:ab}
\end{equation}
\end{document}
And another file references this, compiled after main
\documentclass{article}
\usepackage[capitalise,noabbrev]{cleveref}
\crefname{equation}{}{}
\usepackage{xr}
\externaldocument[main:]{main} %Loads a doc for external
\begin{document}
\section{My section}\label{sec:mysection}
\begin{equation}
B = C\label{eq:bc}
\end{equation}
local ref: \cref{sec:mysection}, external ref: \cref{main:sec:mytitle} and \cref{main:sec:sub}\\
local eq ref: \cref{eq:bc}, external ref: \cref{main:eq:ab}
\end{document}
Question: The above should work, but while reading there is no way for me to know if a reference is to the external (technical appendix) in my case, or to an internal link.
Is there any way to have \cref
conditionally change the text if a file is external (e.g. set something up so that if the refered label begins with main:
then add a Main
to the beginning of the title, etc.) That technique should work for sections, propositions, figures, but perhaps not for equations, which have the form (1)
in this setup. Ideally this would show up as Main (1)
or (Main 1)
... whichever works, though I think the latter is a little clearer.
Extention with xr-hyper
Something different will be necessary to get this to work with the related xr-hyper
and hyperref
packages. I don't care of the hyperlinks actually work between documents or not, the test is:
In file main.tex
\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}
\crefname{equation}{}{}
\begin{document}
\section{MyTitle}\label{sec:mytitle}
\begin{equation}
A = b\label{eq:ab}
\end{equation}
\end{document}
and in the separate file:
\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}
\externaldocument[main:]{main1}
\begin{document}
\section{My section}\label{sec:mysection}
\begin{equation}
B = C\label{eq:bc}
\end{equation}
Local ref: \cref{sec:mysection}, external ref: \cref{main:sec:mytitle}
Local eq ref: \cref{eq:bc}, external ref: \cref{main:eq:ab}
\end{document}