如何在 Sphinx Docs 中显示 Matrix?
How to show Matrix in Sphinx Docs?
我有一个 3 x 3 的矩阵,我想在 Python 文档的 Generated sphinx 文档中显示它。
def Matrix_func():
"""
[1 4 7 ]
M = [2 5 8 ]
[3 6 9 ]
"""
目前上面的矩阵没有打印出来,因为它在生成的 sphinx 文档中。
以下是如何在函数文档字符串中包含矩阵:
def Matrix_func():
"""
::
[1 4 7 ]
M = [2 5 8 ]
[3 6 9 ]
More text...
"""
注意双冒号 (::
),表示 literal block。
或者使用 MathJax 扩展
在您的狮身人面像 config.py
中添加 mathjax
extension
extensions = [
# ... other extensions
'sphinx.ext.mathjax',
]
然后一个漂亮的数组将呈现为:
def Matrix_func():
r"""
.. math::
M = \begin{bmatrix}
1 & 4 & 7 \
2 & 5 & 8 \
3 & 6 & 9
\end{bmatrix}
"""
这个答案晚了 2.25 年,但我希望它对某人有所帮助 ;)
我有一个 3 x 3 的矩阵,我想在 Python 文档的 Generated sphinx 文档中显示它。
def Matrix_func():
"""
[1 4 7 ]
M = [2 5 8 ]
[3 6 9 ]
"""
目前上面的矩阵没有打印出来,因为它在生成的 sphinx 文档中。
以下是如何在函数文档字符串中包含矩阵:
def Matrix_func():
"""
::
[1 4 7 ]
M = [2 5 8 ]
[3 6 9 ]
More text...
"""
注意双冒号 (::
),表示 literal block。
或者使用 MathJax 扩展
在您的狮身人面像 config.py
中添加 mathjax
extension
extensions = [
# ... other extensions
'sphinx.ext.mathjax',
]
然后一个漂亮的数组将呈现为:
def Matrix_func():
r"""
.. math::
M = \begin{bmatrix}
1 & 4 & 7 \
2 & 5 & 8 \
3 & 6 & 9
\end{bmatrix}
"""
这个答案晚了 2.25 年,但我希望它对某人有所帮助 ;)