Search code examples
python-sphinxrestructuredtext

Create a link with independent text


Is it possible to create an intra-document link with sphinx, such that the displayed text is independent of the link and destination? Currently, I make intra-document links like so:

.. _Label_For_Section:

===============
Name Of Section
===============

The link :ref:`Label_For_Section` is rendered as "Name Of Section".
The link Label_For_Section_ is rendered as "Label_For_Section".

What I want is a way to have a link, where the destination text, link label, and displayed link text can all be different strings. Eg a link to a section called "A" with a label .. _B: which is rendered as "C"

Note

I noticed that other kinds of links (eg external hyperlinks) are similarly constrained, and I figure the solutions may look similar, however I am looking specifically for a solution for intra-document links.


Solution

  • See Cross-referencing arbitrary locations, specifically the ref role.

    :ref:`Link title <label-name>`