Up Next
Go up to 8 Moving information around
Go forward to 8.2 Links to external information

8.1 Cross-references

You can use the \label{label} command to attach a label to a position in your document. This label can be used to create a hyperlink to this position from any other point in the document. This is done using the \link command:

  \link{anchor}{label}
This command typesets anchor, expanding any commands in there, and makes it an active hyperlink to the position marked with label:
   This parameter can be set in the
   \link{configuration panel}{sect:con-panel} to influence ...

The \link command does not do anything exciting in the printed document. It simply typesets the text anchor. If you also want a reference in the LaTeX output, you will have to add a reference using \ref or \pageref. Sometimes you will want to place the reference directly behind the anchor text. In that case you can use the optional argument to \link:

   This parameter can be set in the
   \link{configuration
     panel}[~(Section~\ref{sect:con-panel})]{sect:con-panel} to
   influence ... 
The optional argument is ignored in the HTML-output.

The starred version \link* suppresses the anchor in the printed version, so that we can write

   We will see \link*{later}[in Section~\ref{sl}]{sl}
   how this is done.
It is very common to use \ref{label} or \pageref{label} inside the optional argument, where label is the label set by the link command. In that case the reference can be abbreviated as \Ref or \Pageref (with capitals). These definitions are already active when the optional arguments are expanded, so we can write the example above as
   We will see \link*{later}[in Section~\Ref]{sl}
   how this is done.
Often this format is not useful, because you want to put it differently in the printed manual. Still, as long as the reference comes after the \link command, you can use \Ref and \Pageref.
   \link{Such a file}{ipe-file} is at
   the same time ... a legal \LaTeX{}
   file\texonly{---see Section~\Ref}.

Note that when you use LaTeX's \ref command, the label does not mark a position in the document, but a certain object, like a section, equation etc. It sometimes requires some care to make sure that both the hyperlink and the printed reference point to the right place, and sometimes you will have to place the label twice. The HTML-label tends to be placed before the interesting object--a figure, say--, while the LaTeX-label tends to be put after the object (when the \caption command has set the counter for the label). In such cases you can use the new Label environment. It puts the HTML-label at the beginning of the text, but the latex label at the end. For instance, you can correctly refer to a figure using:

   \begin{figure}
     \begin{Label}{fig:wonderful}
       %% here comes the figure itself
       \caption{Isn't it wonderful?}
     \end{Label}
   \end{figure}
A \link{fig:wonderful} will now correctly lead to a position immediatly above the figure, while a Figure~\ref{fig:wonderful} will show the correct number of the figure.

A special case occurs for section headings. Always place labels after the heading. In that way, the LaTeX reference will be correct, and the Hyperlatex converter makes sure that the link will actually lead to a point directly before the heading--so you can see the heading when you follow the link.

After a while, you may notice that in certain situations Hyperlatex has a hard time dealing with a label. The reason is that although it seems that a label marks a position in your node, the HTML-tag to set the label must surround some text. If there are other HTML-tags in the neighborhood, Hyperlatex may not find an appropriate contents for this container and has to add a space in that position (which may sometimes mess up your formatting). In such cases you can help Hyperlatex by using the Label environment, showing Hyperlatex how to make a label tag surrounding the text in the environment.

Note that Hyperlatex uses the argument of a \label command to produce a mnemonic HTML-label in the HTML file, but only if it is a legal URL.

In certain situations--for instance when it is to be expected that documents are going to be printed directly from web pages, or when you are porting a LaTeX-document to Hyperlatex--it makes sense to mimic the standard way of referencing in LaTeX, namely by simply using the number of a section as the anchor of the hyperlink leading to that section. Therefore, the \ref command is implemented in Hyperlatex. It's default definition is

   \newcommand{\ref}[1]{\link{\htmlref{#1}}{#1}}
The \htmlref command used here simply typesets the counter that was saved by the \label command. So I can simply write
   see Section~\ref{sec:cross-references}
to refer to the current section: see Section 8.1.
Otfried Schwarzkopf, September 2, 1997

Up Next