Skip to content

Commit 2e77290

Browse files
committed
LaTeX: partially fix color issues for wrapped code lines with pagebreak
This does not fix entirely #10610 but it does sufficiently for it not to require reverting #10577 which tried to solve #8686 conundrum. In extreme cases, the #8686 problem meant that some contents disappeared at page bottom, so it is probably better to maintain #10577 which will avoid any such overflow of code beyond its frame, even though in some specific cases (a colored entity such as a long string is partly on both pages), some syntax highlighting gets lost. There are anyhow other issues with colors for wrapped code lines, even with no pagebreaks involved, such as #10615. This patch does not change the situation there.
1 parent 9741d13 commit 2e77290

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

sphinx/texinputs/sphinxlatexliterals.sty

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% LITERAL BLOCKS
22
%
33
% change this info string if making any custom modification
4-
\ProvidesFile{sphinxlatexliterals.sty}[2022/06/18 code-blocks and parsed literals]
4+
\ProvidesFile{sphinxlatexliterals.sty}[2022/06/29 code-blocks and parsed literals]
55

66
% Provides support for this output mark-up from Sphinx latex writer:
77
%
@@ -99,37 +99,48 @@
9999
% - frame is \fboxsep separated from the contents,
100100
% - the contents use the full available text width,
101101
% - #1 = color of frame, #2 = color of background,
102-
% - #3 = above frame, #4 = below frame, #5 = within frame,
103-
% - #3 and #4 must be already typeset boxes; they must issue \normalcolor
104-
% or similar, else, they are under scope of color #1
102+
% - #3 = will be typeset above frame,
103+
% - #4 = will be typeset below frame,
104+
% - #5 = will be typeset within frame,
105+
% #3 and #4 must be already typeset boxes.
106+
% #5 are the contents, and in the context of usage of fancyvrb+framed by
107+
% Sphinx, it will arrive here already transformed into horizontal
108+
% boxes. The \normalcolor is a preventive measure to some color issues
109+
% when a pagebreak occurs in the middle of a wrapped long code line.
105110
\long\def\spx@fcolorbox #1#2#3#4#5{%
106111
\hskip\@totalleftmargin
107112
\hskip-\fboxsep\hskip-\fboxrule
108113
% MEMO: \color@b@x from xcolor.sty is identical with the one from color.sty
109-
\color@b@x {\color{#1}\spx@CustomFBox{#3}{#4}}{\color{#2}}{#5}%
114+
\color@b@x {\spx@CustomFBox{#1}{#3}{#4}}{\color{#2}}{{\normalcolor#5}}%
110115
\hskip-\fboxsep\hskip-\fboxrule
111116
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth
112117
}%
113-
% #1 = for material above frame, such as a caption or a "continued" hint
114-
% #2 = for material below frame, such as a caption or "continues on next page"
115-
% #3 = actual contents, which will be typeset with a background color
116-
\long\def\spx@CustomFBox#1#2#3{%
118+
% #1 = color of frame
119+
% #2 = for material above frame, such as a caption or a "continued" hint
120+
% #3 = for material below frame, such as a caption or "continues on next page"
121+
% #4 = contents; or rather if called from \spx@fcolorbox (only use case here),
122+
% the contents are in \box\z@ and #4 is
123+
% \color{<bgcolor>}\color@block {\wd \z@ }{\ht \z@ }{\dp \z@ }\box \z@
124+
\long\def\spx@CustomFBox#1#2#3#4{%
117125
\begingroup
118-
\setbox\@tempboxa\hbox{{#3}}% inner braces to avoid color leaks
119-
\vbox{#1% above frame
126+
\setbox\@tempboxa\hbox{{#4}}% inner braces to avoid background color leak
127+
\vbox{#2% above frame
120128
% draw frame border _latest_ to avoid pdf viewer issue
121129
\kern\fboxrule
122130
\hbox{\kern\fboxrule
123131
\copy\@tempboxa
132+
{\color{#1}% frame color
124133
\kern-\wd\@tempboxa\kern-\fboxrule
125134
\vrule\@width\fboxrule
126135
\kern\wd\@tempboxa
127136
\vrule\@width\fboxrule}%
137+
}%
138+
{\color{#1}% frame color
128139
\kern-\dimexpr\ht\@tempboxa+\dp\@tempboxa+\fboxrule\relax
129140
\hrule\@height\fboxrule
130141
\kern\dimexpr\ht\@tempboxa+\dp\@tempboxa\relax
131-
\hrule\@height\fboxrule
132-
#2% below frame
142+
\hrule\@height\fboxrule}%
143+
#3% below frame
133144
}%
134145
\endgroup
135146
}%
@@ -145,10 +156,10 @@
145156
%
146157
\def\sphinxVerbatim@Continued
147158
{\csname spx@fcolorbox@put@\spx@opt@verbatimcontinuedalign\endcsname
148-
{\normalcolor\sphinxstylecodecontinued\literalblockcontinuedname}}%
159+
{{\normalcolor\sphinxstylecodecontinued\literalblockcontinuedname}}}%
149160
\def\sphinxVerbatim@Continues
150161
{\csname spx@fcolorbox@put@\spx@opt@verbatimcontinuesalign\endcsname
151-
{\normalcolor\sphinxstylecodecontinues\literalblockcontinuesname}}%
162+
{{\normalcolor\sphinxstylecodecontinues\literalblockcontinuesname}}}%
152163
\def\sphinxVerbatim@Title
153164
{\spx@fcolorbox@put@c{\unhcopy\sphinxVerbatim@TitleBox}}%
154165
\let\sphinxVerbatim@Before\@empty

sphinx/texinputs/sphinxlatexstyletext.sty

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% TEXT STYLING
22
%
33
% change this info string if making any custom modification
4-
\ProvidesFile{sphinxlatexstyletext.sty}[2021/12/06 text styling]
4+
\ProvidesFile{sphinxlatexstyletext.sty}[2022/06/29 text styling]
55

66
% Basically everything here consists of macros which are part of the latex
77
% markup produced by the Sphinx latex writer
@@ -39,15 +39,16 @@
3939
\protected\def\sphinxstyleothertitle #1{\textbf{#1}}
4040
\protected\def\sphinxstylesidebarsubtitle #1{~\\\textbf{#1} \smallskip}
4141
% \text.. commands do not allow multiple paragraphs
42+
% attention, this one is not self-delimiting
4243
\protected\def\sphinxstyletheadfamily {\sffamily}
4344
\protected\def\sphinxstyleemphasis #1{\emph{#1}}
4445
\protected\def\sphinxstyleliteralemphasis#1{\emph{\sphinxcode{#1}}}
4546
\protected\def\sphinxstylestrong #1{\textbf{#1}}
4647
\protected\def\sphinxstyleliteralstrong#1{\sphinxbfcode{#1}}
4748
\protected\def\sphinxstyleabbreviation #1{\textsc{#1}}
4849
\protected\def\sphinxstyleliteralintitle#1{\sphinxcode{#1}}
49-
\newcommand*\sphinxstylecodecontinued[1]{\footnotesize(#1)}%
50-
\newcommand*\sphinxstylecodecontinues[1]{\footnotesize(#1)}%
50+
\newcommand*\sphinxstylecodecontinued[1]{{\footnotesize(#1)}}%
51+
\newcommand*\sphinxstylecodecontinues[1]{{\footnotesize(#1)}}%
5152
% figure legend comes after caption and may contain arbitrary body elements
5253
\newenvironment{sphinxlegend}{\par\small}{\par}
5354
% reduce hyperref "Token not allowed in a PDF string" warnings on PDF builds

0 commit comments

Comments
 (0)