我有一个带有文档字符串的函数,如下所示,
def func(x):
'''Boring function
Notes
-----
Let :math:`\bar{x}_k = \sum_{i=1}^{n_k}x_{ik}`,
'''
return x
但是 Latex 中的 \bar
命令呈现为“ar”,
最佳答案
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/