Cross-referencing labels in other files

With the xr package one can pull labels from different files, however it is not possible to create hyperref-Hyperlinks with this package.

Fortunately there is a was around this challenge:

„Label-Dokument.tex“ with the label inside

%!TEX TS-program = Arara
% arara: pdflatex
\documentclass[12pt]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\hypersetup{
    bookmarks=true,                     % show bookmarks bar
    unicode=false,                      % non - Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,                        % show Acrobat’s toolbar
    pdfmenubar=true,                        % show Acrobat’s menu
    pdffitwindow=false,                 % window fit to page when opened
    pdfstartview={FitH},                    % fits the width of the page to the window
    pdftitle={Title},                        % title
    pdfauthor={Author},                 % author
    pdfsubject={Subject},                   % subject of the document
    pdfcreator={LaTeX},                   % creator of the document
    pdfproducer={LaTeX},             % producer of the document
    pdfkeywords={keyword1} {key2} {key3},   % list of keywords
    pdfnewwindow=true,                  % links in new window
    colorlinks=true,                        % false: boxed links; true: colored links
    linkcolor=blue,                          % color of internal links
    citecolor=blue,                          % color of internal links
    filecolor=blue,                     % color of file links
    urlcolor=blue                        % color of external links
}
\begin{document}
 
\section{Some Section}
 
In this file I am setting a label. \label{lab:label1}
 
\end{document}

„Ref-Dokument“ with the reference to „Label-Dokument“

%!TEX TS-program = Arara
% arara: pdflatex
\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{
    bookmarks=true,                     % show bookmarks bar
    unicode=false,                      % non - Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,                        % show Acrobat’s toolbar
    pdfmenubar=true,                        % show Acrobat’s menu
    pdffitwindow=false,                 % window fit to page when opened
    pdfstartview={FitH},                    % fits the width of the page to the window
    pdftitle={Title},                        % title
    pdfauthor={Author},                 % author
    pdfsubject={Subject},                   % subject of the document
    pdfcreator={LaTeX},                   % creator of the document
    pdfproducer={LaTeX},             % producer of the document
    pdfkeywords={keyword1} {key2} {key3},   % list of keywords
    pdfnewwindow=true,                  % links in new window
    colorlinks=true,                        % false: boxed links; true: colored links
    linkcolor=blue,                          % color of internal links
    citecolor=blue,                          % color of internal links
    filecolor=blue,                     % color of file links
    urlcolor=blue                        % color of external links
}
\usepackage{zref-xr,zref-user}
\usepackage{nameref}
\zxrsetup{toltxlabel}
\zexternaldocument*{Label-Dokument}
\begin{document}
 
In this document I reference the external label in section \ref{lab:label1} on page \pageref{lab:label1} of the external document.
 
\end{document}

ref

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website