summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-02-28 01:39:29 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-02-28 02:04:12 +0900
commit6c244bdd696ac320d02735cf1724b047515a7847 (patch)
tree8eaccdf5375f53496f3998334193929a6e56e2f5
parent836d65f04c0abf328ee312125a2fd7bc2b55e09c (diff)
downloadsphinx-git-6c244bdd696ac320d02735cf1724b047515a7847.tar.gz
Fix #6067: LaTeX: images having a target are concatenated to next line
-rw-r--r--CHANGES1
-rw-r--r--sphinx/writers/latex.py4
-rw-r--r--tests/roots/test-images/index.rst3
-rw-r--r--tests/test_build_latex.py10
4 files changed, 17 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 65f39e538..eb2898927 100644
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,7 @@ Bugs fixed
* LaTeX: Remove extraneous space after author names on PDF title page (refs: #6004)
* #6026: LaTeX: A cross reference to definition list does not work
* #6046: LaTeX: ``TypeError`` is raised when invalid latex_elements given
+* #6067: LaTeX: images having a target are concatenated to next line
* #6019: imgconverter: Including multipage PDF fails
* #6047: autodoc: ``autofunction`` emits a warning for method objects
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 7cef81ff4..65e64a61b 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -1987,6 +1987,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
for id in node.get('ids'):
anchor = not self.in_caption
self.body += self.hypertarget(id, anchor=anchor)
+ if not self.is_inline(node):
+ self.body.append('\n')
uri = node.get('refuri', '')
if not uri and node.get('refid'):
uri = '%' + self.curfilestack[-1] + '#' + node['refid']
@@ -2039,6 +2041,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
def depart_reference(self, node):
# type: (nodes.Node) -> None
self.body.append(self.context.pop())
+ if not self.is_inline(node):
+ self.body.append('\n')
def visit_number_reference(self, node):
# type: (nodes.Node) -> None
diff --git a/tests/roots/test-images/index.rst b/tests/roots/test-images/index.rst
index d1478fab1..577dd0f88 100644
--- a/tests/roots/test-images/index.rst
+++ b/tests/roots/test-images/index.rst
@@ -15,6 +15,9 @@ test-image
.. image:: testimäge.png
+.. image:: rimg.png
+ :target: https://www.sphinx-doc.org/
+
.. a remote image
.. image:: https://www.python.org/static/img/python-logo.png
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index b81d2a3fe..fe092113e 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -1184,16 +1184,24 @@ def test_latex_raw_directive(app, status, warning):
@pytest.mark.sphinx('latex', testroot='images')
-def test_latex_remote_images(app, status, warning):
+def test_latex_images(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
+
+ # images are copied
assert '\\sphinxincludegraphics{{python-logo}.png}' in result
assert (app.outdir / 'python-logo.png').exists()
+
+ # not found images
assert '\\sphinxincludegraphics{{NOT_EXIST}.PNG}' not in result
assert ('WARNING: Could not fetch remote image: '
'http://example.com/NOT_EXIST.PNG [404]' in warning.getvalue())
+ # an image having target
+ assert ('\\sphinxhref{https://www.sphinx-doc.org/}'
+ '{\\sphinxincludegraphics{{rimg}.png}}\n\n' in result)
+
@pytest.mark.sphinx('latex', testroot='latex-index')
def test_latex_index(app, status, warning):