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

时间:2014-11-16 13:06:03

标签: python python-sphinx mathjax restructuredtext pypi

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

我开发了一个名为hwrt的Python包,它在pythonhosted.org(setuputils会自动放置它的官方网站)上托管其文档。

我让Sphinx自动从docstrings生成文档。某些模块文档字符串包含数学,如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."""

但是当我转到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'
]

1 个答案:

答案 0 :(得分:6)

请参阅Sphinx documentation on math support以获取以下句子:

  

请记住,当您在Python docstrings中读取数学标记时   通过autodoc,你要么必须加倍所有的反斜杠,要么使用Python   原始字符串(r" raw")。

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

:math:`2 \\cdot \\text{points\\_per\\_stroke} \\cdot \\text{strokes}`

<强>更新

您的问题是您访问pythonhosted而不是https,但尝试在http上加载mathjax文件,默认情况下会阻止该文件。请参阅Chrome控制台中的错误消息

  

页面在   &#39; https://pythonhosted.org/hwrt/features.html#hwrt.features.ConstantPointCoordinates&#39;   是通过HTTPS加载的,但运行的是不安全的内容   &#39; http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&#39 ;:   此内容也应通过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/...

有关详细信息,请参阅this question on SOhttp://blog.jonathanoliver.com/http-and-https-with-google-cdn/

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