python - Latex 命令\栏在 Python 文档字符串中无法正常工作

标签 python latex docstring

我有一个带有文档字符串的函数,如下所示,

def func(x):

    '''Boring function

    Notes
    -----
    Let :math:`\bar{x}_k = \sum_{i=1}^{n_k}x_{ik}`,
    '''

    return x

但是 Latex 中的 \bar 命令呈现为“ar”,

enter image description here

最佳答案

Python 正在解释反斜杠。您需要传递反斜杠以便 LaTeX 可以解释它们;你应该使用 raw string这样做:

def func(x):

    # Note the r!
    r'''Boring function

    Notes
    -----
    Let :math:`\bar{x}_k = \sum_{i=1}^{n_k}x_{ik}`,
    '''

关于python - Latex 命令\栏在 Python 文档字符串中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37470072/

相关文章:

c# - 在 Python ReST 文档字符串中是否有类似 C#'s "see cref"的内容?

python - 如何阻止 PyCharm 填充文档字符串?

python - 在 Scikit-Learn 中设置多个算法试验时遇到问题

python - 检查文件的名称是否具有相同的日期,Python 3

latex - 使用pdflatex快速将EPS转换为PDF

latex - 如何以 UTF8 编译 LaTeX?

python - 如何为所有类方法将常量字符串添加到 __doc__?

python - 名称错误 : name 'altitude' is not defined

python - 如何在python中比较2个json

latex - 防止\texttt LaTeX 标签让其内容越过边距