Aniket Vij
Aniket Vij

Reputation: 687

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.

Upvotes: 7

Views: 2491

Answers (2)

FraggaMuffin
FraggaMuffin

Reputation: 4225

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 ;)

Upvotes: 11

mzjn
mzjn

Reputation: 50967

Here is how you can include the matrix in the function docstring:

def Matrix_func():
    """
    ::

             [1  4  7 ]
       M  =  [2  5  8 ] 
             [3  6  9 ]

    More text...

    """

Note the double colon (::), signifying a literal block.

Upvotes: 3

Related Questions