Skip to content

Commit

Permalink
Fix #2370: the equations are slightly misaligned in LaTeX
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Apr 14, 2016
1 parent 9a7bbb0 commit 39396a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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)
=====================================
Expand Down
7 changes: 3 additions & 4 deletions sphinx/ext/mathbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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=[]):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_ext_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 39396a4

Please sign in to comment.