4

In one of my documents, I used the combination of \label with \hyperref. Now, I fail for some reason.

I included the package:

\usepackage[colorlinks=true,urlcolor=blue,linkcolor=blue]{hyperref}

Created a label somewhere in my text:

\label{key1}

And referenced it from the text:

\hyperref[key1]{there}

But xelatex gives me this:

Package hyperref Warning: Empty destination name,
(hyperref)                using `UNDEFINED' on input line 66.

What am I doing wrong?

EDIT: Minimal working example:

\documentclass[a4paper, 12pt]{article}

\usepackage{xltxtra}
\usepackage[colorlinks=true,urlcolor=blue,linkcolor=blue]{hyperref}

\begin{document}

  Some text. \label{key1} Continuing.

  Some more text (\hyperref[key1]{goto}).

\end{document}
lockstep
  • 250,273
Rogach
  • 3,088
  • Your MWE works fine for me. Pl. improve it to show the actual problem. –  Apr 23 '12 at 08:19
  • @HarishKumar - what version of xelatex do you have? I have "XeTeX 3.1415926-2.2-0.9995.2". – Rogach Apr 23 '12 at 08:21
  • @HarishKumar - That MWE actually shows my problem (on my machine) - the compiler outputs that error message, and link does not work. – Rogach Apr 23 '12 at 08:21
  • @Rogach: My Xetex version is : This is XeTeX, Version 3.1415926-2.3-0.9997.5 (MiKTeX 2.9) (preloaded format=xelatex 2011.12.21) 23 APR 2012 13:55 entering extended mode. Looks like you have to update your distro. –  Apr 23 '12 at 08:25
  • @HarishKumar - I'd like to, but it is the latest texlive release available in repositories - and I do not want to build all the deb packages by myself (not that I'm lazy, there are just too many of them :)) – Rogach Apr 23 '12 at 08:28
  • @HarishKumar - besides, I assume the people were able to do the linking even before version 2.3 - I just do not know how. – Rogach Apr 23 '12 at 08:29
  • 2
    the repositories are out of date- your example works fine in the latest texlive. Please see Martin's answer to best-way-to-install-packages-for-texlive-in-ubuntu- you don't need to build the deb packages yourself, texlive 2011 comes with very easy executables that do all of the work – cmhughes Apr 23 '12 at 08:59
  • It seems a bug that has been around between 2008 and 2009. The example works with TeX Live 2007 and 2010, not with the version of those two years. However, \hypertarget and \hyperlink might be better for this application. – egreg Apr 23 '12 at 09:32

2 Answers2

5

It seems that \label can be attached only to sections or subsections (or some other environments, like figures). To be able to reference arbitrary points in text, I needed to define "phantom section":

\phantomsection
\label{key1}
Rogach
  • 3,088
  • 2
    What hyperref needs, for sure, is a "hook" or "target." However, TeX does not "attach" a \label directly to the place where the command is encountered but, rather, to the "item" it's designed to cross-reference -- an equation, the header of a section of a section, the caption of a figure, etc. If, though, you need to create a hyper-target to a \label that's not associated with a known target type, it's necessary to specify \phantomsection (which might better be called \explicittarget). – Mico Apr 23 '12 at 11:01
  • Since hyperref 2010/04/17 v6.80x this is no longer necessary. The target is initialized with Doc-Start, that is set at the begin of the document. – Heiko Oberdiek Aug 07 '12 at 01:39
2

The repositories are out of date- your example works fine in texlive 2011 available at

http://www.tug.org/texlive/acquire-netinstall.html

Please see Martin's answer to Best way to install packages for TeXLive in Ubuntu?

You don't need to build the deb packages yourself, texlive 2011 comes with very easy executables that do all of the work for you. Once you have texlive 2011 installed, you can update it using tlmgr update --self --all

cmhughes
  • 100,947