1
1
% % TABLES (WITH SUPPORT FOR MERGED CELLS OF GENERAL CONTENTS)
2
2
%
3
3
% change this info string if making any custom modification
4
- \ProvidesPackage {sphinxlatextables}[2024/07/01 v7.4 .0 tables]%
4
+ \ProvidesPackage {sphinxlatextables}[2025/06/09 v8.3 .0 tables]%
5
5
6
6
% Provides support for this output mark-up from Sphinx latex writer
7
7
% and table templates:
42
42
% - \sphinxthistablewithnocolorrowsstyle
43
43
% - \sphinxthistablewithvlinesstyle
44
44
% - \sphinxthistablewithnovlinesstyle
45
+ % These conditionals added at 8.3.0 for nested tables not to break row colors
46
+ % (#13635). Nested tables are only partially supported by Sphinx LaTeX.
47
+ % The method here is with no changes to neither writer nor templates.
48
+ \newif\ifspx@intable
49
+ \newif\ifspx@thistableisnested
45
50
%
46
51
% Also provides user command (see docs)
47
52
% - \sphixncolorblend
62
67
\RequirePackage {tabulary}
63
68
% tabulary has a bug with its re-definition of \multicolumn in its first pass
64
69
% which is not \long. But now Sphinx does not use LaTeX's \multicolumn but its
65
- % own macro. Hence we don't even need to patch tabulary. See
66
- % sphinxpackagemulticell.sty
70
+ % own macro. Hence we don't even need to patch tabulary.
71
+ %
67
72
% X or S (Sphinx) may have meanings if some table package is loaded hence
68
73
% \X was chosen to avoid possibility of conflict
69
74
\newcolumntype {\X }[2]{p{\dimexpr
109
114
\LTpre\z@skip\LTpost\z@skip % set to zero longtable's own skips
110
115
\edef\sphinxbaselineskip {\dimexpr\the\dimexpr\baselineskip\relax\relax }%
111
116
\spx@inframedtrue % message to sphinxheavybox
112
- }%
117
+ \spx@table@setnestedflags
118
+ }
113
119
% Compatibility with caption package
114
120
\def\sphinxthelongtablecaptionisattop {%
115
121
\spx@ifcaptionpackage {\noalign {\vskip -\belowcaptionskip }}{}%
124
130
% B. Table with tabular or tabulary
125
131
\def\sphinxattablestart {\par\vskip\dimexpr\sphinxtablepre\relax
126
132
\spx@inframedtrue % message to sphinxheavybox
133
+ \spx@table@setnestedflags
127
134
}%
135
+ % MEMO: this happens inside a savenotes environment and hence flags
136
+ % are reset on exit of it.
137
+ \def\spx@table@setnestedflags {% Issue #13635
138
+ \ifspx@intable
139
+ \let\spx@table@resetcolortbl\spx@nestedtable@resetcolortbl
140
+ \spx@thistableisnestedtrue
141
+ \else
142
+ \spx@intabletrue
143
+ \fi
144
+ }%
128
145
\let\sphinxattableend\sphinxatlongtableend
129
146
% This is used by tabular and tabulary templates
130
147
\newcommand *\sphinxcapstartof [1]{%
270
287
% cells (the code does inserts & tokens, see TN1b). It was decided to keep it
271
288
% simple with \sphinxstartmulticolumn...\sphinxstopmulticolumn.
272
289
%
290
+ % **** ATTENTION: Sphinx does generate at least some nested tables in LaTeX
291
+ % **** TODO: clarify if next paragraph means we must raise an
292
+ % **** if LaTeX writer detects a merged cell inside nested table.
273
293
% MEMO about nesting: if sphinxmulticolumn is encountered in a nested tabular
274
294
% inside a tabulary it will think to be at top level in the tabulary. But
275
295
% Sphinx generates no nested tables, and if some LaTeX macro uses internally a
857
877
}%
858
878
\the\everycr
859
879
}%
860
- \global\rownum\@ne % is done from inside table so ok with tabulary two passes
880
+ \ifspx@thistableisnested
881
+ % Attention that tabulary does two passes so we need to push the
882
+ % initial rownum and, after the first pass, we must reset it!
883
+ % Fortunately Sphinx LaTeX writer makes parent table tabular or
884
+ % longtable if a nested table is a tabulary. So we don't need to
885
+ % worry about distinguishing if this or parent is tabulary.
886
+ \ifx \TY@final\@undefined % tabular
887
+ \spx@gpush@rownum
888
+ \else
889
+ \ifx \equation $ % tabulary, first pass
890
+ \spx @gpush@rownum
891
+ \else % tabulary, second pass
892
+ \spx @gpop@rownum % reset \rownum
893
+ \spx @gpush@rownum% and push it again.
894
+ \fi
895
+ \fi
896
+ % To make nested tables stand out in a color row, we toggle the parity.
897
+ % TODO: Double-check if compatible with method for color of header
898
+ % row.
899
+ % TODO: Perhaps better to use specific colors for nested tables?
900
+ % This would mean though adding new sphinxsetup parameters
901
+ % and extending the documentation...
902
+ \ifodd\rownum\global\rownum\z @\else\global\rownum\@ ne\fi
903
+ \else
904
+ \global\rownum\@ ne
905
+ \fi
861
906
\sphinxSwitchCaseRowColor\rownum % set up color for the first body row
862
907
\sphinxrowcolorON % has been done from \sphinxtoprule location but let's do
863
908
% it again in case \sphinxtabletoprulehook has been used
883
928
\let\sphinxtabledecrementrownum\@ empty
884
929
885
930
% \sphinxtableafterendhook will be modified by colorrows class to execute
886
- % this after the table
931
+ % this after the table.
887
932
\def\spx @table@resetcolortbl{%
888
933
\sphinxrowcolorOFF
889
- \spx@table@reset@CTeverycr
934
+ \spx@table@reset@CT@everycr
890
935
% this last bit is done in order for the \sphinxbottomrule from the "foot"
891
- % longtable template to be able to use same code as the \sphinxbottomrule
892
- % at end of table body; see \sphinxbooktabsspecialbottomrule code
936
+ % part of the longtable template to be able to use same code as the
937
+ % \sphinxbottomrule at end of table body; see \sphinxbooktabsspecialbottomrule.
893
938
\global\rownum\z@
939
+ \global\let\spx@rownum@stack\@empty
940
+ }
941
+ % Most of \spx@table@resetcolortbl must be avoided if the table is nested.
942
+ % Besides the sphinxTableRowColor must be reset because it has been
943
+ % redefined by the cells of the nested table. So this is the alternative
944
+ % macro which is executed on exit of nested table.
945
+ \def\spx @nestedtable@resetcolortbl{%
946
+ \spx@gpop@rownum
947
+ \sphinxSwitchCaseRowColor\rownum
894
948
}
895
- \def\spx @table@reset@CTeverycr {%
949
+ \def\spx @table@reset@CT@everycr {%
896
950
% we should probably be more cautious and not hard-code here the colortbl
897
- % set-up; so the macro is defined without @ to fac
951
+ % set-up.
898
952
\global\CT@everycr {\noalign {\global\let\CT@row@color\relax }\the\everycr }%
899
953
}
954
+ \let\spx @rownum@stack\@ empty
955
+ \def\spx @gpush@rownum{\xdef\spx@rownum@stack {\the\rownum .\spx@rownum@stack }}%
956
+ \def\spx @gpop@rownum{\afterassignment\spx@gpop@rownum@i
957
+ \global\rownum =\spx@rownum@stack\relax }
958
+ \def\spx @gpop@rownum@i.#1 \relax {\gdef\spx@rownum@stack {#1}}
900
959
901
960
% At last the style macros \sphinxthistablewithstandardstyle etc...
902
961
@@ -1047,10 +1106,13 @@ local use of booktabs table style}%
1047
1106
%
1048
1107
% this one is not set to \@empty by nocolorrows, because it looks harmless
1049
1108
% to execute it always, as it simply resets to standard colortbl state after
1050
- % the table; so we don't need an @@ version for this one
1109
+ % the table [^1]; so we don't need an @@ version for this one.
1110
+ % .. [1]: which is bad if nested in another table. This is taken care of
1111
+ % at level of \sphinxattablestart and \sphinxatlongtablestart.
1051
1112
\spx@prepend\spx@table@resetcolortbl\to\sphinxtableafterendhook
1052
1113
}
1053
1114
\def\spx @prepend#1 \to #2 {% attention about using this only with #2 "storage macro"
1115
+ % MEMO: #1 is prepended with no expansion, i.e. "as is".
1054
1116
\toks@ {#1}%
1055
1117
\toks@\expandafter\expandafter\expandafter {\expandafter\the\expandafter\toks@ #2}%
1056
1118
\edef #2{\the\toks@ }%
@@ -1064,9 +1126,10 @@ local use of booktabs table style}%
1064
1126
\let\spx@table@startbodycolorrows\@empty
1065
1127
\let\sphinxtabledecrementrownum \@empty
1066
1128
% we don't worry about \sphinxtableafterendhook as the \spx@table@resetcolortbl
1067
- % done at end can not do harm; and we could also have not bothered with the
1129
+ % done at end can not do harm [^1] ; and we could also have not bothered with the
1068
1130
% \sphinxtabledecrementrownum as its \rownum decrement, if active, is harmless
1069
- % in non-colorrows context
1131
+ % in non-colorrows context.
1132
+ % .. [1]: if nested in another table it is modified to do no harm.
1070
1133
}
1071
1134
1072
1135
% (not so easy) implementation of the booktabscolorgaps option. This option
0 commit comments