Commit 164a0286 authored by Tiago Peixoto's avatar Tiago Peixoto

doc: switch from Mathjax 2 to 3

parent 68e1234a
......@@ -39,7 +39,7 @@ extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
mathjax_path = "MathJax/MathJax.js?config=default"
mathjax_path = "MathJax/tex-chtml-full.js"
# Add any paths that contain templates here, relative to this directory.
templates_path = ['.templates']
# -*- coding: utf-8 -*-
Set up everything for use of MathJax (
to display math in HTML via JavaScript.
(c) Kevin Dunn,
:license: BSD, see LICENSE for details.
from docutils import nodes
from sphinx.application import ExtensionError
from sphinx.ext.mathbase import setup_math as mathbase_setup
def html_visit_math(self, node):
self.body.append(self.starttag(node, 'span', '', CLASS='math'))
self.body.append(self.builder.config.mathjax_inline[0] + \
self.encode(node['latex']) +\
self.builder.config.mathjax_inline[1] + '</span>')
raise nodes.SkipNode
def html_visit_displaymath(self, node):
self.body.append(self.starttag(node, 'div', CLASS='math'))
if node['nowrap']:
self.body.append(self.builder.config.mathjax_display[0] + \
node['latex'] +\
raise nodes.SkipNode
parts = [prt for prt in node['latex'].split('\n\n') if prt.strip() != '']
for i, part in enumerate(parts):
part = self.encode(part)
if i == 0:
# necessary to e.g. set the id property correctly
if node['number']:
self.body.append('<span class="eqno">(%s)</span>' %
if '&' in part or '\\\\' in part:
self.body.append(self.builder.config.mathjax_display[0] + \
'\\begin{split}' + part + '\\end{split}' + \
self.body.append(self.builder.config.mathjax_display[0] + part + \
raise nodes.SkipNode
def builder_inited(app):
if not app.config.mathjax_path:
raise ExtensionError('mathjax_path config value must be set for the '
'mathjax extension to work')
def setup(app):
mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None))
app.add_config_value('mathjax_path', '', False)
app.add_config_value('mathjax_inline', [r'\(', r'\)'], 'html')
app.add_config_value('mathjax_display', [r'\[', r'\]'], 'html')
app.connect('builder-inited', builder_inited)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment