summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/ext/mathbase.py1
-rw-r--r--sphinx/writers/latex.py5
-rw-r--r--tests/roots/test-latex-equations/conf.py5
-rw-r--r--tests/roots/test-latex-equations/equations.rst21
-rw-r--r--tests/roots/test-latex-equations/expects/latex-equations.tex13
-rw-r--r--tests/test_build_latex.py10
6 files changed, 55 insertions, 0 deletions
diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py
index 24c10df3c..3cc734537 100644
--- a/sphinx/ext/mathbase.py
+++ b/sphinx/ext/mathbase.py
@@ -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:
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index b425f79e6..ab15ec8b5 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -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):
diff --git a/tests/roots/test-latex-equations/conf.py b/tests/roots/test-latex-equations/conf.py
new file mode 100644
index 000000000..6122e9212
--- /dev/null
+++ b/tests/roots/test-latex-equations/conf.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+master_doc = 'equations'
+extensions = ['sphinx.ext.imgmath']
+
diff --git a/tests/roots/test-latex-equations/equations.rst b/tests/roots/test-latex-equations/equations.rst
new file mode 100644
index 000000000..2eef2f2a4
--- /dev/null
+++ b/tests/roots/test-latex-equations/equations.rst
@@ -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.
diff --git a/tests/roots/test-latex-equations/expects/latex-equations.tex b/tests/roots/test-latex-equations/expects/latex-equations.tex
new file mode 100644
index 000000000..ce07a0128
--- /dev/null
+++ b/tests/roots/test-latex-equations/expects/latex-equations.tex
@@ -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.
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index 4b02b7c54..602429a96 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -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()