Merge pull request #4729 from jfbu/latex_equation_nophantom

Fix vertical space before equation in latex (closes: #4574)
This commit is contained in:
Jean-François B 2018-03-15 10:29:10 +01:00 committed by GitHub
commit e1e46cdf8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 0 deletions

View File

@ -85,6 +85,7 @@ class MathDomain(Domain):
newnode['target'] = target
return newnode
else:
# TODO: perhaps use rather a sphinx-core provided prefix here?
node_id = make_id('equation-%s' % target)
if env.config.math_numfig and env.config.numfig:
if docname in env.toc_fignumbers:

View File

@ -1959,6 +1959,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
if id.startswith('index-'):
return
# equations also need no extra blank line nor hypertarget
# TODO: fix this dependency on mathbase extension internals
if id.startswith('equation-'):
return
# insert blank line, if the target follows a paragraph node
index = node.parent.index(node)
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
@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')
def test_latex_image_in_parsed_literal(app, status, warning):
app.builder.build_all()