From 55934a9334e9c6234509933da947676e9bd78d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Sat, 20 Aug 2022 19:02:59 +0200 Subject: [PATCH] Move \rownum reset away from longtable template into afterendhook This is better not to overload our template. Besides it makes it easier for user to use another longtable template. --- sphinx/templates/latex/longtable.tex_t | 2 +- sphinx/texinputs/sphinxlatextables.sty | 17 ++++++++++------- .../test-latex-table/expects/longtable.tex | 2 +- .../expects/longtable_having_align.tex | 2 +- .../expects/longtable_having_caption.tex | 2 +- .../longtable_having_problematic_cell.tex | 2 +- ...having_stub_columns_and_problematic_cell.tex | 2 +- .../expects/longtable_having_verbatim.tex | 2 +- .../expects/longtable_having_widths.tex | 2 +- ...table_having_widths_and_problematic_cell.tex | 2 +- .../expects/longtable_with_tabularcolumn.tex | 2 +- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/sphinx/templates/latex/longtable.tex_t b/sphinx/templates/latex/longtable.tex_t index 27c887ab921..f5cb522cef3 100644 --- a/sphinx/templates/latex/longtable.tex_t +++ b/sphinx/templates/latex/longtable.tex_t @@ -53,7 +53,7 @@ \sphinxmidrule <% endif -%> \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{<%= table.colcount %>}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{<%= _('continues on next page') %>}}% diff --git a/sphinx/texinputs/sphinxlatextables.sty b/sphinx/texinputs/sphinxlatextables.sty index 1d90f12ce7a..247ad7a7674 100644 --- a/sphinx/texinputs/sphinxlatextables.sty +++ b/sphinx/texinputs/sphinxlatextables.sty @@ -892,6 +892,10 @@ \def\spx@table@resetcolortbl{% \sphinxrowcolorOFF \spx@table@reset@CTeverycr +% this last bit is done in order for the \sphinxbottomrule from the "foot" +% longtable template to be able to use same code as the \sphinxbottomrule +% at end of table body; see \sphinxbooktabsspecialbottomrule code + \global\rownum\z@ } \def\spx@table@reset@CTeverycr{% % we should probably be more cautious and not hard-code here the colortbl @@ -1174,13 +1178,12 @@ local use of booktabs table style}% % execute again the colour selection code, but this is not too complicated. % What is annoying though is that \sphinxbottomrule in the longtable context % appears both in the "foot" part and after the last body row. For the first -% occurrence the \rownum has not been reset and could be arbitrary. So we had -% to set it to "2" in the longtable templates :-(. Not "0" in order to avoid -% \sphinxSwitchCaseRowColor having to know how to handle negative inputs, -% although the Sphinx definition has no issue with that. (there is no easy -% official way from longtable to know the macro is expanded in a "foot" box). -% So 2-1=1 and in longtable the colour will always be the "Odd" one, except at -% very end of longtable, where it will match colour of the last row. +% occurrence the \rownum could be arbitrary if it had not been reset by each +% table using it via the \sphinxtableafterendhook (see above). This avoids +% having to modify the longtable template. But as \rownum is thus 0 in the +% "foot", the \sphinxSwitchCaseRowColor has to know how to handle negative +% inputs (in fact the -1 value), the Sphinx definition has no issue with that +% but any redefinition must be aware of this constraint. \def\sphinxbooktabsspecialbottomrule{% \noalign{\global\let\spx@@saved@CT@arc@\CT@arc@ \sphinxSwitchCaseRowColor{\numexpr\rownum-\@ne\relax}% diff --git a/tests/roots/test-latex-table/expects/longtable.tex b/tests/roots/test-latex-table/expects/longtable.tex index 93b8dbae4df..754d10249e1 100644 --- a/tests/roots/test-latex-table/expects/longtable.tex +++ b/tests/roots/test-latex-table/expects/longtable.tex @@ -29,7 +29,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_having_align.tex b/tests/roots/test-latex-table/expects/longtable_having_align.tex index 1de4a05df60..dcf8f83a1a2 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_align.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_align.tex @@ -28,7 +28,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_having_caption.tex b/tests/roots/test-latex-table/expects/longtable_having_caption.tex index 6540d3513d9..dd2a87fa68f 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_caption.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_caption.tex @@ -30,7 +30,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex b/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex index 4874280dd35..8258612f50c 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex @@ -28,7 +28,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex b/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex index 6a81f074c61..44114ce78c2 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex @@ -34,7 +34,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{3}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex b/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex index fa640229965..fc78914a9cf 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex @@ -28,7 +28,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_having_widths.tex b/tests/roots/test-latex-table/expects/longtable_having_widths.tex index 77427c17a7d..bac2fe129d4 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_widths.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_widths.tex @@ -4,7 +4,7 @@ \sphinxatlongtablestart \sphinxthistablewithglobalstyle \begin{longtable}[c]{|\X{30}{100}|\X{70}{100}|} -\noalign{\phantomsection\label{\detokenize{longtable:namedlongtable}}\label{\detokenize{longtable:mylongtable}}}% + \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex b/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex index f38cc40d2ff..bf9192009ca 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex @@ -28,7 +28,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}% diff --git a/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex b/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex index 63c2a78ee60..6383d9d5667 100644 --- a/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex +++ b/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex @@ -29,7 +29,7 @@ \\ \sphinxmidrule \endhead -\noalign{\global\rownum2 }% + \sphinxbottomrule \multicolumn{2}{r}{\sphinxnorowcolor \makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%