0

I have two documents file1.tex and file2.tex in two different folds fold1 and fold2, which are in the fold father.

In file1, I defined \label{file1:hello}, how do I use it in file2?

Ma Ming
  • 2,306

1 Answers1

2

I replace here the same answer given for this question: in this case solutions are for files in the same folder.

Solution 1

You can use the xr package to reference to other LaTeX document.

In the file supplementmain.tex you say:

\usepackage{xr}
\externaldocument{supplement}
...
\ref{ext:supplement}

Note: normally xr doesn't add hyperlinks. Use zref package for this. You only need to replace \externaldocument with \zexternaldocument.

Solution 2

A minimal working example taken from the following site: GUIT

First.tex

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{xr-hyper} \usepackage{hyperref} \externaldocument[S-]{Second}[Second.pdf] \begin{document} \chapter{One}\label{chp:one} \chapter{Two}\label{chp:two} Bla Bla Bla. \end{document}

Second.tex

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{xr-hyper} \usepackage{hyperref} \externaldocument[F-]{First}[First.pdf] \begin{document} \chapter{Beginning}\label{chp:One} Hello! \chapter{Continuation} I read chapters~\ref{F-chp:one}~and~\ref{F-chp:two} of the first file.

\end{document}

GUIT also says that in this way you have the hyperlink to the first file.

If files are in different folders, you can add paths into \externaldocument

marchetto
  • 991