5

For the following MWE hyperref complains that it can not find a target for the link, and thus does not create a link. What can I do to make it work?

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage[pagewise]{lineno}
\usepackage{lipsum}

\pagewiselinenumbers

\begin{document}
\lipsum[1-2]
foo\linelabel{l:foo}

\lipsum[3]
Line~\ref{l:foo} on page~\pageref{l:foo}.
\end{document}
  • 1
    Does the code I posted at tex.stackexchange.com/a/129570/15925 help? – Andrew Swann Aug 22 '13 at 14:14
  • @AndrewSwann Hi Andrew, that is quite good! The other question is newer, but has an accepted answer, so I would not want to close it as duplicate. So I'd like to suggest that you give another answer here, maybe even proposing something for the nonworking \pageref. Acceptance guaranteed ;-) – mafp Aug 22 '13 at 22:54
3

The work-around I gave in Hyperref and lineno: always jumping to first page is easily extended to page references via a new command \lpageref:

Sample output

\documentclass[11pt]{article}

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

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

\begin{document}
\linenumbers
\Blindtext
\llabel{test}\Blindtext

Finally, we reference line \lref{test} on page~\lpageref{test}.
\end{document}

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.