From 6afde2e3016d61342977c55ac7f4a71e38adcb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Thu, 30 Jun 2022 19:45:41 +0200 Subject: [PATCH] LaTeX: refactor sphinxShadowBox to allow colors for frame and shadow --- doc/latex.rst | 16 +++++++++- sphinx/texinputs/sphinx.sty | 5 ++- sphinx/texinputs/sphinxlatexshadowbox.sty | 39 +++++++++++++++++------ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/doc/latex.rst b/doc/latex.rst index 294de559907..0140d0b2c9e 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 930d1b64f67..b67722c1bfa 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 8d6c78666cf..420fee2f2bd 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,30 +17,48 @@ % 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 in an invisible frame \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 + \kern\sphinxshadowrule}% + \kern\sphinxshadowrule}% + % now we unbox the previous one, drawing contents first, then + % we frame it with a color + \setbox\@tempboxa + \hbox{\unhcopy\@tempboxa + \kern-\wd\@tempboxa + {\color{sphinxshadowBorderColor}% + \vrule\@width\sphinxshadowrule + \vbox{\hrule\@height\sphinxshadowrule + \kern\dimexpr\ht\@tempboxa-\sphinxshadowrule\relax + \hbox{\kern\dimexpr\wd\@tempboxa-2\sphinxshadowrule\relax}% + \kern\dimexpr\dp\@tempboxa-\sphinxshadowrule\relax \hrule\@height\sphinxshadowrule}% \vrule\@width\sphinxshadowrule}% + }% % Now we add the shadow, like \shadowbox from fancybox.sty would do - \dimen@\dimexpr.5\sphinxshadowrule+\sphinxshadowsize\relax + % Formerly, shadow was drawn partly on top of frame, but this was + % before both frame and shadow acquired colors. \hbox{\vbox{\offinterlineskip - \hbox{\copy\@tempboxa\kern-.5\sphinxshadowrule + \hbox{\copy\@tempboxa % 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 \kern-\sphinxshadowsize @@ -48,6 +66,7 @@ \endgroup } +% Again based on use of "framed.sty", this allows breakable framed boxes. % 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)