diff --git a/CHANGES b/CHANGES index b98745900..5f5262702 100644 --- a/CHANGES +++ b/CHANGES @@ -120,6 +120,9 @@ New features added - The new ``html_link_suffix`` config value can be used to select the suffix of generated links between HTML files. + - #96: The LaTeX builder now supports figures wrapped by text, when + using the ``figwidth`` option and right/left alignment. + * New translations: - Italian by Sandro Dentella. diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index df86f9972..2de29010c 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -9,6 +9,19 @@ :license: BSD, see LICENSE for details. """ +from docutils.parsers.rst import directives +from docutils.parsers.rst.directives import images + +# import and register directives from sphinx.directives.desc import * from sphinx.directives.code import * from sphinx.directives.other import * + + +# allow units for the figure's "figwidth" +try: + images.Figure.option_spec['figwidth'] = \ + directives.length_or_percentage_or_unitless +except AttributeError: + images.figure.options['figwidth'] = \ + directives.length_or_percentage_or_unitless diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 367683088..0ce6b8637 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -17,11 +17,15 @@ \RequirePackage{makeidx} \RequirePackage{framed} \RequirePackage{color} +% For highlighted code. \RequirePackage{fancyvrb} +% For table captions. \RequirePackage{threeparttable} % Handle footnotes in tables. \RequirePackage{footnote} \makesavenoteenv{tabulary} +% For floating figures in the text. +\RequirePackage{wrapfig} % Redefine these colors to your liking in the preamble. \definecolor{TitleColor}{rgb}{0.126,0.263,0.361} diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 841a5ba14..2ff242036 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -850,17 +850,23 @@ class LaTeXTranslator(nodes.NodeVisitor): pass def visit_figure(self, node): - if (not node.attributes.has_key('align') or - node.attributes['align'] == 'center'): - # centering does not add vertical space like center. - align = '\n\\centering' - align_end = '' + if node.has_key('width') 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'])) + self.context.append('\\end{wrapfigure}\n') else: - # TODO non vertical space for other alignments. - align = '\\begin{flush%s}' % node.attributes['align'] - align_end = '\\end{flush%s}' % node.attributes['align'] - self.body.append('\\begin{figure}[htbp]%s\n' % align) - self.context.append('%s\\end{figure}\n' % align_end) + if (not node.attributes.has_key('align') or + node.attributes['align'] == 'center'): + # centering does not add vertical space like center. + align = '\n\\centering' + align_end = '' + else: + # TODO non vertical space for other alignments. + align = '\\begin{flush%s}' % node.attributes['align'] + align_end = '\\end{flush%s}' % node.attributes['align'] + self.body.append('\\begin{figure}[htbp]%s\n' % align) + self.context.append('%s\\end{figure}\n' % align_end) def depart_figure(self, node): self.body.append(self.context.pop())