Fix vertical space before equation in latex (closes: #4574)

This commit is contained in:
jfbu 2018-03-11 11:36:16 +01:00
parent 87e8dd16b2
commit 711b8ecf70
5 changed files with 53 additions and 0 deletions

View File

@ -1959,6 +1959,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
if id.startswith('index-'): if id.startswith('index-'):
return return
# equations also need no extra blank line nor hypertarget
if id.startswith('equation-'):
return
# insert blank line, if the target follows a paragraph node # insert blank line, if the target follows a paragraph node
index = node.parent.index(node) index = node.parent.index(node)
if index > 0 and isinstance(node.parent[index - 1], nodes.paragraph): if index > 0 and isinstance(node.parent[index - 1], nodes.paragraph):

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
master_doc = 'equations'
extensions = ['sphinx.ext.imgmath']

View File

@ -0,0 +1,21 @@
test-latex-equation
===================
Equation without a label.
.. math::
E = mc^2
Equation with label.
.. math:: E = hv
:label: test
Second equation without label.
.. math::
c^2 = a^2 + b^2
Equation with label :eq:`test` is important.

View File

@ -0,0 +1,13 @@
Equation without a label.
\begin{equation*}
\begin{split}E = mc^2\end{split}
\end{equation*}
Equation with label.
\begin{equation}\label{equation:equations:test}
\begin{split}E = hv\end{split}
\end{equation}
Second equation without label.
\begin{equation*}
\begin{split}c^2 = a^2 + b^2\end{split}
\end{equation*}
Equation with label \eqref{equation:equations:test} is important.

View File

@ -1134,6 +1134,16 @@ def test_latex_index(app, status, warning):
assert '\n\\index{Einstein}\\index{relativity}\\ignorespaces \nand' in result assert '\n\\index{Einstein}\\index{relativity}\\ignorespaces \nand' in result
@pytest.mark.sphinx('latex', testroot='latex-equations')
def test_latex_equations(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
expected = (app.srcdir / 'expects' / 'latex-equations.tex').text().strip()
assert expected in result
@pytest.mark.sphinx('latex', testroot='image-in-parsed-literal') @pytest.mark.sphinx('latex', testroot='image-in-parsed-literal')
def test_latex_image_in_parsed_literal(app, status, warning): def test_latex_image_in_parsed_literal(app, status, warning):
app.builder.build_all() app.builder.build_all()