16
votes

I know how to create an external hyperlink with customized text.

`My cool link <http://www.asdf.com>`_

But I want to link to an internal reference.

.. _foo:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

So I'd like to do something like

`My cool internal link <foo>`_

But this doesn't work.

4

4 Answers

14
votes

Solution:

`My cool internal link <foo_>`_
9
votes

Use 2 underscores on text and 1 undescore on link target, example:

`My cool internal link <foo_>`__

... somewhere lower ...

.. _foo:

This staff is referenced by "My cool internal link"

When I use one underscore instead of 2, rst2pdf throws an error.

2
votes

If John's solution doesn't work for you:

`My cool internal link<foo>`
2
votes

You just needed to remove the space after your custom title, and before the angle brackets, and use the :ref: directive:

This works:

:ref:`My cool internal link with no space before bracket<foo>`

This doesn't:

:ref:`My cool internal link with space <foo>`