4

I have one document that has hyperref loaded, and works fine.

I have a second document that I am using xr-hyper to reference the first. If I remove hyperref from the first document, the \titleref{} (from memoir) command works as expected. If I use hyperref I get "See Chapter 1" instead of "See Chapter Example".

Here are the two files that show this behavior:

\documentclass[12pt]{memoir}
\usepackage{xr-hyper}
\usepackage{hyperref}

\begin{document}
\chapter{Example}\label{chap:example}

Examples
\end{document}

Call that one example.tex, run pdflatex on it, and then the second file references it:

\documentclass[12pt]{memoir}
\usepackage{xr-hyper}
\usepackage{hyperref}

\externaldocument{example}
\begin{document}
See Chapter~\ref{chap:example} on page~\pageref{chap:example} which is called~\titleref{chap:example}.
\end{document}

Compile the second file and the issue will appear. Remove or comment out \usepackage{hyperref} in the first file and rerun both pdflatex commands and the \titleref command will work, but the first document won't have any hyperreferences.

I suspect that the problem is that the example.aux file has

\newlabel{chap:example}{{\M@TitleReference {1}{Example}}{1}}

in the working case, and

\newlabel{chap:example}{{1}{1}{Example}{chapter.1}{}}

in the case that doesn't work. I suppose I can compile my first file without hyperref and then the second file, and then turn hyperref on again and recompile the first file.

1
  • Even though you haven't asked a specific question, I assume you want to find a work-around for this broken behaviour.
    – Werner
    Commented Mar 6, 2014 at 4:53

2 Answers 2

4

In order to make this work, rely solely on hyperref to manage the titles in the target/external document. Why? Because it wasn't compiled under the memoir class, and therefore has no reference of the \titleref requirements. Use \nameref instead.

Here's a minimal example:

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage{xr-hyper,hyperref}% http://ctan.org/pkg/{xr-hyper,hyperref}
\externaldocument{example}
\begin{document}
\chapter{Some chapter}\label{chap:current}
See Chapter~\ref{chap:example} on page~\pageref{chap:example} which is called~\nameref{chap:example}.

See Chapter~\ref{chap:current} on page~\pageref{chap:current} which is called~\titleref{chap:current}.
\end{document}
2
  • This is working, but now I get another (perhaps related) issue. The references to the external document don't work with memoir \NumToName: Chapter~\NumToName{\ref{chap:example}} errors out with Missing number. Should I create a new question?
    – bombcar
    Commented Mar 6, 2014 at 15:51
  • @bombcar: It would think so, since it's complete different in nature from this one. It may be helpful to reference this question in the follow-up.
    – Werner
    Commented Mar 6, 2014 at 17:10
5

Package zref-xref can be used instead of xr-hyper, even if the zref labels are not used, because \zexternaldocument also can import and export from LaTeX labels with or without hyperref:

\documentclass[12pt]{memoir}
\usepackage[colorlinks]{hyperref}
\usepackage{nameref}
\usepackage{zref-xr}
\zxrsetup{
  tozreflabel=false,
  toltxlabel=true,  
}
\zexternaldocument*{example}

\begin{document}
See Chapter~\ref{chap:example} on page~\pageref{chap:example} which is
called~\titleref{chap:example}.
\end{document}

Result

Remark:

  • Package nameref changes the internal label format. It is loaded by package hyperref via \AtBeginDocument at a late time. However \zexternaldocument should know it, thus the example ensures that nameref is loaded before.
2
  • What are the advantages of zref-xr as opposed to simple xr?
    – bombcar
    Commented Mar 6, 2014 at 18:14
  • @bombcar: Better support of the various combinations of packages (with/without hyperref, nameref, titleref, ...). It should be a superset of xr and xr-hyper. Commented Mar 6, 2014 at 18:22

You must log in to answer this question.

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