# using \ref for words in text - across files - and including urls

So, I have a couple of questions, I'll try to build it up progressively:

1. I want to use labels and references for words or phrases instead of the usual reference to a section number or page. I found a solution here - Heiko's solution - that works for me, so I can then use

\LBL[A-01]{some phrase}


and when I want to print out "some phrase" I use

\ref{A-01}


which works great. So far so good, but if anyone has any other ideas - especially in light of what follows, I would be happy to hear them.

2. Then I want to be able to use this system between files. So in one file I have a list of all the phrases (which might change at some point) and in another file I can just use \ref to get the phrases from the other file. I found simply adding \usepackage{xr} and the appropriate \externaldocument{} command, that worked fine in conjunction with the \LBL code from above.

3. Now this is where it got too tricky for me. I want the 'some phrase' to actually be a url or rather href. So to get urls in the first place, I add the hyperref package, and then it seems the xr package gets all weird, which is fixed by using xr-hyper instead. So I want the 'some phrase' to be the description of the href from the other file, AND I want clicking on it to take me to the url, and NOT to the other pdf.

Maybe this is too involved of an explanation, so I've got a minimal working example below - you have to name them file1.tex and file2.tex:

file1.tex

\documentclass[12pt]{article}

\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument{file2}

\newcounter{word}
\makeatletter
\newcommand*{\LBL}{%
\@dblarg\@LBL
}
\def\@LBL[#1]#2{%
\begingroup
\renewcommand*{\theword}{#2}%
\refstepcounter{word}%
\label{#1}%
#2%
\endgroup
}
\makeatother

\begin{document}

\ref{A-01}

\ref{A-02}
\end{document}


file2.tex:

\documentclass[12pt]{article}

\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument{file1}

\newcounter{word}
\makeatletter
\newcommand*{\LBL}{%
\@dblarg\@LBL
}
\def\@LBL[#1]#2{%
\begingroup
\renewcommand*{\theword}{#2}%
\refstepcounter{word}%
\label{#1}%
#2%
\endgroup
}
\makeatother

\begin{document}

\LBL[A-01]{some phrase}

\LBL[A-02]{\href{https://tex.stackexchange.com/}{Best website ever}}

\end{document}


What happens now is that in file1.pdf both lines are hyperlinks to file2.pdf. But I want the first one to not be a clickable link at all, just normal text, and the second one to be the url hyperlink. I hope this makes sense.. How should I go about doing such a thing?

Package hyperref extends the syntax of \ref (and \pageref, ...) with a star form that creates a reference without hyperlink:

\ref*{A-01}


In the second case the reference data contains the complete \href expression, from file2.aux:

\newlabel{A-02}{{\href  {http://tex.stackexchange.com/}{Best website ever}}{1}{}{word.2}{}}


Thus \ref{A-02} generates a link to file2.pdf with destination word.2 on top of the URL link. Also the star form helps to get rid of the top link:

\ref*{A-02}

• Oh the beautiful simplicity. You are a life saver! – maja zaloznik Jun 3 '13 at 11:41