0

is there any way where i can put a label on a full latex document and refer to it in another tex file.

e.g. supplement.tex

\documentclass[review,12pt]{article}
\usepackage{graphicx}
\begin{document}
\label{supplement1}


something

\end{document}

and in the main document main.tex do something like:

    \documentclass[review,12pt]{article}
    \usepackage{graphicx}
\externaldocument{supplement}
    \begin{document}


    something is refered from Supplement file~\ref{supplement1}

    \end{document}

EDIT

thanks for your comments, what i basically want is not to refer to a section or chapter in another document, but i want to refer to the whole document.

3
  • Check the answer here, I believe it does what you want. If not, please clarify by editing the question. Feb 12 '14 at 16:28
  • 1
    the latex cross reference mechanism to sections (including the xr system for external references) are designed to produce dynamically constructed numbers. For the file reference, if you just want the filename, just type the filename (or if you want it to be a link, hyperref can make it so) Feb 12 '14 at 16:37
  • The "duplicate" question is answered by xr which does not answer this question. I voted for reopen. Feb 12 '14 at 17:48
4

Your question could be clearer (as seen from the comments and close/open votes) but I think you want

\documentclass[12pt]{article}
    \usepackage{hyperref}

    \begin{document}


    something is refered from Supplement file~\href{supplement1.pdf}{supplement1}

\end{document}

which makes the word supplement1 a link to supplement1.pdf

1

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.

8
  • Hi, this did not work, im still getting ?? in the place of \ref{ext:supplement} when i run pdflatex
    – ifreak
    Feb 12 '14 at 16:45
  • It could be because both files must to be in the same folder.
    – marchetto
    Feb 12 '14 at 16:50
  • they are in the same folder already
    – ifreak
    Feb 12 '14 at 17:03
  • @ifreak the above assumes that there is a label \label{ext:supplement} in the external document, and that you want the number associated with that label. Feb 12 '14 at 17:09
  • @David Carlisle: Taanks I forgot to explain this thing
    – marchetto
    Feb 12 '14 at 17:16

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.