Django ReStructuredText中的Math指令

时间:2013-01-09 11:28:35

标签: python django django-templates restructuredtext docutils

我正在使用Django模板restructuredtext过滤器在我的模板中显示第一个文件。 我已安装docutils,并已将django.contrib.markup添加到settings.py。显示第一个文本工作正常。

现在,我想在第一个文件中添加一些数学运算:

test.rst:

.. math::
    16 \div 2

The equation is :math:`16 \div 2`.

更新::我部分解决了这个问题。最初,错误为Unknown directive。我试图将数学指令添加到模板中,但后来意识到docutils 0.10默认支持数学指令。因此刚升级到docutils-0.10。

但是,现在我看到的是:

\begin{equation*} 16 \div 2 \end{equation*}
The equation is \(16 \div 2\)

如果我rst2html并在浏览器中检查,则第一个文件正常工作。区别在于html文件加载MathJax javascript而Django模板不添加js文件。

所以我猜测缺少某些设置或配置......

非常感谢在这里伸出援助之手!

1 个答案:

答案 0 :(得分:2)

修正了两件事:

  1. 初始错误为Unknown directive。我试图将数学指令添加到模板以加载latex,但后来意识到docutils 0.10默认支持数学指令。因此刚升级到docutils-0.10。

  2. 之后的错误是我看到\begin{equation*}\end{equation*}标签中包含的乳胶数学代码。比较rst2html和django模板过滤器的输出,我意识到django restructuredtext过滤器不会添加需要做乳胶的MathJax javascript。所以,在我的模板文件部分,我手动添加了:

    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  3. 现在,它有效!