From a2a02c08fcc523d4e23b90fdc71e63b85a9f47a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Sat, 13 Aug 2022 20:35:30 +0200 Subject: [PATCH] Fix regression from commit 25c415b78 regarding \sphinxcline + booktabs Can not add test for that, because it shows only after PDF build. --- sphinx/texinputs/sphinxlatextables.sty | 50 ++++++++++++++------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/sphinx/texinputs/sphinxlatextables.sty b/sphinx/texinputs/sphinxlatextables.sty index 7dc5532de3e..42016a06300 100644 --- a/sphinx/texinputs/sphinxlatextables.sty +++ b/sphinx/texinputs/sphinxlatextables.sty @@ -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 @@ -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 @@ -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}% @@ -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}% @@ -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 @@ -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 @@ -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