在docstrings公式中使用'\ displaymath'指令

si2*_*19e 8 python documentation latex python-sphinx

我正在使用Sphinx文档包来记录我正在处理的一个小型Python工具包,并且我想通过在Python文档字符串中以LaTeX格式列出它们来描述各种模块实现的数学公式.

使用:math:.. math::指令reStructuredText 很容易实现这一点,例如:

.. math::
   \\displaymath \\sum_{i=1}^{\\infty} x_{i}
Run Code Online (Sandbox Code Playgroud)

但是\\displaymath在Python文档字符串中,该指令只是以红色文本突出显示.当在.rst文件(例如index.rst)中使用时,这按预期工作,并且用于求和的子脚本和超脚本直接在求和符号之下和之上.

这根本不支持docstrings,还是我做错了什么或不做我需要做的事情?

bmu*_*bmu 16

你不需要\displaymath在狮身人面像和没有额外的转义反斜线\sum\infty.

调用时,以下示例函数在html和latex输出中呈现正常.. autofunction:::

def test_func(x):
    """This function will try to calculate:

    .. math::
        \sum_{i=1}^{\\infty} x_{i}

    good luck!
    """
    pass
Run Code Online (Sandbox Code Playgroud)

您必须使用该.. math::指令,因为内联math(:math:)不起作用.

  • 通常,我认为你不应该需要任何逃避反斜杠.`\ frac {\ sum_ {i = 1} ^ {\ infty} x_ {i}} {\ infty}`对我来说非常适合.我使用sphinx 1.1.3,docutils 0.8.1和`sphinx.ext.mathjax`进行数学运算.你用什么? (2认同)