4

I have two documents A and B. I wish to refer to theorems and lemmas from A in B. To do this I am using the package xr in B.

If I use the package hyperref in B then it's all fine. Otherwise, when I write something like

from Theorem \ref{thm:1}

it looks like

from Theorem 1.1theorem1.1

which is not what I wanted. How I do get rid of the "theorem1.1" part at the end? I do not want to use hyperref because I do not want people to click the links in B. Thanks.

  • Please provide a minimal example (or see here). Few people really want to have to construct one themselves just to answer the question. – jon Feb 5 '15 at 16:27
  • when switching in either direction between using or not using hyperref you need to delete your .aux files and regenerate both the current and the referenced document. the internal structure of the \ref information changes with hyperef. – David Carlisle Feb 5 '15 at 16:38
5

Package zref-xr provides many options for importing references with support of many packages (hyperref, titleref, ...).

Example file A.tex with hyperref, which contains the theorems:

\documentclass{article}
\usepackage{hyperref}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
\label{thm:1}
\end{theorem}
\end{document}

File B.tex without references imports references from A:

\documentclass{article}

\usepackage{zref-xr}
\zxrsetup{toltxlabel=true, tozreflabel=false}
\zexternaldocument*{A}

\begin{document}
from Theorem \ref{thm:1}
\end{document}
0

In case this helps anyone else: I was previously using hyperref(in my document A as well as B; it's required in A by the publisher). Removing hyperref from the B document and trying zref-xr as in @Heiko Oberdiek's solution still gave me some errors:

   ! Undefined control sequence.
   l.61 \url{...}`.

Some further searching led me to this question: Undefined control sequence \url error.

Full solution: adding \usepackage{url} made the first solution (@Heiko Oberdiek) work like a charm.

\usepackage{zref-xr}
\zxrsetup{toltxlabel=true, tozreflabel=false}
\zexternaldocument*{A}
\usepackage{url}  %Need to make doc B work with URL links in the bibtex file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.