2

I am using TL 2023 (Ubuntu 24.04)

It seems that xr-hyper does work for the beamer class (using or not using subfiles)

I have a longer (500 page) beamer document, that I split using subfiles. I deal with the links between sub documents, using xr-hyper. main.tex:

\documentclass[presentation]{beamer} 
\usepackage{xr-hyper}
\usepackage{hyperref}
\hypersetup{%
  colorlinks=true,% hyperlinks will be coloured
%  linkcolor=blue,% hyperlink text will be blue
  urlcolor=blue,% hyperlink text will be blue
%  linkbordercolor=red,% hyperlink border will be red
  urlbordercolor=red,% hyperlink border will be red
}
\externaldocument[M-]{main}[]
\usepackage{subfiles}
\begin{document}
\subfile{part1}
\subfile{part2}
\end{document}


and part1.tex

\documentclass[main.tex]{subfiles}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[M-]{main}
\begin{document}
\begin{frame}
  \frametitle{Summary}
  This is a \textbf{xr-hyper} ref: \eqref{M-eq:part2-ceros:1}.

  This is regular reference: \eqref{eq:part2-ceros:1}
  \begin{equation}
    \label{eq:part1-ceros:1}
    \int f dx =0
  \end{equation}
\end{frame}
\end{document}

and part2.tex

\documentclass[main.tex]{subfiles}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[M-]{main}
\begin{document}
\begin{frame}
  \frametitle{Main equations}
\textbf{xr-hyper} ref:  \eqref{M-eq:part1-ceros:1}

Usual ref: \eqref{eq:part1-ceros:1}
  \begin{equation}
    \label{eq:part2-ceros:1}
    \sum\limits_{}^{} f dx =0
  \end{equation}
\end{frame}
\end{document}

When I compile main tex the no xr-hyper links work, the xr-hyper don't

I also tried \externaldocument[M-]{main}[] but it does not change

I also tried just two beamer files, without using subfiles but the result was the same, the xr-hyper links do not work.

Any idea?

Thanks

Uwe Brauer

6
  • 1
    subfiles is a form of \input so you shouldn't use xr at all, as that is for referencing documents that are not input Commented 2 days ago
  • Well, yes and now. While I cannot compile \input files independently, but I can do this with subfiles for example using the article class, I compile the sub-documents independently (from main.tex). So when I compile them I want to check the references links, without being forced to run main.tex. That IMHO is the whole point of subfiles. Commented 2 days ago
  • 1
    well \externaldocument[M-]{main}[] in main.tex is referencing the current document as external so it's conceptually wrong and (as the person who wrote xr) I can confirm that whatever it does is accidental unplanned behaviour. Commented 2 days ago
  • ok, I changed this to \externaldocument[M-]{main} and still does not work, moreover if I consider two beamer files, (not using subfiles) the xr-hyper links do not work in beamer, (I know that beamer rewrites a lot of basic commands) Commented 2 days ago
  • \externaldocument[M-]{main} that is still conceptually wrong, the main document is not external to main Commented 2 days ago

1 Answer 1

3

In beamer the names of the anchors are not independant from the keys of the labels and the anchor a \ref command is trying to use is not independant of the label key either.

That means that \label{eq:part1-ceros:1} is creating an anchor named eq:part1-ceros:1 while your \ref{M-eq:part1-ceros:1} is looking for M-eq:part1-ceros:1.

In your texlive 2023 there are perhaps additional problems as it didn't correctly record the destination names, see https://github.com/josephwright/beamer/issues/917

In texlive 2025 you could try

\makeatletter
\RenewDocumentCommand{\eqref}{sm}
 {\IfBooleanTF{#1}
   {\textup{\tagform@{\ref*{#2}}}}
   {\textup{\tagform@{\ref{#2}}}}}
\makeatother

and then use \eqref*{M-eq:part2-ceros:1} for xr-hyper references.

Another option is to create two labels everywhere:

\label{eq:part1-ceros:1}\label{M-eq:part1-ceros:1}
2
  • Thanks, adding \label{eq:part1-ceros:1}\label{M-eq:part1-ceros:1} gives an error, when using amsmath, shall I add your \makeatletter \RenewDocumentCommand{\eqref}{sm} ` {\IfBooleanTF{#1}` {\textup{\tagform@{\ref*{#2}}}} {\textup{\tagform@{\ref{#2}}}}} \makeatother only in the main.tex file or also in the subfiles? Commented 2 days ago
  • I tried out what you suggested in TL2023, it generates references (not colored) and when I try to click on them nothing happens. Commented 2 days ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.