Enable math node rendering by default (without HTML builders)

Nowadays, math elements (inline and block level equations) are
integrated into reST spec by default.  But, in Sphinx, they are
not enabled by default.  For this reason, users have to enable
one of math extensions even if target builder supports math
elements directly.

This change starts to enable them by default.  As a first step,
this replaces math node and its structure by docutils based one.
This commit is contained in:
Takeshi KOMIYA
2018-05-15 10:57:07 +09:00
parent 4cdb51be83
commit 4e04bff4f5
16 changed files with 203 additions and 63 deletions

View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from sphinx.ext.mathbase import math
master_doc = 'index'
extensions = ['sphinx.ext.mathjax']
def my_math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
return [math(latex='E = mc^2')], []
def setup(app):
app.add_role('my_math', my_math_role)

View File

@@ -0,0 +1,25 @@
Test Math
=========
inline
------
Inline: :math:`E=mc^2`
Inline my math: :my_math:`:-)`
block
-----
.. math:: a^2+b^2=c^2
Second math
.. math:: e^{i\pi}+1=0
Multi math equations
.. math::
S &= \pi r^2
V &= \frac{4}{3} \pi r^3

View File

@@ -12,8 +12,12 @@
import errno
import re
import subprocess
import warnings
import pytest
from docutils import nodes
from sphinx.testing.util import assert_node
def has_binary(binary):
@@ -208,3 +212,21 @@ def test_imgmath_numfig_html(app, status, warning):
'href="math.html#equation-foo">(1)</a> and '
'<a class="reference internal" href="#equation-bar">(3)</a>.</p>')
assert html in content
@pytest.mark.sphinx('dummy', testroot='ext-math-compat')
def test_math_compat(app, status, warning):
with warnings.catch_warnings(record=True):
app.builder.build_all()
doctree = app.env.get_and_resolve_doctree('index', app.builder)
assert_node(doctree,
[nodes.document, nodes.section, (nodes.title,
[nodes.section, (nodes.title,
nodes.paragraph)],
nodes.section)])
assert_node(doctree[0][1][1],
('Inline: ',
[nodes.math, "E=mc^2"],
'\nInline my math: ',
[nodes.math, "E = mc^2"]))