From be57d3f421da441cdcac7656af8894564a52e3a3 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sat, 30 Jan 2021 10:10:15 +0100 Subject: [PATCH] Let latex writer line trimming from depart_entry() work as before #8081 This is cosmetic as the blank line starting varwidth environment used for merged table cells in latex output changed nothing to PDF. Nevertheless I extended a unit test to have a multi-paragraph merged cell using varwidth. What is important is that \sphinxAtStartPar line itself is never followed by blank line. --- sphinx/writers/latex.py | 3 ++- tests/roots/test-latex-table/complex.rst | 4 ++-- .../test-latex-table/expects/complex_spanning_cell.tex | 5 ----- tests/roots/test-latex-table/expects/gridtable.tex | 7 +++---- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 55d56d63023..0336e771609 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1163,7 +1163,8 @@ def visit_paragraph(self, node: Element) -> None: else: # the \sphinxAtStartPar is to allow hyphenation of first word of # a paragraph in narrow contexts such as in a table cell - self.body.append('\n\\sphinxAtStartPar\n') + # added as two items (cf. line trimming in depart_entry()) + self.body.extend(['\n','\\sphinxAtStartPar\n']) def depart_paragraph(self, node: Element) -> None: self.body.append('\n') diff --git a/tests/roots/test-latex-table/complex.rst b/tests/roots/test-latex-table/complex.rst index f3f927a3e7d..fa84f8266cf 100644 --- a/tests/roots/test-latex-table/complex.rst +++ b/tests/roots/test-latex-table/complex.rst @@ -11,9 +11,9 @@ grid table +---------+ +---------+ | cell2-1 | | cell2-3 | + +---------+---------+ -| | cell3-2 | +| | cell3-2-par1 | +---------+ | -| cell4-1 | | +| cell4-1 | cell3-2-par2 | +---------+---------+---------+ | cell5-1 | +---------+---------+---------+ diff --git a/tests/roots/test-latex-table/expects/complex_spanning_cell.tex b/tests/roots/test-latex-table/expects/complex_spanning_cell.tex index 4d432f5003c..966f39a955e 100644 --- a/tests/roots/test-latex-table/expects/complex_spanning_cell.tex +++ b/tests/roots/test-latex-table/expects/complex_spanning_cell.tex @@ -19,7 +19,6 @@ \hline \sphinxmultirow{3}{1}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{5}} - \sphinxAtStartPar cell1\sphinxhyphen{}1 \par @@ -27,7 +26,6 @@ }% &\sphinxmultirow{3}{2}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{5}} - \sphinxAtStartPar cell1\sphinxhyphen{}2 \par @@ -38,7 +36,6 @@ cell1\sphinxhyphen{}3 &\sphinxmultirow{3}{4}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{5}} - \sphinxAtStartPar cell1\sphinxhyphen{}4 \par @@ -46,7 +43,6 @@ }% &\sphinxmultirow{2}{5}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{5}} - \sphinxAtStartPar cell1\sphinxhyphen{}5 \par @@ -55,7 +51,6 @@ \\ \cline{3-3}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxmultirow{2}{6}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{5}} - \sphinxAtStartPar cell2\sphinxhyphen{}3 \par diff --git a/tests/roots/test-latex-table/expects/gridtable.tex b/tests/roots/test-latex-table/expects/gridtable.tex index fc5b757b90e..a71c9e202a0 100644 --- a/tests/roots/test-latex-table/expects/gridtable.tex +++ b/tests/roots/test-latex-table/expects/gridtable.tex @@ -19,7 +19,6 @@ cell1\sphinxhyphen{}1 &\sphinxmultirow{2}{5}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{3}} - \sphinxAtStartPar cell1\sphinxhyphen{}2 \par @@ -31,7 +30,6 @@ \\ \cline{1-1}\cline{3-3}\sphinxmultirow{2}{7}{% \begin{varwidth}[t]{\sphinxcolwidth{1}{3}} - \sphinxAtStartPar cell2\sphinxhyphen{}1 \par @@ -44,9 +42,11 @@ \cline{2-3}\sphinxtablestrut{7}&\sphinxstartmulticolumn{2}% \sphinxmultirow{2}{9}{% \begin{varwidth}[t]{\sphinxcolwidth{2}{3}} +\sphinxAtStartPar +cell3\sphinxhyphen{}2\sphinxhyphen{}par1 \sphinxAtStartPar -cell3\sphinxhyphen{}2 +cell3\sphinxhyphen{}2\sphinxhyphen{}par2 \par \vskip-\baselineskip\vbox{\hbox{\strut}}\end{varwidth}% }% @@ -58,7 +58,6 @@ &\multicolumn{2}{l|}{\sphinxtablestrut{9}}\\ \hline\sphinxstartmulticolumn{3}% \begin{varwidth}[t]{\sphinxcolwidth{3}{3}} - \sphinxAtStartPar cell5\sphinxhyphen{}1 \par