summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-François B <2589111+jfbu@users.noreply.github.com>2023-01-08 19:40:24 +0100
committerJean-François B <2589111+jfbu@users.noreply.github.com>2023-01-08 19:40:24 +0100
commit19b07109446cf7436a27d9b5ee921c7da3049215 (patch)
tree6684ac612b9694a5fa05e4301e713ffd17fb82fd
parent670bcb743b718d7b3ced548c645aafe71d0310eb (diff)
downloadsphinx-git-19b07109446cf7436a27d9b5ee921c7da3049215.tar.gz
Fix #11079 (LaTeX: figure with align disappears if not followed by text)
-rw-r--r--CHANGES3
-rw-r--r--sphinx/writers/latex.py5
-rw-r--r--tests/test_build_latex.py9
3 files changed, 13 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 04eed21c5..f5126e0ac 100644
--- a/CHANGES
+++ b/CHANGES
@@ -26,6 +26,9 @@ Features added
Bugs fixed
----------
+* #11079: LaTeX: figures with align attribute may disappear and strangely impact
+ following lists
+
Testing
--------
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 70dec716d..acd44605c 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -1366,7 +1366,10 @@ class LaTeXTranslator(SphinxTranslator):
self.body.append(r'\begin{wrapfigure}{%s}{%s}' %
('r' if node['align'] == 'right' else 'l', length or '0pt') + CR)
self.body.append(r'\centering')
- self.context.append(r'\end{wrapfigure}' + CR)
+ self.context.append(r'\end{wrapfigure}' +
+ BLANKLINE +
+ r'\mbox{}\par\vskip-\dimexpr\baselineskip+\parskip\relax' +
+ CR) # avoid disappearance if no text next issues/11079
elif self.in_minipage:
self.body.append(CR + r'\begin{center}')
self.context.append(r'\end{center}' + CR)
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index 3f1206ac8..1090dbfec 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -120,19 +120,22 @@ def test_writer(app, status, warning):
assert ('\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n'
'\\caption{figure with align option}\\label{\\detokenize{markup:id9}}'
- '\\end{wrapfigure}' in result)
+ '\\end{wrapfigure}\n\n'
+ '\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' in result)
assert ('\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n'
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n'
'\\caption{figure with align \\& figwidth option}'
'\\label{\\detokenize{markup:id10}}'
- '\\end{wrapfigure}' in result)
+ '\\end{wrapfigure}\n\n'
+ '\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' in result)
assert ('\\begin{wrapfigure}{r}{3cm}\n\\centering\n'
'\\noindent\\sphinxincludegraphics[width=3cm]{{rimg}.png}\n'
'\\caption{figure with align \\& width option}'
'\\label{\\detokenize{markup:id11}}'
- '\\end{wrapfigure}' in result)
+ '\\end{wrapfigure}\n\n'
+ '\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' in result)
assert 'Footnotes' not in result