From 76e29ca5b3ddf0f745fdc905e36480f1e8472098 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 15 Jan 2016 01:39:31 -0800 Subject: [PATCH] Use "align" environment to wrap math equations instead of "gather" Using align brings the benefit when multiple math equations are in one math directive, alignment is provided. We also use "aligned" to wrap the equations since in this way all the equations will be given only one label/tag, while previously only the first equation is labeled. --- sphinx/ext/mathbase.py | 19 +++++++++++-------- tests/roots/test-ext-math/conf.py | 3 +++ tests/roots/test-ext-math/index.rst | 8 ++++++++ tests/test_ext_math.py | 7 +++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index 6dc1c7323..8ede05b87 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -34,16 +34,19 @@ def wrap_displaymath(math, label, numbering): for i, part in enumerate(parts): if not part.strip(): continue - if label is not None and i == 0: - ret.append('\\begin{split}%s\\end{split}' % part + - (label and '\\label{'+label+'}' or '')) - else: - ret.append(r'\begin{split}%s\end{split}' % part) - if not numbering: - ret.append(r'\notag') + ret.append(r'\begin{split}%s\end{split}' % part) if not ret: return '' - return '\\begin{gather}\n' + '\\\\'.join(ret) + '\n\\end{gather}' + if label is not None or numbering: + env_begin = r'\begin{align}' + if label is not None: + env_begin += r'\label{%s}' % label + env_end = r'\end{align}' + else: + env_begin = r'\begin{align*}' + env_end = r'\end{align*}' + return ('%s\\begin{aligned}\n%s\\end{aligned}%s') % ( + env_begin, '\\\\\n'.join(ret), env_end) def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]): diff --git a/tests/roots/test-ext-math/conf.py b/tests/roots/test-ext-math/conf.py index f81c30bc4..3fe886c17 100644 --- a/tests/roots/test-ext-math/conf.py +++ b/tests/roots/test-ext-math/conf.py @@ -1,3 +1,6 @@ # -*- coding: utf-8 -*- master_doc = 'index' + +latex_documents = [ + (master_doc, 'test.tex', 'Math Extension Testing', 'Sphinx', 'report')] diff --git a/tests/roots/test-ext-math/index.rst b/tests/roots/test-ext-math/index.rst index 491edda95..02f50c20a 100644 --- a/tests/roots/test-ext-math/index.rst +++ b/tests/roots/test-ext-math/index.rst @@ -8,3 +8,11 @@ Inline :math:`E=mc^2` Second math .. math:: e^{i\pi}+1=0 + +Multi math equations + +.. math:: + + S &= \pi r^2 + + V &= \frac{4}{3} \pi r^3 diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 84bca95a3..d72da7934 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -53,3 +53,10 @@ def test_math_number_all(app, status, warning): html = (r'
\s*' r'\(1\)\\\[a\^2\+b\^2=c\^2\\\]
') assert re.search(html, content, re.S) + +@with_app('latex', testroot='ext-math', + confoverrides={'extensions': ['sphinx.ext.mathjax']}) +def test_math_number_all(app, status, warning): + app.builder.build_all() + + content = (app.outdir / 'test.tex').text()