0

I have two files; one is main.tex and the other is supplement.tex and I want to reference table label from supplement.tex to main.tex, I do the following in main.tex:

\usepackage{xr}
\externaldocument{supplement}

No error has shown and I got like this Table ?? (the number didn't appear)

Any help please, I tried different ways while searching but none of them succeed with me.

LamaMo
  • 113
  • 1
    Pls give a full compilable example, with this info we can't get started – vaettchen Oct 22 '18 at 11:47
  • supplement.aux which comes into being when compiling supplement.tex needs to be available. (Make sure to have compiled supplement.tex as many times as needed for having everything matching out correctly.) – Ulrich Diez Oct 22 '18 at 11:48
  • Are you using the hyperref package? – samcarter_is_at_topanswers.xyz Oct 22 '18 at 11:52
  • It like this really, put those two lines up and I have a text like: jkjkjfj Table \ref{fig1} kkjkjkj; and fig1 in supplement.tex. That's is @vaettchen – LamaMo Oct 22 '18 at 11:53
  • No I didn't, I just use what I write in the question @samcarter – LamaMo Oct 22 '18 at 11:53
  • See here and here for some caveats – vaettchen Oct 22 '18 at 11:54
  • @SaraWasl That is good, hyperref would require another package. – samcarter_is_at_topanswers.xyz Oct 22 '18 at 11:54
  • What you mean by "supplement.tex needs to be available"? it's there (already created and have some tables and text inside) @UlrichDiez – LamaMo Oct 22 '18 at 11:55
  • if you mean that I should add also \usepackage{hyperref}, I try it right now but nothing change @samcarter – LamaMo Oct 22 '18 at 11:58
  • not supplement.tex but supplement.aux . When you compile supplement.tex for obtaining supplement.pdf or supplement.dvi, you also get a file supplement.aux. That file is read when processing the call to \externaldocument from main.tex for obtaining the referencing-data. – Ulrich Diez Oct 22 '18 at 11:58
  • It seems that I didn't have it :/ how can I got/produce supplement.aux ? @UlrichDiez – LamaMo Oct 22 '18 at 11:59
  • @SaraWasl No, don't add it if you don't need it. It is just an often used package which would have caused problems with your code. So I wanted to know if you use it. – samcarter_is_at_topanswers.xyz Oct 22 '18 at 12:00
  • @SaraWasl I think for debugging it would be good if you would add two short minimal working example (MWE) of your documents to your question. This way we could test if we can replicate your problem. – samcarter_is_at_topanswers.xyz Oct 22 '18 at 12:01
  • I assume supplement.tex itself is a compilable document. So compile supplement.tex via the latex-compiler or the pdflatex-compiler for obtaining supplement.dvi respective supplement.pdf. This compilation also delivers the auxiliary file supplement.aux. (Probably you use some fancy TeX editor or frontend for calling the latex-compiler. If you do so make sure that the auxiliary-files don't get deleted after compilation of your .tex-files.) – Ulrich Diez Oct 22 '18 at 12:04
  • See the comment from 'Ulrich Diez' I didn't have supplement.aux, maybe this the problem @samcarter – LamaMo Oct 22 '18 at 12:05
  • I simply use overleaf for editing, I just creat supplement.tex and write down what I want, so even when I run it nothing show to me (I mean I didn't see anything on the other side) @UlrichDiez – LamaMo Oct 22 '18 at 12:07
  • With overleaf it won't work. overleaf imho compiles every document with the name "output". See https://tex.stackexchange.com/questions/252317/can-one-safely-redefine-jobname. There is also a faq about this: https://www.overleaf.com/learn/latex/Questions/How_can_I_make_the_xr_package_work_on_Overleaf%3F – Ulrike Fischer Oct 22 '18 at 12:11

1 Answers1

1

File documentA.tex

\documentclass{article}
\begin{document}
\section{Section in document A}\label{Asection}
\end{document}

File documentB.tex

\documentclass{article}
\usepackage{xr}
\externaldocument[documentAPrefix-]{documentA}
\begin{document}
\section{Section in document B}\label{Bsection}

This are references to section of document A:

ref: \ref{documentAPrefix-Asection}

pageref: \pageref{documentAPrefix-Asection}

\end{document}

First compile documentA.tex in order to obtain documentA.pdf.

During this compilation, beneath other things, the file documentA.aux comes into being.

Keep that file. Don't have it deleted.

Then compile documentB.tex.

I suggest doing this on the shell-prompt (bash/LXTerminal/command.com/whatever you use) :

On the prompt of your shell change to the directory/folder where both documentA.tex and documentB.tex are saved. (The command for changing to a directory or folder is chdir or cd or the like.)

Then two or three times use the command pdflatex documentA.tex.

Then two or three times use the command pdflatex documentB.tex.

Besides documentA.pdf and documentB.pdf you will get files of extension .log and .aux as well. The .aux-files are of interest for the \externaldocument-command. ;-)

Ulrich Diez
  • 28,770