Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to include links/reference points in my latex document, e.g.

Picture showing 3 pages and a link from page 3 to page 1

The situation is the following:

There is a certain paragraph on, say page 11, and on page 13 there is a link and when the reader clicks this link (which does not necessarily have to be blue) then the reader is taken to the desired paragraph on page 11.

And I imagined my code to look like this:

Lie groups are smooth manifolds
...
Lie algebra.

\CreateLink{LabelLie}{Paragraph about Lie groups}
Lie groups play an enormous role in modern geometry, 
  ...
and are studied in representation theory.

In the 1940s–1950s, Ellis Kolchin, Armand Borel
  ...
in number theory.

On a "global" level, whenever a 
  ...
analysis on the manifold.  (see \LinkTo{LabelLie})

Is such a construction possible?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

There are several methods in hyperref:

  • \hypertarget and \hyperlink can be used to create an anchor and a link to that anchor.
  • \phantomsection\label{foo} can be referenced with arbitrary text as \hypererf[foo]{arbitrary text}.
  • The following example uses \refstepcounter that automatically sets an anchor. By redefining \the<counter> the text is setup for later use with \ref:

The example file:

\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}

\newcounter{partextdummy}
\newcommand*{\CreateLink}[2]{%
  \begingroup
    \renewcommand*{\thepartextdummy}{#2}%
    \ifhmode
      % raise the anchor above the base line in horizontal mode
      \raisebox{2ex}[0pt][0pt]{%
        \refstepcounter{partextdummy}%
        \label{#1}%
      }%
    \else
      \refstepcounter{partextdummy}%
      \label{#1}%
    \fi
  \endgroup
  \ignorespaces
}
\newcommand*{\LinkTo}{\ref}

\begin{document}
\lipsum[1]
\CreateLink{nam}{Paragraph about nam dui ligula}
\lipsum[2]
\lipsum[3]
See \LinkTo{nam}
\end{document}

Result

share|improve this answer
    
May I just ask what the line \renewcommand*{\thepartextdummy}{#2}% does ? –  Thomas Feb 23 '13 at 17:20
    
\refstepcounter{<counter>} advances the counter by one and \label will use \the<counter> for the referenced number that \ref refers to. \renewcommand*{\the<counter>}{#2} replaces that number with #2. –  Heiko Oberdiek Feb 23 '13 at 17:29
    
I am not a latex pro, but couldn't I run the risk of overwriting another command each time I use \CreateLink ? –  Thomas Feb 23 '13 at 19:57
    
\CreateLink is defined by \newcommand that complains, if the command already exists. The redefinition of \thepartextdummy is local (because of \begingroup and \endgroup) and the command belongs to the counter partextdummy. –  Heiko Oberdiek Feb 23 '13 at 20:14
    
Okay, thanks a lot. :) –  Thomas Feb 23 '13 at 20:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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