Skip to content

Commit

Permalink
Move \rownum reset away from longtable template into afterendhook
Browse files Browse the repository at this point in the history
This is better not to overload our template.  Besides it makes it easier
for user to use another longtable template.
  • Loading branch information
jfbu committed Aug 20, 2022
1 parent 866692d commit 6a6a770
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion sphinx/templates/latex/longtable.tex_t
Expand Up @@ -53,7 +53,7 @@
\sphinxmidrule
<% endif -%>
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{<%= table.colcount %>}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{<%= _('continues on next page') %>}}%
Expand Down
17 changes: 10 additions & 7 deletions sphinx/texinputs/sphinxlatextables.sty
Expand Up @@ -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
Expand Down Expand Up @@ -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}%
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-latex-table/expects/longtable.tex
Expand Up @@ -29,7 +29,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -28,7 +28,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -30,7 +30,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -28,7 +28,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -34,7 +34,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{3}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -28,7 +28,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -28,7 +28,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down
Expand Up @@ -29,7 +29,7 @@
\\
\sphinxmidrule
\endhead
\noalign{\global\rownum2 }%

\sphinxbottomrule
\multicolumn{2}{r}{\sphinxnorowcolor
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%
Expand Down

0 comments on commit 6a6a770

Please sign in to comment.