Fix the caption of figure is always put on center even if `:align:` was specified

This commit is contained in:
Takeshi KOMIYA 2016-05-04 01:21:16 +09:00
parent 4789ef899f
commit 885653a35d
5 changed files with 20 additions and 7 deletions

View File

@ -50,6 +50,7 @@ Bugs fixed
* #2483: any figure number was not assigned if figure title contains only non text objects * #2483: any figure number was not assigned if figure title contains only non text objects
* #2501: Unicode subscript numbers are normalized in LaTeX * #2501: Unicode subscript numbers are normalized in LaTeX
* #2492: Figure directive with :figwidth: generates incorrect Latex-code * #2492: Figure directive with :figwidth: generates incorrect Latex-code
* The caption of figure is always put on center even if ``:align:`` was specified
Release 1.4.1 (released Apr 12, 2016) Release 1.4.1 (released Apr 12, 2016)

View File

@ -1424,10 +1424,13 @@ class LaTeXTranslator(nodes.NodeVisitor):
isinstance(node.children[0], nodes.image) and isinstance(node.children[0], nodes.image) and
node.children[0]['ids']): node.children[0]['ids']):
ids += self.hypertarget(node.children[0]['ids'][0], anchor=False) ids += self.hypertarget(node.children[0]['ids'][0], anchor=False)
if 'width' in node and node.get('align', '') in ('left', 'right'): if node.get('align', '') in ('left', 'right'):
if 'width' in node:
length = width_to_latex_length(node['width'])
else:
length = '0pt'
self.body.append('\\begin{wrapfigure}{%s}{%s}\n\\centering' % self.body.append('\\begin{wrapfigure}{%s}{%s}\n\\centering' %
(node['align'] == 'right' and 'r' or 'l', (node['align'] == 'right' and 'r' or 'l', length))
width_to_latex_length(node['width'])))
self.context.append(ids + '\\end{wrapfigure}\n') self.context.append(ids + '\\end{wrapfigure}\n')
elif self.in_minipage: elif self.in_minipage:
if ('align' not in node.attributes or if ('align' not in node.attributes or

View File

@ -235,6 +235,11 @@ Figures
Description paragraph is wraped with legend node. Description paragraph is wraped with legend node.
.. figure:: rimg.png
:align: right
figure with align option
.. figure:: rimg.png .. figure:: rimg.png
:align: right :align: right
:figwidth: 50% :figwidth: 50%

View File

@ -31,14 +31,14 @@ http://www.python.org/logo.png
reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \ reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
:encoding: option\\n? :encoding: option\\n?
%(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png %(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png
(%(root)s/markup.txt:368: WARNING: invalid single index entry u'')? (%(root)s/markup.txt:373: WARNING: invalid single index entry u'')?
(%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \ (%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
with "\\?": b?'here: >>>(\\\\|/)xbb<<<' with "\\?": b?'here: >>>(\\\\|/)xbb<<<'
)?""" )?"""
HTML_WARNINGS = ENV_WARNINGS + """\ HTML_WARNINGS = ENV_WARNINGS + """\
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*' %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
%(root)s/markup.txt:280: WARNING: Could not lex literal_block as "c". Highlighting skipped. %(root)s/markup.txt:285: WARNING: Could not lex literal_block as "c". Highlighting skipped.
%(root)s/footnote.txt:60: WARNING: citation not found: missing %(root)s/footnote.txt:60: WARNING: citation not found: missing
%(root)s/markup.txt:164: WARNING: unknown option: &option %(root)s/markup.txt:164: WARNING: unknown option: &option
""" """

View File

@ -27,7 +27,7 @@ LATEX_WARNINGS = ENV_WARNINGS + """\
%(root)s/markup.txt:164: WARNING: unknown option: &option %(root)s/markup.txt:164: WARNING: unknown option: &option
%(root)s/footnote.txt:60: WARNING: citation not found: missing %(root)s/footnote.txt:60: WARNING: citation not found: missing
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*' %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
%(root)s/markup.txt:280: WARNING: Could not lex literal_block as "c". Highlighting skipped. %(root)s/markup.txt:285: WARNING: Could not lex literal_block as "c". Highlighting skipped.
""" """
if PY3: if PY3:
@ -111,9 +111,13 @@ def test_writer(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8') result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
assert ('\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
'\\includegraphics{{rimg}.png}\n\\caption{figure with align option}'
'\\label{markup:id7}\\end{wrapfigure}' in result)
assert ('\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n' assert ('\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n'
'\\includegraphics{{rimg}.png}\n\\caption{figure with align \\& figwidth option}' '\\includegraphics{{rimg}.png}\n\\caption{figure with align \\& figwidth option}'
'\\label{markup:id7}\\end{wrapfigure}' in result) '\\label{markup:id8}\\end{wrapfigure}' in result)
@with_app(buildername='latex', freshenv=True, # use freshenv to check warnings @with_app(buildername='latex', freshenv=True, # use freshenv to check warnings