3

This is probably an unusual way of using labels, but I would be happy if there was a way for me to create an alias to a label without just writing another \label at the target environment.

I imagine something like this:

% File A 
\documentclass{article}
\begin{docuement}
\begin{proposition}
    \label{original_label}
    ...
\end{proposition}
\end{docuement}
% File B
\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}

\externaldocument[A-]{a.tex}
\labelalias{new_label}[A-original_label}
\begin{document}
    See Proposition \hyperref{new_label}...
\end{docuement}

Thanks!

1
  • 2
    \ExpandArgs{cc}\let{r@newlabel}{r@oldlabel} Commented Oct 15 at 16:41

1 Answer 1

4

\ref{foo} uses (if defined) the control sequence \r@foo.

You can abstract the definition. I choose to do it at begin document, so when the .aux files have been read in.

\documentclass{article}
\usepackage{xr}
\usepackage{hyperref}

\externaldocument[A-]{external}

\ExplSyntaxOn
\NewDocumentCommand{\definelabelalias}{mm}
 {
  \AtBeginDocument
   {
    \cs_if_exist:cT {r@#2} { \cs_set_eq:cc {r@#1} {r@#2} }
   }
 }
\ExplSyntaxOff

\definelabelalias{foo}{A-test-external}
\definelabelalias{baz}{test-internal}

\begin{document}

\section{Test}\label{test-internal}

\ref{A-test-external} = \ref{foo}

\ref{baz} = \ref{test-internal}

\end{document}

The external file I used is

\documentclass{article}
\begin{document}
\section{Title}\label{test-external}
\end{document}

Note that you don't need xr-hyper. Everything produces 1 as expected and the links to the external labels have different colors than the internal.

output

If no .aux file is available (or isn't up-to-date) you get

LaTeX Warning: Reference `A-test-external' on page 1 undefined on input line 24.
LaTeX Warning: Reference `foo' on page 1 undefined on input line 24.
LaTeX Warning: Reference `baz' on page 1 undefined on input line 26.
LaTeX Warning: Reference `test-internal' on page 1 undefined on input line 26.

If the external .aux file is available, you just get

LaTeX Warning: Reference `baz' on page 1 undefined on input line 26.
LaTeX Warning: Reference `test-internal' on page 1 undefined on input line 26.
0

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.