Fix #2593: latex crashes if any figures in the table

This commit is contained in:
Takeshi KOMIYA 2016-06-02 23:57:14 +09:00
parent bb360d8984
commit bb6bb7ded6
5 changed files with 34 additions and 4 deletions

View File

@ -13,6 +13,7 @@ Bugs fixed
* #2602: URL redirection breaks the hyperlinks generated by `sphinx.ext.intersphinx`
* #2613: Show warnings if merged extensions are loaded
* #2619: make sure amstext LaTeX package always loaded (ref: d657225, 488ee52, 9d82cad and #2615)
* #2593: latex crashes if any figures in the table
Release 1.4.2 (released May 29, 2016)

View File

@ -835,3 +835,11 @@
% if the left page space is less than \literalblockneedspace, insert page-break
\newcommand{\literalblockneedspace}{5\baselineskip}
\newcommand{\literalblockwithoutcaptionneedspace}{1.5\baselineskip}
% figure in table
\newenvironment{figure-in-table}[1][\linewidth]{
\def\@captype{figure}%
\minipage{#1}%
}{\endminipage}
% store \caption to use it in longtable
\let\figcaption\caption

View File

@ -1433,7 +1433,15 @@ class LaTeXTranslator(nodes.NodeVisitor):
isinstance(node.children[0], nodes.image) and
node.children[0]['ids']):
ids += self.hypertarget(node.children[0]['ids'][0], anchor=False)
if node.get('align', '') in ('left', 'right'):
if self.table:
# TODO: support align option
if 'width' in node:
length = width_to_latex_length(node['width'])
self.body.append('\\begin{figure-in-table}[%s]\n\\centering' % length)
else:
self.body.append('\\begin{figure-in-table}\n\\centering')
self.context.append(ids + '\\end{figure-in-table}\n')
elif node.get('align', '') in ('left', 'right'):
if 'width' in node:
length = width_to_latex_length(node['width'])
elif 'width' in node[0]:
@ -1477,6 +1485,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{')
elif self.in_minipage and isinstance(node.parent, nodes.figure):
self.body.append('\\captionof{figure}{')
elif self.table and node.parent.tagname == 'figure':
self.body.append('\\figcaption{')
else:
self.body.append('\\caption{')

View File

@ -220,6 +220,13 @@ Tables with multirow and multicol:
| |
+----+
.. list-table::
:header-rows: 0
* - .. figure:: img.png
figure in table
Figures
-------

View File

@ -111,18 +111,22 @@ def test_writer(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
assert ('\\begin{figure-in-table}\n\\centering\n'
'\\includegraphics{{img}.png}\n'
'\\figcaption{figure in table}\\label{markup:id7}\\end{figure-in-table}' in result)
assert ('\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
'\\includegraphics{{rimg}.png}\n\\caption{figure with align option}'
'\\label{markup:id7}\\end{wrapfigure}' in result)
'\\label{markup:id8}\\end{wrapfigure}' in result)
assert ('\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n'
'\\includegraphics{{rimg}.png}\n\\caption{figure with align \\& figwidth option}'
'\\label{markup:id8}\\end{wrapfigure}' in result)
'\\label{markup:id9}\\end{wrapfigure}' in result)
assert ('\\begin{wrapfigure}{r}{3cm}\n\\centering\n'
'\\includegraphics[width=3cm]{{rimg}.png}\n'
'\\caption{figure with align \\& width option}'
'\\label{markup:id9}\\end{wrapfigure}' in result)
'\\label{markup:id10}\\end{wrapfigure}' in result)
@with_app(buildername='latex', freshenv=True, # use freshenv to check warnings