#96: The LaTeX builder now supports figures wrapped by text, when using the `figwidth` option and right/left alignment.

This commit is contained in:
Georg Brandl
2009-02-21 20:28:20 +01:00
parent 18c3748c98
commit edaf639c2c
4 changed files with 36 additions and 10 deletions

View File

@@ -120,6 +120,9 @@ New features added
- The new ``html_link_suffix`` config value can be used to select - The new ``html_link_suffix`` config value can be used to select
the suffix of generated links between HTML files. 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: * New translations:
- Italian by Sandro Dentella. - Italian by Sandro Dentella.

View File

@@ -9,6 +9,19 @@
:license: BSD, see LICENSE for details. :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.desc import *
from sphinx.directives.code import * from sphinx.directives.code import *
from sphinx.directives.other 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

View File

@@ -17,11 +17,15 @@
\RequirePackage{makeidx} \RequirePackage{makeidx}
\RequirePackage{framed} \RequirePackage{framed}
\RequirePackage{color} \RequirePackage{color}
% For highlighted code.
\RequirePackage{fancyvrb} \RequirePackage{fancyvrb}
% For table captions.
\RequirePackage{threeparttable} \RequirePackage{threeparttable}
% Handle footnotes in tables. % Handle footnotes in tables.
\RequirePackage{footnote} \RequirePackage{footnote}
\makesavenoteenv{tabulary} \makesavenoteenv{tabulary}
% For floating figures in the text.
\RequirePackage{wrapfig}
% Redefine these colors to your liking in the preamble. % Redefine these colors to your liking in the preamble.
\definecolor{TitleColor}{rgb}{0.126,0.263,0.361} \definecolor{TitleColor}{rgb}{0.126,0.263,0.361}

View File

@@ -850,17 +850,23 @@ class LaTeXTranslator(nodes.NodeVisitor):
pass pass
def visit_figure(self, node): def visit_figure(self, node):
if (not node.attributes.has_key('align') or if node.has_key('width') and node.get('align', '') in ('left', 'right'):
node.attributes['align'] == 'center'): self.body.append('\\begin{wrapfigure}{%s}{%s}\n\\centering' %
# centering does not add vertical space like center. (node['align'] == 'right' and 'r' or 'l',
align = '\n\\centering' node['width']))
align_end = '' self.context.append('\\end{wrapfigure}\n')
else: else:
# TODO non vertical space for other alignments. if (not node.attributes.has_key('align') or
align = '\\begin{flush%s}' % node.attributes['align'] node.attributes['align'] == 'center'):
align_end = '\\end{flush%s}' % node.attributes['align'] # centering does not add vertical space like center.
self.body.append('\\begin{figure}[htbp]%s\n' % align) align = '\n\\centering'
self.context.append('%s\\end{figure}\n' % align_end) 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): def depart_figure(self, node):
self.body.append(self.context.pop()) self.body.append(self.context.pop())