Question

Is there a way to automatically generate an image/figure caption using sphinx?

I currently have rest-sphinx files I'm converting to html and (latex)pdf using sphinx.

I'd like an easy way for users to reference a specific image in the resulting html/pdf files. For example, if a user is refering to the documentation in an email, "In 'Image 65' it says XXX, but this doesn't work for me".

I've tried using figure where it appears to allow you to apply a caption to an image, but this has to be manually added. (And I have problems getting it to work with substitution for some reason).

Is there a rest-sphinx method I'm overlooking that would achieve this? Or, is there a way to modify/edit sphinx's existing templates to add this ability?

Was it helpful?

Solution

Sphinx consumes reStructuredText as templated by Jinja. According to the Sphinx documentation though, you have other templating options.

You should be able to use Jinja's control structures in a custom template to achieve the effect you're after.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top