mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix vertical space before equation in latex (closes: #4574)
This commit is contained in:
parent
87e8dd16b2
commit
711b8ecf70
@ -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):
|
||||||
|
5
tests/roots/test-latex-equations/conf.py
Normal file
5
tests/roots/test-latex-equations/conf.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
master_doc = 'equations'
|
||||||
|
extensions = ['sphinx.ext.imgmath']
|
||||||
|
|
21
tests/roots/test-latex-equations/equations.rst
Normal file
21
tests/roots/test-latex-equations/equations.rst
Normal 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.
|
13
tests/roots/test-latex-equations/expects/latex-equations.tex
Normal file
13
tests/roots/test-latex-equations/expects/latex-equations.tex
Normal 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.
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user