Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx: different relative paths to same figure possible?

I am new to Sphinx and would like to show the same figure in two different *.rst files.

The first *.rst file "lower.rst" is on the same level as the "figures" folder and I am including a figure in it like this:

.. figure:: figures/figure1.png

The second *.rst file "higher.rst", is several levels higher than lower.rst. In fact, I am including lower.rst in higher.rst like this:

.. include:: relative/path/to/lower.rst.

Unfortunately, in the higher.rst, the figures from lower.rst are not displayed:

"image file not readable" error.

higher.rst looks in the current directory for the figure instead of pointing to the original lower directory.

This question is sort-of addressed here: Can sphinx link to documents that are not located in directories below the root document?, but I still do not understand how to resolve my problem with the information given there.

like image 668
anfho Avatar asked May 01 '17 03:05

anfho


1 Answers

Put your figures in a directory at the root level, and change your markup to find them relative to the root using a leading /.

.. figure:: /_static/figure1.png

Now from the higher level file, you should be able to include the lower, and both files should display the image.

like image 143
Steve Piercy Avatar answered Oct 22 '22 16:10

Steve Piercy