mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2492: Figure directive with :figwidth: generates incorrect Latex-code
This commit is contained in:
parent
5ecbbec79d
commit
4789ef899f
1
CHANGES
1
CHANGES
@ -49,6 +49,7 @@ Bugs fixed
|
||||
* Show error reason when multiple math extensions are loaded (ref: #2499)
|
||||
* #2483: any figure number was not assigned if figure title contains only non text objects
|
||||
* #2501: Unicode subscript numbers are normalized in LaTeX
|
||||
* #2492: Figure directive with :figwidth: generates incorrect Latex-code
|
||||
|
||||
|
||||
Release 1.4.1 (released Apr 12, 2016)
|
||||
|
@ -263,6 +263,24 @@ class Table(object):
|
||||
self.longtable = False
|
||||
|
||||
|
||||
def width_to_latex_length(length_str):
|
||||
"""Convert `length_str` with rst length to LaTeX length.
|
||||
|
||||
This function is copied from docutils' latex writer
|
||||
"""
|
||||
match = re.match('(\d*\.?\d*)\s*(\S*)', length_str)
|
||||
if not match:
|
||||
return length_str
|
||||
value, unit = match.groups()[:2]
|
||||
if unit in ('', 'pt'):
|
||||
length_str = '%sbp' % value # convert to 'bp'
|
||||
# percentage: relate to current line width
|
||||
elif unit == '%':
|
||||
length_str = '%.3f\\linewidth' % (float(value)/100.0)
|
||||
|
||||
return length_str
|
||||
|
||||
|
||||
class LaTeXTranslator(nodes.NodeVisitor):
|
||||
sectionnames = ["part", "chapter", "section", "subsection",
|
||||
"subsubsection", "paragraph", "subparagraph"]
|
||||
@ -1409,7 +1427,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if 'width' in node and node.get('align', '') in ('left', 'right'):
|
||||
self.body.append('\\begin{wrapfigure}{%s}{%s}\n\\centering' %
|
||||
(node['align'] == 'right' and 'r' or 'l',
|
||||
node['width']))
|
||||
width_to_latex_length(node['width'])))
|
||||
self.context.append(ids + '\\end{wrapfigure}\n')
|
||||
elif self.in_minipage:
|
||||
if ('align' not in node.attributes or
|
||||
|
@ -235,6 +235,11 @@ Figures
|
||||
|
||||
Description paragraph is wraped with legend node.
|
||||
|
||||
.. figure:: rimg.png
|
||||
:align: right
|
||||
:figwidth: 50%
|
||||
|
||||
figure with align & figwidth option
|
||||
|
||||
Version markup
|
||||
--------------
|
||||
|
@ -31,14 +31,14 @@ http://www.python.org/logo.png
|
||||
reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
|
||||
:encoding: option\\n?
|
||||
%(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png
|
||||
(%(root)s/markup.txt:363: WARNING: invalid single index entry u'')?
|
||||
(%(root)s/markup.txt:368: WARNING: invalid single index entry u'')?
|
||||
(%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
|
||||
with "\\?": b?'here: >>>(\\\\|/)xbb<<<'
|
||||
)?"""
|
||||
|
||||
HTML_WARNINGS = ENV_WARNINGS + """\
|
||||
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
|
||||
%(root)s/markup.txt:275: WARNING: Could not lex literal_block as "c". Highlighting skipped.
|
||||
%(root)s/markup.txt:280: WARNING: Could not lex literal_block as "c". Highlighting skipped.
|
||||
%(root)s/footnote.txt:60: WARNING: citation not found: missing
|
||||
%(root)s/markup.txt:164: WARNING: unknown option: &option
|
||||
"""
|
||||
|
@ -27,7 +27,7 @@ LATEX_WARNINGS = ENV_WARNINGS + """\
|
||||
%(root)s/markup.txt:164: WARNING: unknown option: &option
|
||||
%(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/markup.txt:275: WARNING: Could not lex literal_block as "c". Highlighting skipped.
|
||||
%(root)s/markup.txt:280: WARNING: Could not lex literal_block as "c". Highlighting skipped.
|
||||
"""
|
||||
|
||||
if PY3:
|
||||
@ -106,6 +106,16 @@ def test_latex(app, status, warning):
|
||||
run_latex(app.outdir)
|
||||
|
||||
|
||||
@with_app(buildername='latex')
|
||||
def test_writer(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
|
||||
|
||||
assert ('\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n'
|
||||
'\\includegraphics{{rimg}.png}\n\\caption{figure with align \\& figwidth option}'
|
||||
'\\label{markup:id7}\\end{wrapfigure}' in result)
|
||||
|
||||
|
||||
@with_app(buildername='latex', freshenv=True, # use freshenv to check warnings
|
||||
confoverrides={'latex_documents': [
|
||||
('contents', 'SphinxTests.tex', 'Sphinx Tests Documentation',
|
||||
|
Loading…
Reference in New Issue
Block a user