2

I am writing a thesis. In the main file of the thesis, I have included \usepackage{xr}. Then in Chapter2, I have included \externaldocument{./Chapters/Chapter1} to get access of equations of Chapter1. But I cant. Can anyone help me in this regard?

  • If you include the chapters with \include you don't need xr package at all. Do you have \labels at all? – user31729 May 9 '16 at 9:45
  • In the main chapter, I have used \usepackage{xr}. Then called two chapters \input{./Chapters/Chapter1} and \input{./Chapters/Chapter2}. Then to get access of equations of Chapter1 from Chapter2, I have just included \externaldocument{./Chapters/Chapter1} in the header of Chapter2. Nothing else. Now, how can I get access to the equations of Chapter 1 from Chapter2? – Nasim May 9 '16 at 9:50
  • Nasim, this procedure is wrong, sorry – user31729 May 9 '16 at 9:52
  • How can I do it? – Nasim May 9 '16 at 9:55
1

The xr package is not meant to get references from external files that are included anyway -- it works, but it will complain about the multiply defined labels (unless the optional argument of \externaldocument is used.

Rather use \include or \input. This way the content of files are included and the references are correct anyway!

\documentclass{book}


\begin{document}

In \ref{eq:first} and \ref{eq:second} we will see that

\include{chapterone}


\include{chaptertwo}
\end{document}

chapterone.tex:

\chapter{First chapter}

\begin{equation}
  E=mc^2 \label{eq:first}
\end{equation}

chaptertwo.tex

\chapter{Second chapter}

\begin{equation}
  c^2 = a^2 + b^2 \label{eq:second}
\end{equation}

Other way (but not really useful!):

\documentclass{book}

\usepackage{xr}

\externaldocument[Aext]{chapterone}

\externaldocument[Bext]{chaptertwo}

\begin{document}

In \ref{eq:first} and \ref{eq:second} we will see that

\include{chapterone}


\include{chaptertwo}
\end{document}
  • @Nasim: You're welcome. Happy TeXing! – user31729 May 9 '16 at 10:06
1
\RequirePackage{filecontents}
\begin{filecontents*}{chapter1.tex}
    \chapter{foo}\label{chap:foo}
\end{filecontents*}
\begin{filecontents*}{chapter2.tex}
    \chapter{bar}\label{chap:bar}
\end{filecontents*}
\documentclass{book}
\begin{document}

\input{chapter1}
\input{chapter2}

See chapter \ref{chap:foo} and \ref{chap:bar}

\end{document}

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.