mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
14
tests/roots/test-ext-math-compat/conf.py
Normal file
14
tests/roots/test-ext-math-compat/conf.py
Normal 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)
|
||||
25
tests/roots/test-ext-math-compat/index.rst
Normal file
25
tests/roots/test-ext-math-compat/index.rst
Normal 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
|
||||
@@ -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"]))
|
||||
|
||||
Reference in New Issue
Block a user