Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose the text use in a cross-reference with Sphinx?

Using sphinx, I included a figure using the following syntax.

.. _struct_NiO:

.. figure:: img/NiO.png
   :align: center
   :width: 400px

   long long very long caption ...

In another part of the text I used

See figure :ref:`struct_NiO` bla bla bla

in order to do a cross reference to the figure. This work, but the output looks like :

See figure "long long very long caption ..." bla bla bla.

This is the normal behavior of sphinx, but if you have a figure a little bit complicated with a 3 or 4 lines caption it is no really adapted.

Is it possible to select the text used in the cross reference ?

like image 381
Ger Avatar asked Jan 17 '13 09:01

Ger


People also ask

Does Sphinx support markdown?

To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.

How do you comment in RST?

For comments, add 2 periods .. followed by a newline and then your comment indented.


1 Answers

You can provide a custom link text for :ref: targets, like this:

See figure :ref:`Link text <struct_NiO>` bla bla bla

See http://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#ref-role.

like image 137
mzjn Avatar answered Sep 25 '22 11:09

mzjn