summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-François B <2589111+jfbu@users.noreply.github.com>2022-07-03 12:10:42 +0200
committerGitHub <noreply@github.com>2022-07-03 12:10:42 +0200
commitaae64baac00d0c7d15d3f2e984730a13ac48e7bb (patch)
treeb64ddb5fff4dbddaee90ade0445985345ae7d402
parenta9cd517c0444d6f3c75be996290b93e2df4a574c (diff)
parent0d3f606dff3a1e1fec23c30b0ae08e94653f9bee (diff)
downloadsphinx-git-aae64baac00d0c7d15d3f2e984730a13ac48e7bb.tar.gz
Merge pull request #10619 from jfbu/latex_coloredshadows
LaTeX: refactor sphinxShadowBox to allow colors for frame and shadow
-rw-r--r--doc/latex.rst16
-rw-r--r--sphinx/texinputs/sphinx.sty5
-rw-r--r--sphinx/texinputs/sphinxlatexshadowbox.sty88
3 files changed, 89 insertions, 20 deletions
diff --git a/doc/latex.rst b/doc/latex.rst
index 294de5599..0140d0b2c 100644
--- a/doc/latex.rst
+++ b/doc/latex.rst
@@ -846,7 +846,7 @@ Do not use quotes to enclose values, whether numerical or strings.
Default: ``5pt``
``shadowsize``
- The width of the lateral "shadow" to the right.
+ The width of the lateral "shadow" to the right and bottom.
Default: ``4pt``
@@ -855,6 +855,20 @@ Do not use quotes to enclose values, whether numerical or strings.
Default: ``\fboxrule``
+``shadowBorderColor``
+ The color of the frame around :dudir:`topic` boxes.
+
+ Default: ``{rgb}{0,0,0}`` (black)
+
+ .. versionadded:: 5.1.0
+
+``shadowShadowColor``
+ The color of the lateral "shadow" to the right and bottom.
+
+ Default: ``{rgb}{0,0,0}`` (black)
+
+ .. versionadded:: 5.1.0
+
|notebdcolors|
The colour for the two horizontal rules used by Sphinx in LaTeX for styling
a :dudir:`note` type admonition.
diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty
index 930d1b64f..b67722c1b 100644
--- a/sphinx/texinputs/sphinx.sty
+++ b/sphinx/texinputs/sphinx.sty
@@ -6,7 +6,7 @@
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
-\ProvidesPackage{sphinx}[2021/01/27 v4.0.0 LaTeX package (Sphinx markup)]
+\ProvidesPackage{sphinx}[2022/06/30 v5.1.0 LaTeX package (Sphinx markup)]
% provides \ltx@ifundefined
% (many packages load ltxcmds: graphicx does for pdftex and lualatex but
@@ -154,6 +154,9 @@
}%
% Default color chosen to be as in minted.sty LaTeX package!
\sphinxDeclareSphinxColorOption{VerbatimHighlightColor}{{rgb}{0.878,1,1}}
+% topic and contents boxes
+\sphinxDeclareSphinxColorOption{shadowBorderColor}{{rgb}{0,0,0}}
+\sphinxDeclareSphinxColorOption{shadowShadowColor}{{rgb}{0,0,0}}
% admonition boxes, "light" style
\sphinxDeclareSphinxColorOption{noteBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{hintBorderColor}{{rgb}{0,0,0}}
diff --git a/sphinx/texinputs/sphinxlatexshadowbox.sty b/sphinx/texinputs/sphinxlatexshadowbox.sty
index 8d6c78666..12d3cec09 100644
--- a/sphinx/texinputs/sphinxlatexshadowbox.sty
+++ b/sphinx/texinputs/sphinxlatexshadowbox.sty
@@ -1,7 +1,7 @@
%% TOPIC AND CONTENTS BOXES
%
% change this info string if making any custom modification
-\ProvidesFile{sphinxlatexshadowbox.sty}[2021/01/27 sphinxShadowBox]
+\ProvidesFile{sphinxlatexshadowbox.sty}[2022/06/30 sphinxShadowBox]
% Provides support for this output mark-up from Sphinx latex writer:
%
@@ -17,41 +17,93 @@
% Requires:
\RequirePackage{framed}
-% Again based on use of "framed.sty", this allows breakable framed boxes.
+% Let's draw the contents first, then the frame and the shadow last,
+% to avoid problems with some pdf viewers.
\long\def\spx@ShadowFBox#1{%
\leavevmode\begingroup
- % first we frame the box #1
+ % First we prepare a box with the contents and some reserved space for the
+ % frame and inner separation; with more parameters we could allow various
+ % border widths for top, bottom, left, right, but here all are equal.
\setbox\@tempboxa
- \hbox{\vrule\@width\sphinxshadowrule
- \vbox{\hrule\@height\sphinxshadowrule
+ \hbox{\kern\sphinxshadowrule
+ \vbox{\kern\sphinxshadowrule
\kern\sphinxshadowsep
\hbox{\kern\sphinxshadowsep #1\kern\sphinxshadowsep}%
\kern\sphinxshadowsep
- \hrule\@height\sphinxshadowrule}%
- \vrule\@width\sphinxshadowrule}%
- % Now we add the shadow, like \shadowbox from fancybox.sty would do
- \dimen@\dimexpr.5\sphinxshadowrule+\sphinxshadowsize\relax
+ \kern\sphinxshadowrule}%
+ \kern\sphinxshadowrule}%
+ % Now we rebox, adding the colored frame for which space was reserved.
+ \setbox\@tempboxa
+ \hbox{\unhcopy\@tempboxa % not \unhbox to be able to refer to \ht, \wd later
+ \kern-\wd\@tempboxa
+ {\color{sphinxshadowBorderColor}% color push here
+ \vrule\@width\sphinxshadowrule% TeX auto-computes the height
+ \vbox{\hrule\@height\sphinxshadowrule% TeX auto-computes the width
+ \kern\dimexpr\ht\@tempboxa-\sphinxshadowrule\relax
+ % This empty \hbox is here to give width used by \hrule
+ % As \dp\@tempboxa is zero, the \hbox location is at the
+ % bottom of frame.
+ \hbox{\kern\dimexpr\wd\@tempboxa-2\sphinxshadowrule\relax}%
+ \kern\dimexpr\dp\@tempboxa-\sphinxshadowrule\relax
+ \hrule\@height\sphinxshadowrule% TeX auto-computes the width
+ }%
+ \vrule\@width\sphinxshadowrule% TeX auto-computes the height
+ }% color pop will happen here
+ }%
+ % Now we add the shadow.
+ %
+ % Formerly, shadow was drawn partly on top of frame, but this was before
+ % both frame and shadow acquired colors. The width of the part of the
+ % shadow on the right is hidden, so it will stick into the right page
+ % margin.
+ %
+ % The frame borders are included into this final \hbox, which is sent back
+ % to \MakeFramed/\endMakeFramed measurements and then finally to page
+ % shipout. As \advance\hsize-\width appears in \MakeFramed, where \width is
+ % the computed extra width added by the framing plus inner separation (so
+ % actually 2\sphinxshadowrule+2\sphinxshadowsep), this all means that
+ % horizontally the frame will be perfectly adjusted to the *total* text
+ % width limits (i.e. independent of current list nesting; but anyhow
+ % Docutils does not allow nesting of topic within topics or body elements).
\hbox{\vbox{\offinterlineskip
- \hbox{\copy\@tempboxa\kern-.5\sphinxshadowrule
+ \hbox{\copy\@tempboxa % not \box as we need \wd and \ht next
% add shadow on right side
\lower\sphinxshadowsize
- \hbox{\vrule\@height\ht\@tempboxa \@width\dimen@}%
+ \hbox{{\color{sphinxshadowShadowColor}%
+ \vrule\@height\ht\@tempboxa \@width\sphinxshadowsize}}%
}%
- \kern-\dimen@ % shift back vertically to bottom of frame
+ \kern-\sphinxshadowsize % shift back vertically to bottom of frame
% and add shadow at bottom
\moveright\sphinxshadowsize
- \vbox{\hrule\@width\wd\@tempboxa \@height\dimen@}%
+ \vbox{{\color{sphinxshadowShadowColor}%
+ \hrule\@width\wd\@tempboxa \@height\sphinxshadowsize}}%
}%
- % move left by the size of right shadow so shadow adds no width
+ % move left by the size of right shadow so shadow adds no width, and
+ % will stick into right margin
+ % (we did not conceal of course from TeX the depth)
\kern-\sphinxshadowsize
}%
\endgroup
}
-% use framed.sty to allow page breaks in frame+shadow
-% works well inside Lists and Quote-like environments
-% produced by ``topic'' directive (or local contents)
-% could nest if LaTeX writer authorized it
+% Use framed.sty \MakeFramed/\endMakeFramed to allow page breaks for topic
+% boxes. Originally Sphinx used \shadowbox from fancybox.sty but it did not
+% allow pagebreaks (which was problematic for "contents" directive if there
+% are many subsections).
+%
+% Docutils does not allow topic to be nested within topics or other body
+% elements. But the LaTeX code here does allow it:
+%
+% - a topic inside another topic would be rendered in a minipage (thus not
+% allowing pagebreaks). Its external frame would adapt perfectly to
+% the *current (smaller) width for text*.
+%
+% - a topic inside (nested) lists or quote environments would have its frame
+% take the *full width* of the page, but its text contents on the other hand
+% would obey exactly the current indentation plus inner separation. This is
+% in contrast with the framing used for literal blocks, also based, but in a
+% more sophisticated way on usage of \MakeFramed/\endMakeFramed, and
+% adjusting to current text indentation.
\newenvironment{sphinxShadowBox}
{\def\FrameCommand {\spx@ShadowFBox }%
\advance\spx@image@maxheight