Reputation: 106
How can I cross-reference an indexed item inside a reStructuredText document?
For example, how can I cross-reference SectionB:
.. index::
pair: SectionA; SectionB
SectionB
--------
SectionB description.
I tried using the index labels in references, such as:
:ref:`SectionB`
but this does not work.
Upvotes: 8
Views: 3477
Reputation: 4295
see: Cross-referencing arbitrary locations
in the Sphinx documentation.
I think what you might be missing is a reference label,
Try something like:
.. index::
pair: SectionA; SectionB
.. _section-b-label:
SectionB
--------
SectionB description.
and then elsewhere do:
:ref:`section-b-label`
Upvotes: 3
Reputation: 2104
Sphinx (now, since v1.4 in 2016) has an autosectionlabel extension that does exactly what you want:
This extension allows you to refer sections its title. This affects to the reference role (ref).
For example:
A Plain Title ------------- This is the text of the section. It refers to the section title, see :ref:`A Plain Title`.
Internally, this extension generates the labels for each section. If same section names are used in whole of document, any one is used for a target by default. The autosectionlabel_prefix_document configuration variable can be used to make headings which appear multiple times but in different documents unique.
Upvotes: 2
Reputation: 6528
This options still does not seem possible without adding in custom labels. There is an issue open at https://github.com/sphinx-doc/sphinx/issues/1671
It is possible to link to glossary terms using :term:
, and index links ideally would be possible and added to the arbitrary links docs
Upvotes: 0