Skip to content

Commit 51fd494

Browse files
committed
Fix regression from commit 25c415b regarding \sphinxcline + booktabs
Can not add test for that, because it shows only after PDF build.
1 parent d280176 commit 51fd494

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

sphinx/texinputs/sphinxlatextables.sty

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -663,21 +663,21 @@
663663
% the initialization macros executed before the table environments
664664
% their scope is limited by a wrapper "savenotes" environment
665665
%
666-
% 0) color support is enacted via adding code to four hooks:
666+
% 0) color support is enacted via adding code to three hooks:
667667
% - \sphinxtabletoprulehook (implicit from \sphinxtoprule expansion)
668-
% - \sphinxtableclinehook (implicit from \sphinxcline expansion)
669668
% - \sphinxtableatstartofbodyhook (explicit from table templates)
670669
% - \sphinxtableafterendhook (explicit from table templates)
671-
%
672-
% 1) we manage these four hooks in a way allowing a custom user extra wrapper
673-
% cenvironment from a container class to use them as entry point for some
674-
% custom code. The container code is done first, prior to table templates. So,
675-
% the style macros will *prepend* the needed color-code to the existing custom
676-
% user code, so the custom user code can override them. The custom user code
677-
% should not redefine any of the 3 \sphinxtable...hook macros via a
670+
% additionally special adjustment must be made in \sphinxcline
671+
%
672+
% 1) we manage these three hooks in a way allowing a custom user extra wrapper
673+
% environment from a container class to use them as entry point for some
674+
% custom code. The container code is done first, prior to table templates.
675+
% So, the style macros will *prepend* the needed color-code to the existing
676+
% custom user code, so the custom user code can override them. The custom
677+
% user code should not redefine any of the 3 \sphinxtable...hook macros via a
678678
% \global\def, but their contents can use \gdef if this is the user intention,
679679
% (attention that the hooks are executed from inside the table, except the
680-
% afterend hook so probably the code in-there should use \noalign),
680+
% afterend hook so probably the code in-there should use \noalign),
681681
%
682682
% 2) the table templates and LaTeX writer code make it so that only
683683
% one of either
@@ -693,7 +693,6 @@
693693
% if it was already executed before as it self-annihilates).
694694
695695
\let\sphinxtabletoprulehook \@empty
696-
\let\sphinxtableclinehook \@empty
697696
\let\sphinxtableatstartofbodyhook\@empty
698697
\let\sphinxtableafterendhook \@empty
699698
@@ -839,23 +838,21 @@
839838
% this macro is needed in color tables as each \cline or \cmidrule (booktabs)
840839
% consumes one \cr, offsetting the rownum parity.
841840
\def\spx@table@@decrementrownum{\noalign{\global\advance\rownum\m@ne}}
842-
841+
\let\sphinxtabledecrementrownum\@empty
843842
844843
% At last the style macros
845844
846845
% \spx@toprule is what the styles define; the colorrows class will prepend
847846
% some code in \sphinxtabletoprulehook
848847
\def\sphinxtoprule{\spx@toprule\sphinxtabletoprulehook}
849-
% \spx@cline is what the styles define; the colorrows class will prepend
850-
% some code in \sphinxtableclinehook. This hook is located first due
851-
% to constraint of the booktabs \cmidrule.
852-
\def\sphinxcline{\sphinxtableclinehook\spx@cline}
853848
854849
% standard style
855850
\def\sphinxthistablewithstandardstyle{%
856851
% Those two are produced by the latex writer
857852
\def\sphinxhline {\hline}%
858-
\def\spx@cline {\cline}%
853+
% \sphinxtabledecrementrownum is a no-op which is redefined by colorrows
854+
% to correct the \rownum increment induced by \cline in colorrows regime
855+
\def\sphinxcline {\sphinxtabledecrementrownum\cline}%
859856
% Those three are inserted by the table templates
860857
\def\spx@toprule {\hline}%
861858
\def\sphinxmidrule {\hline}%
@@ -890,11 +887,18 @@
890887
\def\sphinxbooktabsmidrule {\midrule}
891888
\def\sphinxbooktabsbottomrule{\bottomrule}
892889
\let\sphinxbooktabscmidrule \@gobble % i.e. draw no short rules at all!
890+
% You can redefine this to use \cmidrule with various options, such
891+
% as \cmidrule(lr), but:
892+
% Attention, if you want this to use \cmidrule (or \cline) you must
893+
% also include the \sphinxtabledecrementrownum token like e.g. this
894+
% \def\sphinxbooktabscmidrule{\sphinxtabledecrementrownum\cmidrule}
895+
% and it must be first due to internals of the \cmidrule usage of \futurelet,
896+
% if the table uses row colours.
893897
894898
\def\sphinxthistablewithbooktabsstyle{%
895899
\let\sphinxhline\@empty % there is no wrapper macro here so if you want to change that
896900
% you will have to redefine \sphinxthistablewithbooktabsstyle
897-
\def\spx@cline {\sphinxbooktabscmidrule}% defaults to \@gobble
901+
\def\sphinxcline {\sphinxbooktabscmidrule}% defaults to \@gobble
898902
\def\spx@toprule {\sphinxbooktabstoprule}%
899903
\def\sphinxmidrule {\sphinxbooktabsmidrule}%
900904
\def\sphinxbottomrule{\sphinxbooktabsbottomrule}%
@@ -916,7 +920,7 @@ to allow local use of booktabs table style}%
916920
% borderless style
917921
\def\sphinxthistablewithborderlessstyle{%
918922
\let\sphinxhline \@empty
919-
\let\spx@cline \@gobble
923+
\let\sphinxcline \@gobble
920924
\let\spx@toprule \@empty
921925
\let\sphinxmidrule \@empty
922926
\let\sphinxbottomrule \@empty
@@ -937,10 +941,9 @@ to allow local use of booktabs table style}%
937941
%
938942
\let\spx@table@toprulehook \spx@table@@toprulehook
939943
\let\spx@table@startbodycolorrows \spx@table@@startbodycolorrows
940-
\let\spx@table@decrementrownum \spx@table@@decrementrownum
944+
\let\sphinxtabledecrementrownum \spx@table@@decrementrownum
941945
\spx@prepend\spx@table@toprulehook \to\sphinxtabletoprulehook
942946
\spx@prepend\spx@table@startbodycolorrows\to\sphinxtableatstartofbodyhook
943-
\spx@prepend\spx@table@decrementrownum \to\sphinxtableclinehook
944947
%
945948
% this one is not set to \@empty by norowcolors, because it looks harmless
946949
% to execute it always, as it simply resets to standard colortbl state after
@@ -958,10 +961,11 @@ to allow local use of booktabs table style}%
958961
% simply make it no-op, without even checking if really it was activated.
959962
\let\spx@table@toprulehook \@empty
960963
\let\spx@table@startbodycolorrows\@empty
961-
\let\spx@table@decrementrownum \@empty
964+
\let\sphinxtabledecrementrownum \@empty
962965
% we don't worry about \sphinxtableafterendhook as the \spx@table@resetcolortbl
963966
% done at end can not do harm; and also we could have not bothered with the
964-
% \spx@table@decrementrownum as its action is harmless
967+
% \sphinxtabledecrementrownum as its \rownum decrement, if active, is harmless
968+
% in non-colorrows context
965969
}
966970
967971
% The \sphinxarrayrulewidth is used for some complex matters of merged

0 commit comments

Comments
 (0)