2

I have a document where lines are numbered. I want to reference some special lines, for which the correct line numbers are generated. But using hyperref does not give the expected result: clicking on a line reference always moves me to the first page of the document, not the page which the referenced line is on. Check the following minimal example for reproducing my problem:

\documentclass[11pt]{article}

\usepackage{lipsum}
\usepackage{hyperref}
\usepackage[right]{lineno}

\begin{document}
  \linenumbers
  \lipsum[1-8]
  \textbf{Here is the line, I want a reference to.}\linelabel{test}
  \lipsum[5-8]
  \textbf{Here is the line, where I refence a the special line (on page two):
  \ref{test}}
\end{document}

I'm using pdflatex.

5

You can set up a system for creating such references using hyperrefs commands \hypertarget and \hyperlink. I have called the labelling command \llabel and the reference command \lref. The llineno: prefix is to avoid clashes with other target names.

\documentclass[11pt]{article}

\usepackage{lipsum}
\usepackage[right]{lineno}
\usepackage{hyperref}

\newcommand{\llabel}[1]{\hypertarget{llineno:#1}{\linelabel{#1}}}
\newcommand{\lref}[1]{\hyperlink{llineno:#1}{\ref*{#1}}}

\begin{document}
  \linenumbers
  \lipsum[1-8]
  \llabel{test}\textbf{Here is the line, I want a reference to.}
  \lipsum[5-8]
  \textbf{Here is the line, where I refence a the special line (on
  page two): \lref{test}}
\end{document}
  • The above solution works. It is still a workaround though. But as Jesse mentioned, the problem has already been discussed among the maintainers of the respective packages. The problem cited by karlkoeller is probably of the same nature, so maybe these two questions should be merged? – SkWob Aug 22 '13 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.