diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-02-28 02:03:59 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-02-28 02:05:21 +0900 |
commit | 9c2e7b6798c51cf631af5918fc217992ad944e2f (patch) | |
tree | 89bd99d8930b50293343dbe5c5828cbca3651ad2 | |
parent | 6c244bdd696ac320d02735cf1724b047515a7847 (diff) | |
download | sphinx-git-9c2e7b6798c51cf631af5918fc217992ad944e2f.tar.gz |
Fix #6067: LaTeX: images having a target are not aligned even if specified
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/writers/latex.py | 8 | ||||
-rw-r--r-- | tests/roots/test-images/index.rst | 4 | ||||
-rw-r--r-- | tests/test_build_latex.py | 4 |
4 files changed, 15 insertions, 2 deletions
@@ -20,6 +20,7 @@ Bugs fixed * #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 +* #6067: LaTeX: images having a target are not aligned even if specified * #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 65e64a61b..0eafc0af9 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1655,7 +1655,11 @@ class LaTeXTranslator(nodes.NodeVisitor): # in reverse order post = [] # type: List[unicode] include_graphics_options = [] - is_inline = self.is_inline(node) + has_hyperlink = isinstance(node.parent, nodes.reference) + if has_hyperlink: + is_inline = self.is_inline(node.parent) + else: + is_inline = self.is_inline(node) if 'width' in attrs: if 'scale' in attrs: w = self.latex_image_length(attrs['width'], attrs['scale']) @@ -1697,7 +1701,7 @@ class LaTeXTranslator(nodes.NodeVisitor): if self.in_parsed_literal: pre.append('{\\sphinxunactivateextrasandspace ') post.append('}') - if not is_inline: + if not is_inline and not has_hyperlink: pre.append('\n\\noindent') post.append('\n') pre.reverse() diff --git a/tests/roots/test-images/index.rst b/tests/roots/test-images/index.rst index 577dd0f88..67b742b27 100644 --- a/tests/roots/test-images/index.rst +++ b/tests/roots/test-images/index.rst @@ -18,6 +18,10 @@ test-image .. image:: rimg.png :target: https://www.sphinx-doc.org/ +.. image:: rimg.png + :align: center + :target: https://www.python.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 fe092113e..03558cd92 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1202,6 +1202,10 @@ def test_latex_images(app, status, warning): assert ('\\sphinxhref{https://www.sphinx-doc.org/}' '{\\sphinxincludegraphics{{rimg}.png}}\n\n' in result) + # a centerized image having target + assert ('\\sphinxhref{https://www.python.org/}{{\\hspace*{\\fill}' + '\\sphinxincludegraphics{{rimg}.png}\\hspace*{\\fill}}}\n\n' in result) + @pytest.mark.sphinx('latex', testroot='latex-index') def test_latex_index(app, status, warning): |