python-sphinxrestructuredtext

Is there a way to generate superscripts from docstrings?


I have a GitHub Actions workflow setup with Sphinx and some extensions for document generation.

I was wondering if there is any way to set up a docstring such that Sphinx will generate in superscript, etc:

:param ne_0: mean electron density
:type ne_0: float, default: 1e24 m^-3

Would produce: ne_0 (float, default: 1e24 m-3) – mean electron density


Solution

  • You need to use :sup:<whatever you want in superscript>, there has to be a space before the :sup: though. To prevent this space from being printed mark it with an escape \, etc: \ :sup:<whatever you want in superscript>

    The correct docstring for my case as an example would be:

    :param ne_0: mean electron density
    :type ne_0: float, default: 1e24 m\ :sup:`-3`