MathJax not rendering in Sphinx

≡放荡痞女 提交于 2019-12-23 20:31:24

问题


I have a documentation set in Sphinx reST. I've included sphinx.ext.mathjax in conf.py, and included the line "mathjax_path = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js'". I believe that is all I need to do before adding markup to the rst files. But my equations aren't being rendered. For example,

:math:`a^2 + b^2 = c^2`

comes out of the browser as

\(a^2 + b^2 = c^2\)

No fancy font or anything. The HTML is

<span class="math">\(a^2 + b^2 = c^2\)</span>

回答1:


You still need to declare the extention to sphinx-doc in the conf.py file.

On the top of the conf.py file, soon after import sys, os under "general configuration" you will see the comments notes about including extentions. For mathjax you need to add it to the listed extension:

 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = ['sphinx.ext.todo', 'sphinx.ext.mathjax', 'sphinx.ext.ifconfig']

(I've just copy pasted my own, you may have other or no extentions listed there at the moment).

That in combination with the mathjax_path that you have already set should work.




回答2:


I had the same problem. I solved it by setting the mathjax_path variable (on the conf.py file) as:

mathjax_path="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"



回答3:


Here there are some options:

1) You must install libjs-mathjax:

apt-get install libjs-mathjax

2) You should put a "r" prefixing documentations lines:

r"""
  :math:`a^2 + b^2 = c^2`

"""

3) Yous must avoid spaces in the equation (with "r" prefix you avoid this solution)

"""
  :math:`a^2+b^2=c^2`

"""

4) You could mix all the previous solution

r"""
  :math:`a^2+b^2=c^2`

"""


来源:https://stackoverflow.com/questions/19655706/mathjax-not-rendering-in-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!