1

I tried to use the xr package to get cross-references between files.

My primary document is book.tex:

\documentclass[a4paper,10pt]{scrbook}
\usepackage{hyperref}

\begin{document}

\chapter{Beginning}
\label{ch1}

Foo

\input{chapter2.tex}

\end{document}

book.tex includes chapter2.tex:

\chapter{End}
\label{ch2}

Bar

My secondary document is supplement.tex:

\documentclass{powerdot}

\usepackage{xr}

\externaldocument{book}

\begin{document}

\begin{slide}{Slide Title}
Reference A: \ref{ch1} page \pageref{ch1}

Reference B: \ref{ch2} page \pageref{ch2}
\end{slide}

\end{document}

book.tex compiles fine using pdflatex book.tex but when I latex supplement.tex I get stuck with

LaTeX Warning: Reference `ch1' on page 1 undefined on input line 13.
LaTeX Warning: Reference `ch2' on page 1 undefined on input line 13.

All the files are in the same directory and I am running pdflatex and latex in that directory without using the -output-directory flag. I also tried the xr-hyper package.

What else do I need to do to make supplement.tex pick up the references from book.tex (and its included file chapter2.tex)?

spraff
  • 1,501
  • 1
    There is no \externaldocument statement in your supplement file –  Jan 22 '17 at 09:48
  • The final problem is beamer since it does apparently not support hyperref in its full extent and redefines some features, e.g. see http://tex.stackexchange.com/questions/127495/referencing-an-article-from-a-beamer-document-with-xr-hyper –  Jan 22 '17 at 10:14
  • @ChristianHupfer I changed to powerdot and got a very similar error. Please see my updated question, thank you. – spraff Jan 22 '17 at 17:18
  • If book.tex loads the hyperref-package, then it is required that supplement.tex does load the hyperref-package also and that supplement.tex does load the xr-hyper-package instead of the xr-package. (The xr-hyper-package must be loaded before the hyperref-package.) – Ulrich Diez Jan 25 '17 at 09:05

1 Answers1

1

Current state of the art is that the \label-\(page)ref-mechanism of the LaTeX2e-kernel gets modified by the hyperref-package.

Thus—if book.tex loads the hyperref-package, then it is required that supplement.tex

  1. does load the hyperref-package also.
  2. does load the xr-hyper-package instead of the xr-package.
    (The xr-hyper-package must be loaded before the hyperref-package.)

(On the platform used by me (MiKTeX 2.9) the powerdot-class seems to work only when compiling in dvi-Mode, yielding a .dvi-file which causes MiKTeX' dvi-previewer YaP to crash but which can without problems be converted via dvips to a postscript-file which in turn can be converted via ps2pdf to a .pdf-file.)

book.tex:

\documentclass[a4paper,10pt]{scrbook}
\usepackage{hyperref}

\begin{document}

\chapter{Beginning}
\label{ch1}

Foo

\input{chapter2.tex}

\end{document}

chapter2.tex:

\chapter{End}
\label{ch2}

Bar

supplement.tex:

\documentclass{powerdot}
\usepackage{xr-hyper}
\usepackage{hyperref}

\externaldocument{book}

\begin{document}

\begin{slide}{Slide Title}
Reference A: \ref{ch1} page \pageref{ch1}

Reference B: \ref{ch2} page \pageref{ch2}
\end{slide}

\end{document}

By the way: If you wish to use the beamer-class, this works as well using the xr-hyper-package instead of the xr-package.

In this case supplement.tex could look like this:

\documentclass{beamer}
\usepackage{xr-hyper}
\usepackage{hyperref}

\externaldocument{book}

\begin{document}

Reference A: \ref{ch1} page \pageref{ch1}

Reference B: \ref{ch2} page \pageref{ch2}

\end{document}
Ulrich Diez
  • 28,770