Fix #4085 Failed PDF build from image in parsed-literal

This commit is contained in:
jfbu 2017-09-27 09:54:18 +02:00
parent e15e9a79b4
commit dc129e0532
6 changed files with 37 additions and 3 deletions

View File

@ -16,6 +16,8 @@ Features added
Bugs fixed
----------
* #4085: Failed PDF build from image in parsed-literal using ``:align:`` option
Testing
--------

View File

@ -1702,9 +1702,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
pre = [] # type: List[unicode]
# in reverse order
post = [] # type: List[unicode]
if self.in_parsed_literal:
pre = ['\\begingroup\\sphinxunactivateextrasandspace\\relax ']
post = ['\\endgroup ']
include_graphics_options = []
is_inline = self.is_inline(node)
if 'width' in attrs:
@ -1744,6 +1741,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
post.append(align_prepost[is_inline, attrs['align']][1])
except KeyError:
pass
if self.in_parsed_literal:
pre.append('\\begingroup\\sphinxunactivateextrasandspace\\relax ')
post.append('\\endgroup ')
if not is_inline:
pre.append('\n\\noindent')
post.append('\n')

View File

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
master_doc = 'index'
exclude_patterns = ['_build']
rst_epilog = '''
.. |picture| image:: pic.png
:width: 15pt
:scale: 200%
:align: middle
:alt: alternative_text
'''

View File

@ -0,0 +1,9 @@
test-image-in-parsed-literal
============================
Dummy text
.. parsed-literal::
|picture|

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

View File

@ -1029,3 +1029,13 @@ def test_latex_index(app, status, warning):
result = (app.outdir / 'Python.tex').text(encoding='utf8')
assert 'A \\index{famous}famous \\index{equation}equation:\n' in result
assert '\n\\index{Einstein}\\index{relativity}\\ignorespaces \nand' 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()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
assert (r'\begingroup\sphinxunactivateextrasandspace\relax \raisebox{-0.5\height}'
r'{\scalebox{2.000000}{\sphinxincludegraphics[width=15bp]{{pic}.png}}}'
r'\endgroup ') in result