gpt4 book ai didi

python - 在文档字符串公式中使用 '\displaymath' 指令

转载 作者:太空狗 更新时间:2023-10-29 20:42:46 24 4
gpt4 key购买 nike

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

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

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

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

这是文档字符串不支持的,还是我做错了什么或没有做我需要做的事情?

最佳答案

在 Sphinx 中不需要 \displaymath 并且 \sum\infty 不需要额外的转义反斜杠。

当使用 .. autofunction:: 调用时,以下示例函数在 html 和 latex 输出中都呈现良好:

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

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

good luck!
"""
pass

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

关于python - 在文档字符串公式中使用 '\displaymath' 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10081633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com