python -\r 在 sphinx 中代表什么吗?

标签 python python-sphinx mathjax docstring numpydoc

我正在按照 numpy 文档字符串指南编写文档字符串。然后我使用 sphinx 的 autodoc 生成我的文档。在一些文档字符串中,我使用 LaTeX 公式(sphinx.ext.mathjax)。似乎 \r 意味着一些特殊的东西,比如换行。如果我有以下命令:

"""
This :math:`\langle a, b\rangle` denotes the dot product of a and b
"""

它无法正确渲染。它将类似角度放入新行并给出错误:内联解释文本或短语引用起始字符串,没有结束字符串 如果我用\langle 替换\rangle 一切正常。我该如何解决这个问题?

最佳答案

解决方案是使用双斜杠转义或在三引号中放置一个“r”(不带引号),这会禁用对引号内斜杠的解释:

r"""
This :math:`\langle a, b\rangle` denotes the dot product of a and b
"""

有几个前缀会影响字符串文字的定义,请参阅 documentation of Python .

相关摘录:

The backslash () character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters. As a result, in string literals, '\U' and '\u' escapes in raw strings are not treated specially.

关于python -\r 在 sphinx 中代表什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46543194/

相关文章:

python - 绘制 Pandas DataFrame 的累积返回

python - 如何处理 Python 中的长行代码和命令

python - 如何在 macos Catalina 中将 python homebrew 版本设置为默认版本

jupyter-notebook - jupyter笔记本需要永远打开才能使页面无响应-[MathJax]问题

python - Pandas DataFrame 替换不适用于 inplace=True

python - sphinx文档中如何自动添加参数类型

Python Sphinx 自动摘要 : Automated listing of member functions

python - 当模块需要在导入前设置时使用 sphinx 记录 sqlalchemy 类

disqus - 是否可以在 DisQus 中使用 MathJax?

javascript - 排版 latex 表达式之前的 MathJax 事件