2

To reference a section using reStructuredText in Sphinx, I can do:

.. _my-reference-label:

Section to cross-reference
--------------------------

This is the text of the section.

It refers to the section itself, see :ref:`my-reference-label`.

as explained here.

This results in the section being referenced by title, that is I get the line:

It refers to the section itself, see Section to cross-reference.

(where Section to cross-reference links to the beginning of the corresponding section)

I'd like to get instead:

It refers to the section itself, see 2.1.

where 2.1 is the section's number.

Is there a way to accomplish this using reStructuredText in Sphinx?

Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404

1 Answers1

1

The numsec Sphinx extension does what you want. The source code is here: https://github.com/jterrace/sphinxtr/blob/master/extensions/numsec.py.

The extension is part of the "Sphinx Thesis Resource" package developed by Stack Overflow member jterrace. See https://github.com/jterrace/sphinxtr.

Community
  • 1
  • 1
mzjn
  • 48,958
  • 13
  • 128
  • 248
  • Thank you very much mzjn! The `numsec` extension worked perfectly and that package also has many other very interesting stuff. – Gabriel Apr 23 '15 at 18:05