Fix #2370: the equations are slightly misaligned in LaTeX

This commit is contained in:
Takeshi KOMIYA committed 2016-04-14 10:37:54 +09:00
1 parent 9a7bbb0947
commit 39396a4b1e
3 files changed
+24 -4

No files matched your search

+2
View File
@@ -4,6 +4,8 @@ Release 1.4.2 (in development)
Bugs fixed
----------
* #2370: the equations are slightly misaligned in LaTeX writer
Release 1.4.1 (released Apr 12, 2016)
=====================================
+3 -4
View File
@@ -31,10 +31,10 @@ class eqref(nodes.Inline, nodes.TextElement):
def wrap_displaymath(math, label, numbering):
parts = math.split('\n\n')
ret = []
for i, part in enumerate(parts):
for part in parts:
if not part.strip():
continue
ret.append(r'\begin{split}%s\end{split}' % part)
ret.append('\\!\\begin{split}%s\\end{split}\\\\\n' % part)
if not ret:
return ''
if label is not None or numbering:
@@ -45,8 +45,7 @@ def wrap_displaymath(math, label, numbering):
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)
return '%s\\begin{aligned}\n%s\\end{aligned}%s' % (env_begin, ''.join(ret), env_end)
def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
+19
View File
@@ -71,3 +71,22 @@ def test_math_number_all_latex(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'test.tex').text()
print content
macro = (r'\\begin{align\*}\\begin{aligned}\s*'
r'\\!\\begin{split}a\^2\+b\^2=c\^2\\end{split}\\\\\s*'
r'\\end{aligned}\\end{align\*}')
assert re.search(macro, content, re.S)
macro = r'Inline \\\(E=mc\^2\\\)'
assert re.search(macro, content, re.S)
macro = (r'\\begin{align\*}\\begin{aligned}\s*'
r'\\!\\begin{split}e\^{i\\pi}\+1=0\\end{split}\\\\\s+'
r'\\end{aligned}\\end{align\*}')
assert re.search(macro, content, re.S)
macro = (r'\\begin{align\*}\\begin{aligned}\s*'
r'\\!\\begin{split}S &= \\pi r\^2\\end{split}\\\\\s*'
r'\\!\\begin{split}V &= \\frac\{4}\{3} \\pi r\^3\\end{split}\\\\\s*'
r'\\end{aligned}\\end{align\*}')
assert re.search(macro, content, re.S)