mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2593: latex crashes if any figures in the table
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -13,6 +13,7 @@ Bugs fixed
|
|||||||
* #2602: URL redirection breaks the hyperlinks generated by `sphinx.ext.intersphinx`
|
* #2602: URL redirection breaks the hyperlinks generated by `sphinx.ext.intersphinx`
|
||||||
* #2613: Show warnings if merged extensions are loaded
|
* #2613: Show warnings if merged extensions are loaded
|
||||||
* #2619: make sure amstext LaTeX package always loaded (ref: d657225, 488ee52, 9d82cad and #2615)
|
* #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)
|
Release 1.4.2 (released May 29, 2016)
|
||||||
|
|||||||
@@ -835,3 +835,11 @@
|
|||||||
% if the left page space is less than \literalblockneedspace, insert page-break
|
% if the left page space is less than \literalblockneedspace, insert page-break
|
||||||
\newcommand{\literalblockneedspace}{5\baselineskip}
|
\newcommand{\literalblockneedspace}{5\baselineskip}
|
||||||
\newcommand{\literalblockwithoutcaptionneedspace}{1.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
|
||||||
|
|||||||
@@ -1433,7 +1433,15 @@ 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 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:
|
if 'width' in node:
|
||||||
length = width_to_latex_length(node['width'])
|
length = width_to_latex_length(node['width'])
|
||||||
elif 'width' in node[0]:
|
elif 'width' in node[0]:
|
||||||
@@ -1477,6 +1485,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{')
|
self.body.append('\\SphinxSetupCaptionForVerbatim{literal-block}{')
|
||||||
elif self.in_minipage and isinstance(node.parent, nodes.figure):
|
elif self.in_minipage and isinstance(node.parent, nodes.figure):
|
||||||
self.body.append('\\captionof{figure}{')
|
self.body.append('\\captionof{figure}{')
|
||||||
|
elif self.table and node.parent.tagname == 'figure':
|
||||||
|
self.body.append('\\figcaption{')
|
||||||
else:
|
else:
|
||||||
self.body.append('\\caption{')
|
self.body.append('\\caption{')
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,13 @@ Tables with multirow and multicol:
|
|||||||
| |
|
| |
|
||||||
+----+
|
+----+
|
||||||
|
|
||||||
|
.. list-table::
|
||||||
|
:header-rows: 0
|
||||||
|
|
||||||
|
* - .. figure:: img.png
|
||||||
|
|
||||||
|
figure in table
|
||||||
|
|
||||||
|
|
||||||
Figures
|
Figures
|
||||||
-------
|
-------
|
||||||
|
|||||||
@@ -111,18 +111,22 @@ 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{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'
|
assert ('\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
|
||||||
'\\includegraphics{{rimg}.png}\n\\caption{figure with align option}'
|
'\\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'
|
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:id8}\\end{wrapfigure}' in result)
|
'\\label{markup:id9}\\end{wrapfigure}' in result)
|
||||||
|
|
||||||
assert ('\\begin{wrapfigure}{r}{3cm}\n\\centering\n'
|
assert ('\\begin{wrapfigure}{r}{3cm}\n\\centering\n'
|
||||||
'\\includegraphics[width=3cm]{{rimg}.png}\n'
|
'\\includegraphics[width=3cm]{{rimg}.png}\n'
|
||||||
'\\caption{figure with align \\& width option}'
|
'\\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
|
@with_app(buildername='latex', freshenv=True, # use freshenv to check warnings
|
||||||
|
|||||||
Reference in New Issue
Block a user