2

My question is quite similar to the one asked here. Also, I found a solution using \ref here. I couldn't find a solution for \cref however.

The setting: I have large file with many chapters, which have many references between chapters, environments and equations. The references are created with \cref and usually include hyperlinks through the hyperref package.

The problem: Most of the time I only want some chapters in my pdf, but still want the references to work.

My idea: I store an .aux file of the full version in the file full.aux. Then I include it using the xrpackage. This works great so far, that my references are presented correctly. However (of course) there is no place to reference for the hyperlinks, so they just jump to the beginning of the document.

My question: Is ist possible to deactive these external hyperlinks completely, while keeping the internal ones? Use of \cref* doesn't make sense for me, as that would mean changing the full document, too.

And here a minimal example. This is a full document.

full.tex
\documentclass{article}

\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{xr}
\externaldocument{full}

\begin{document}
    First page\newpage
    Second page:
    \begin{equation}
    a=b \label{eq:firstequation}
    \end{equation}
    \begin{equation}
    c=d\label{eq:secondequation}
    \end{equation}
    \newpage
    \cref{eq:firstequation}
    \cref{eq:secondequation}
\end{document}

This is what my main document looks like.

main.tex
\documentclass{article}

\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{xr}
\externaldocument{full}

\begin{document}
    First page\newpage
    Second page:
    \begin{equation}
    a=b \label{eq:firstequation}
    \end{equation}
    \newpage
    \cref{eq:firstequation}
    \cref{eq:secondequation}
\end{document}

And this is what I want it to work like, but without explicit use of \cref*

full.tex
\documentclass{article}

\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{xr}
\externaldocument{full}

\begin{document}
    First page\newpage
    Second page:
    \begin{equation}
    a=b \label{eq:firstequation}
    \end{equation}
    \newpage
    \cref*{eq:firstequation}
    \cref{eq:secondequation}
\end{document}
1

1 Answer 1

0

With some more research it turned out, that any possible solution to my question above would mean a redefinition of standard commands in xr as well as cleveref. This does not seem to be an elegant approach to the problem.

Therefore, I came up with the following solution: I replaced \externaldocument{full} by \externaldocument[ext:]{full} and created my own reference command \myref, which acts as \cref for references, which are internal and \cref*{ext:#referencename} for references, which can't be found internally.

It is not an explicit answer to my question, but probably the way more elegant solution to the problem.

Here's the complete solution for my minimal example.

\documentclass{article}

\usepackage{xr}
\usepackage{hyperref}
\usepackage{cleveref}

\externaldocument[ext:]{full}

\makeatletter
\newcommand\myref[1]{
    \@ifundefined{r@#1}{
        \cref*{ext:#1}
    }{
        \cref{#1}
    }
}
\makeatother

\begin{document}
    First page\newpage
    Second page:
    \begin{equation}
    a=b \label{eq:firstequation}
    \end{equation}
    \newpage
    \myref{eq:firstequation}\quad 
    \myref{eq:secondequation}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .