为什么在Sphinx/pythonhosted.org中没有显示数学公式?

Mar*_*oma 4 python restructuredtext pypi mathjax python-sphinx

我不确定问题究竟在哪里.

我开发了一个名为hwrtpythonhosted.org(setuputils会自动发布的官方网站)上的文档托管的Python软件包.

我让Sphinx自动从docstrings生成文档.一些模块docstrings包含数学,如下面的docstring features.py:

"""Take the first ``points_per_stroke=20`` points coordinates of the first
   ``strokes=4`` strokes as features. This leads to
   :math:`2 \cdot \text{points\_per\_stroke} \cdot \text{strokes}`
   features.
   If ``points`` is set to 0, the first ``points\_per\_stroke`` point
   coordinates and the \verb+pen_down+ feature is used. This leads to
   :math:`3 \cdot \text{points_per_stroke}` features."""
Run Code Online (Sandbox Code Playgroud)

但是当我访问https://pythonhosted.org/hwrt/features.html#hwrt.features.ConstantPointCoordinates时,它不会显示mathjax的数学运算.为什么会这样,我该如何解决?

conf.py的狮身人面像有

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.intersphinx',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.mathjax'
]
Run Code Online (Sandbox Code Playgroud)

hal*_*lex 6

有关以下句子的数学支持,请参阅Sphinx文档:

请记住,当您在autodoc读取的Python文档字符串中放置数学标记时,您必须将所有反斜杠加倍,或者使用Python原始字符串(r"raw").

遵循这个建议你必须改变你的第一个数学句子,例如

:math:`2 \\cdot \\text{points\\_per\\_stroke} \\cdot \\text{strokes}`
Run Code Online (Sandbox Code Playgroud)

更新

您的问题是您访问pythonhostedhttps但尝试加载mathjax文件http,默认情况下会被阻止.请参阅Chrome控制台中的错误消息

" https://pythonhosted.org/hwrt/features.html#hwrt.features.ConstantPointCoordinates " 页面是通过HTTPS加载的,但是运行了来自" http://cdn.mathjax.org/mathjax/latest/MathJax "的不安全内容.js?config = TeX-AMS-MML_HTMLorMML ':此内容也应通过HTTPS加载.

尝试将https://pythonhosted.org/hwrt/features.html#hwrt.features.ConstantPointCoordinates更改为http://pythonhosted.org/hwrt/features.html#hwrt.features.ConstantPointCoordinates ,一切都显示得很好.

解决方案是您不进行硬编码,但省略导入的JavaScript库的协议.而不是http://cdn.mathjax.org/...使用外部JavaScript运行//cdn.mathjax.org/...

有关详细信息,请参阅SOhttp://blog.jonathanoliver.com/http-and-https-with-google-cdn/ 上的此问题

另一个准确解决您的问题的来源是https://github.com/MDAnalysis/mdanalysis/issues/182