# -*- coding: utf-8 -*-
"""
test_ext_math
~~~~~~~~~~~~~
Test math extensions.
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import pytest
from util import SkipTest
@pytest.mark.sphinx(
'html', testroot='ext-math',
confoverrides = {'extensions': ['sphinx.ext.jsmath'], 'jsmath_path': 'dummy.js'})
def test_jsmath(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').text()
assert '
\na^2 + b^2 = c^2
' in content
assert '\n\\begin{split}a + 1 < b\\end{split}
' in content
assert (u'(1)'
u'\ne^{i\\pi} = 1
' in content)
assert (u'(2)'
u'\n'
u'e^{ix} = \\cos x + i\\sin x
' in content)
assert '\nn \\in \\mathbb N
' in content
assert '\na + 1 < b
' in content
@pytest.mark.sphinx('html', testroot='ext-math-simple',
confoverrides = {'extensions': ['sphinx.ext.imgmath']})
def test_imgmath_png(app, status, warning):
app.builder.build_all()
if "LaTeX command 'latex' cannot be run" in warning.getvalue():
raise SkipTest('LaTeX command "latex" is not available')
if "dvipng command 'dvipng' cannot be run" in warning.getvalue():
raise SkipTest('dvipng command "dvipng" is not available')
content = (app.outdir / 'index.html').text()
html = (r'\s*
\s*
\s*
\s*
')
assert re.search(html, content, re.S)
@pytest.mark.sphinx('html', testroot='ext-math-simple',
confoverrides={'extensions': ['sphinx.ext.imgmath'],
'imgmath_image_format': 'svg'})
def test_imgmath_svg(app, status, warning):
app.builder.build_all()
if "LaTeX command 'latex' cannot be run" in warning.getvalue():
raise SkipTest('LaTeX command "latex" is not available')
if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue():
raise SkipTest('dvisvgm command "dvisvgm" is not available')
content = (app.outdir / 'index.html').text()
html = (r'\s*
\s*
\s*
\s*
')
assert re.search(html, content, re.S)
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax']})
def test_mathjax_align(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').text()
html = (r'\s*'
r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&= \\pi r\^2\\\\'
r'V \&= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]
')
assert re.search(html, content, re.S)
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'math_number_all': True,
'extensions': ['sphinx.ext.mathjax']})
def test_math_number_all_mathjax(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').text()
html = (r'\s*'
r'
\(1\)\xb6\\\[a\^2\+b\^2=c\^2\\\]
')
assert re.search(html, content, re.S)
@pytest.mark.sphinx('latex', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax']})
def test_math_number_all_latex(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'test.tex').text()
macro = (r'\\begin{equation\*}\s*'
r'\\begin{split}a\^2\+b\^2=c\^2\\end{split}\s*'
r'\\end{equation\*}')
assert re.search(macro, content, re.S)
macro = r'Inline \\\(E=mc\^2\\\)'
assert re.search(macro, content, re.S)
macro = (r'\\begin{equation\*}\s*'
r'\\begin{split}e\^{i\\pi}\+1=0\\end{split}\s+'
r'\\end{equation\*}')
assert re.search(macro, content, re.S)
macro = (r'\\begin{align\*}\\!\\begin{aligned}\s*'
r'S &= \\pi r\^2\\\\\s*'
r'V &= \\frac\{4}\{3} \\pi r\^3\\\\\s*'
r'\\end{aligned}\\end{align\*}')
assert re.search(macro, content, re.S)
macro = r'Referencing equation \\eqref{equation:math:foo}.'
assert re.search(macro, content, re.S)
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax'],
'math_eqref_format': 'Eq.{number}'})
def test_math_eqref_format_html(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').text()
html = ('Referencing equation Eq.1.
')
assert html in content
@pytest.mark.sphinx('latex', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax'],
'math_eqref_format': 'Eq.{number}'})
def test_math_eqref_format_latex(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'test.tex').text()
macro = r'Referencing equation Eq.\\ref{equation:math:foo}.'
assert re.search(macro, content, re.S)