Skip to content

Commit

Permalink
Fix regression from commit 25c415b regarding \sphinxcline + booktabs
Browse files Browse the repository at this point in the history
Can not add test for that, because it shows only after PDF build.
  • Loading branch information
jfbu committed Aug 13, 2022
1 parent d280176 commit 51fd494
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions sphinx/texinputs/sphinxlatextables.sty
Expand Up @@ -663,21 +663,21 @@
% the initialization macros executed before the table environments
% their scope is limited by a wrapper "savenotes" environment
%
% 0) color support is enacted via adding code to four hooks:
% 0) color support is enacted via adding code to three hooks:
% - \sphinxtabletoprulehook (implicit from \sphinxtoprule expansion)
% - \sphinxtableclinehook (implicit from \sphinxcline expansion)
% - \sphinxtableatstartofbodyhook (explicit from table templates)
% - \sphinxtableafterendhook (explicit from table templates)
%
% 1) we manage these four hooks in a way allowing a custom user extra wrapper
% cenvironment from a container class to use them as entry point for some
% custom code. The container code is done first, prior to table templates. So,
% the style macros will *prepend* the needed color-code to the existing custom
% user code, so the custom user code can override them. The custom user code
% should not redefine any of the 3 \sphinxtable...hook macros via a
% additionally special adjustment must be made in \sphinxcline
%
% 1) we manage these three hooks in a way allowing a custom user extra wrapper
% environment from a container class to use them as entry point for some
% custom code. The container code is done first, prior to table templates.
% So, the style macros will *prepend* the needed color-code to the existing
% custom user code, so the custom user code can override them. The custom
% user code should not redefine any of the 3 \sphinxtable...hook macros via a
% \global\def, but their contents can use \gdef if this is the user intention,
% (attention that the hooks are executed from inside the table, except the
% afterend hook so probably the code in-there should use \noalign),
% afterend hook so probably the code in-there should use \noalign),
%
% 2) the table templates and LaTeX writer code make it so that only
% one of either
Expand All @@ -693,7 +693,6 @@
% if it was already executed before as it self-annihilates).
\let\sphinxtabletoprulehook \@empty
\let\sphinxtableclinehook \@empty
\let\sphinxtableatstartofbodyhook\@empty
\let\sphinxtableafterendhook \@empty
Expand Down Expand Up @@ -839,23 +838,21 @@
% this macro is needed in color tables as each \cline or \cmidrule (booktabs)
% consumes one \cr, offsetting the rownum parity.
\def\spx@table@@decrementrownum{\noalign{\global\advance\rownum\m@ne}}
\let\sphinxtabledecrementrownum\@empty
% At last the style macros
% \spx@toprule is what the styles define; the colorrows class will prepend
% some code in \sphinxtabletoprulehook
\def\sphinxtoprule{\spx@toprule\sphinxtabletoprulehook}
% \spx@cline is what the styles define; the colorrows class will prepend
% some code in \sphinxtableclinehook. This hook is located first due
% to constraint of the booktabs \cmidrule.
\def\sphinxcline{\sphinxtableclinehook\spx@cline}
% standard style
\def\sphinxthistablewithstandardstyle{%
% Those two are produced by the latex writer
\def\sphinxhline {\hline}%
\def\spx@cline {\cline}%
% \sphinxtabledecrementrownum is a no-op which is redefined by colorrows
% to correct the \rownum increment induced by \cline in colorrows regime
\def\sphinxcline {\sphinxtabledecrementrownum\cline}%
% Those three are inserted by the table templates
\def\spx@toprule {\hline}%
\def\sphinxmidrule {\hline}%
Expand Down Expand Up @@ -890,11 +887,18 @@
\def\sphinxbooktabsmidrule {\midrule}
\def\sphinxbooktabsbottomrule{\bottomrule}
\let\sphinxbooktabscmidrule \@gobble % i.e. draw no short rules at all!
% You can redefine this to use \cmidrule with various options, such
% as \cmidrule(lr), but:
% Attention, if you want this to use \cmidrule (or \cline) you must
% also include the \sphinxtabledecrementrownum token like e.g. this
% \def\sphinxbooktabscmidrule{\sphinxtabledecrementrownum\cmidrule}
% and it must be first due to internals of the \cmidrule usage of \futurelet,
% if the table uses row colours.
\def\sphinxthistablewithbooktabsstyle{%
\let\sphinxhline\@empty % there is no wrapper macro here so if you want to change that
% you will have to redefine \sphinxthistablewithbooktabsstyle
\def\spx@cline {\sphinxbooktabscmidrule}% defaults to \@gobble
\def\sphinxcline {\sphinxbooktabscmidrule}% defaults to \@gobble
\def\spx@toprule {\sphinxbooktabstoprule}%
\def\sphinxmidrule {\sphinxbooktabsmidrule}%
\def\sphinxbottomrule{\sphinxbooktabsbottomrule}%
Expand All @@ -916,7 +920,7 @@ to allow local use of booktabs table style}%
% borderless style
\def\sphinxthistablewithborderlessstyle{%
\let\sphinxhline \@empty
\let\spx@cline \@gobble
\let\sphinxcline \@gobble
\let\spx@toprule \@empty
\let\sphinxmidrule \@empty
\let\sphinxbottomrule \@empty
Expand All @@ -937,10 +941,9 @@ to allow local use of booktabs table style}%
%
\let\spx@table@toprulehook \spx@table@@toprulehook
\let\spx@table@startbodycolorrows \spx@table@@startbodycolorrows
\let\spx@table@decrementrownum \spx@table@@decrementrownum
\let\sphinxtabledecrementrownum \spx@table@@decrementrownum
\spx@prepend\spx@table@toprulehook \to\sphinxtabletoprulehook
\spx@prepend\spx@table@startbodycolorrows\to\sphinxtableatstartofbodyhook
\spx@prepend\spx@table@decrementrownum \to\sphinxtableclinehook
%
% this one is not set to \@empty by norowcolors, because it looks harmless
% to execute it always, as it simply resets to standard colortbl state after
Expand All @@ -958,10 +961,11 @@ to allow local use of booktabs table style}%
% simply make it no-op, without even checking if really it was activated.
\let\spx@table@toprulehook \@empty
\let\spx@table@startbodycolorrows\@empty
\let\spx@table@decrementrownum \@empty
\let\sphinxtabledecrementrownum \@empty
% we don't worry about \sphinxtableafterendhook as the \spx@table@resetcolortbl
% done at end can not do harm; and also we could have not bothered with the
% \spx@table@decrementrownum as its action is harmless
% \sphinxtabledecrementrownum as its \rownum decrement, if active, is harmless
% in non-colorrows context
}
% The \sphinxarrayrulewidth is used for some complex matters of merged
Expand Down

0 comments on commit 51fd494

Please sign in to comment.