GeneralIncluding \ref* in \href

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
phil217
Posts: 2
Joined: Mon Apr 18, 2011 8:44 pm

Including \ref* in \href

Post by phil217 »

Hi,
I'm making use of cross-references between some hyperref'd documents. I'm trying to construct a URL using \ref*{mylabel}, but \href really doesn't like this in the URL part.

This is a.tex:

Code: Select all

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\section{Foo}\label{mylabel}
\end{document}
Then b.tex:

Code: Select all

\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[A]{a}
\begin{document}
Amylabel, using \verb|\ref*|, is \ref*{Amylabel}.

Amylabel, using \verb|\ref|, is \ref{Amylabel}.

\href{http://www.example.com/}{Really want this to be a URL to
  \texttt{http://www.example.com/\ref*{Amylabel}}}. 

\def\DM{2}
\href{http://www.example.com/\DM}{I can use a def'd macro in href.}

\href{http://www.example.com/\ref*{Amylabel}}{But this line fails.}. 
\end{document}
The last \href line is the problem one. pdflatex fails with

Code: Select all

! TeX capacity exceeded, sorry [input stack size=5000].
\@makeother #1->\catcode `#1
                            12\relax 
l.16 \href{http://www.example.com/\ref*{Amylabel}}
                                                  {But this line fails.}.
!  ==> Fatal error occurred, no output PDF file produced!
(latex fails similarly.) I can't see a simple way round it. Any advice? I can work my way round it with grep/sed etc., but I'd rather stay within LaTeX if I can.

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply