Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Matrix in Sphinx Docs?

I have a Matrix say 3 x 3, I want to display it in the Generated sphinx documentation of Python docs.

def Matrix_func():
    """
            [1  4  7 ]
    M   =   [2  5  8 ] 
            [3  6  9 ]
    """

Currently the above matrix is not printed as it is in the generated sphinx docs.

like image 926
Aniket Vij Avatar asked Aug 06 '15 17:08

Aniket Vij


People also ask

How do you format a Sphinx Docstring?

The Sphinx docstring formatA pair of :param: and :type: directive options must be used for each parameter we wish to document. The :raises: option is used to describe any errors that are raised by the code, while the :return: and :rtype: options are used to describe any values returned by our code.


1 Answers

Or to use MathJax extension

In your sphinx config.py add the mathjax extension

extensions = [
    # ... other extensions
    'sphinx.ext.mathjax',
]

Then a pretty array will render with:

def Matrix_func():
    r"""
    .. math::

        M = \begin{bmatrix}
                1 & 4 & 7 \\
                2 & 5 & 8 \\
                3 & 6 & 9
            \end{bmatrix}
    """

rendered result

this answer is 2.25 years late, but I hope it helps somebody ;)

like image 77
FraggaMuffin Avatar answered Oct 04 '22 01:10

FraggaMuffin