From e89c29aa3aa4e15f11cecad5ea81e6a1efaa1fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Sat, 9 Jul 2022 09:46:10 +0200 Subject: [PATCH] LaTeX: CSS-name-alike 'sphinxsetup' options for code-blocks and topics Topic boxes acquire possibility to have padding and background color, and inset shadow. And code-blocks now can have shadows too, also inset. --- sphinx/texinputs/sphinx.sty | 374 +++++++++++++------- sphinx/texinputs/sphinxlatexadmonitions.sty | 9 +- sphinx/texinputs/sphinxlatexliterals.sty | 141 +++++--- sphinx/texinputs/sphinxlatexshadowbox.sty | 92 +++-- sphinx/texinputs/sphinxpackageboxes.sty | 84 ++--- 5 files changed, 449 insertions(+), 251 deletions(-) diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 881bcb5b5ef..4915ecba009 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -77,9 +77,8 @@ \AtBeginDocument{\define@key{sphinx}{bookmarksdepth}{\hypersetup{bookmarksdepth=#1}}} % \DeclareBoolOption[false]{usespart}% not used % dimensions, we declare the \dimen registers here. -\newdimen\sphinxverbatimsep +\newdimen\sphinxverbatimsep % <-- TO BE REMOVED NOT USED ANYMORE AT 5.1.0 \newdimen\sphinxverbatimborder -\newdimen\sphinxverbatimradius % % \DeclareStringOption is not convenient for the handling of these dimensions % because we want to assign the values to the corresponding registers. Even if @@ -87,14 +86,11 @@ % set-up and we would need to do initial assignments explicitly. We end up % using \define@key directly. % verbatim -\sphinxverbatimsep=\fboxsep +\sphinxverbatimsep=\fboxsep % <-- TO BE REMOVED NOT USED ANYMORE AT 5.1.0 \define@key{sphinx}{verbatimsep}{\sphinxverbatimsep\dimexpr #1\relax} \sphinxverbatimborder=\fboxrule \define@key{sphinx}{verbatimborder}{\sphinxverbatimborder\dimexpr #1\relax} -\sphinxverbatimradius=0pt - \define@key{sphinx}{verbatimradius}{\sphinxverbatimradius\dimexpr #1\relax} \DeclareBoolOption[true]{verbatimwithframe} -\DeclareBoolOption[false]{verbatimopenframe} \DeclareBoolOption[true]{verbatimwrapslines} \DeclareBoolOption[false]{verbatimforcewraps} \DeclareStringOption[3]{verbatimmaxoverfull} @@ -112,20 +108,16 @@ [{\makebox[2\fontcharwd\font`\x][r]{\textcolor{red}{\tiny$\m@th\hookrightarrow$}}}]% {verbatimcontinued} % topic boxes -\newdimen\sphinxshadowsep % legacy denormination, will be removed at 6.0.0 - \let\sphinxtopicsep\sphinxshadowsep -\newdimen\sphinxshadowsize % legacy not used anymore to be removed at 6.0.0 -\newdimen\sphinxshadowrule % legacy denomination, will be removed at 6.0.0 - \let\sphinxtopicborder\sphinxshadowrule -% will be redefined below +% alternative names and definitions in 5.1.0 section below +\newdimen\sphinxshadowsep % <-- TO BE REMOVED NOT USED ANYMORE AT 5.1.0 +\newdimen\sphinxshadowsize % <-- TO BE REMOVED NOT USED ANYMORE AT 5.1.0 +\newdimen\sphinxshadowrule \sphinxshadowsep=5pt -\define@key{sphinx}{shadowsep}{\sphinxtopicsep\dimexpr #1\relax}% -% redefined below + \define@key{sphinx}{shadowsep}{\sphinxshadowsep\dimexpr #1\relax}% \sphinxshadowsize=4pt -\define@key{sphinx}{shadowsize}{\sphinxshadowsize\dimexpr #1\relax} -% redefined below -\sphinxshadowrule=\fboxrule -\define@key{sphinx}{shadowrule}{\sphinxtopicborder\dimexpr #1\relax} + \define@key{sphinx}{shadowsize}{\sphinxshadowsize\dimexpr #1\relax} +\sphinxshadowrule=\fboxrule % catches current value (probably 0.4pt) + \define@key{sphinx}{shadowrule}{\sphinxshadowsize\dimexpr #1\relax} % notices/admonitions % the dimensions for notices/admonitions are kept as macros and assigned to % \spx@notice@border at time of use, hence \DeclareStringOption is ok for this @@ -168,20 +160,6 @@ }% % Default color chosen to be as in minted.sty LaTeX package! \sphinxDeclareSphinxColorOption{VerbatimHighlightColor}{{rgb}{0.878,1,1}} -% topic and contents boxes -\sphinxDeclareSphinxColorOption{topicBorderColor}{{rgb}{0,0,0}} -\sphinxDeclareSphinxColorOption{topicShadowColor}{{rgb}{0,0,0}} -\define@key{sphinx}{shadowBorderColor}{% - \definecolor{sphinxtopicBorderColor}#1% -}% -\define@key{sphinx}{shadowShadowColor}{% - \definecolor{sphinxtopicShadowColor}#1% -}% -\definecolor{sphinxtopicBackgroundColor}{rgb}{1,1,1} -\define@key{sphinx}{topicBackgroundColor}{% - \spx@opt@topicwithbackgroundcolortrue - \definecolor{sphinxtopicBackgroundColor}#1% -}% % admonition boxes, "light" style \sphinxDeclareSphinxColorOption{noteBorderColor}{{rgb}{0,0,0}} \sphinxDeclareSphinxColorOption{hintBorderColor}{{rgb}{0,0,0}} @@ -193,6 +171,7 @@ \sphinxDeclareSphinxColorOption{attentionBorderColor}{{rgb}{0,0,0}} \sphinxDeclareSphinxColorOption{dangerBorderColor}{{rgb}{0,0,0}} \sphinxDeclareSphinxColorOption{errorBorderColor}{{rgb}{0,0,0}} +% 5.1.0 section redefines the keys for BackgroundColor CSS-like naming \sphinxDeclareSphinxColorOption{warningBgColor}{{rgb}{1,1,1}} \sphinxDeclareSphinxColorOption{cautionBgColor}{{rgb}{1,1,1}} \sphinxDeclareSphinxColorOption{attentionBgColor}{{rgb}{1,1,1}} @@ -200,110 +179,255 @@ \sphinxDeclareSphinxColorOption{errorBgColor}{{rgb}{1,1,1}} %%%%%%%% % -% Experimental, possibly to be replaced by some kind of CSS input -% -\DeclareStringOption[\sphinxverbatimborder]{verbatimbordertop} -\DeclareStringOption[\sphinxverbatimborder]{verbatimborderright} -\DeclareStringOption[\sphinxverbatimborder]{verbatimborderbottom} -\DeclareStringOption[\sphinxverbatimborder]{verbatimborderleft} -\define@key{sphinx}{verbatimborder}{% - \sphinxverbatimborder\dimexpr #1\relax - \def\spx@opt@verbatimbordertop{\sphinxverbatimborder}% - \def\spx@opt@verbatimborderright{\sphinxverbatimborder}% - \def\spx@opt@verbatimborderbottom{\sphinxverbatimborder}% - \def\spx@opt@verbatimborderleft{\sphinxverbatimborder}% +% Additions at 5.1.0 +% +% In future, an alternative user interface will perhaps be provided via +% CSS-like input in a configuration variable latex_css, and Sphinx +% will then parse it into the \sphinxsetup options described it. +% +% In the meantime we adopt already some CSS-like names. However, +% attention to not use these options as genuine CSS properties, only +% very limited syntax is supported. +% +\def\spxstring@none{none} +\def\spxstring@clone{clone} +% Future: should below all the macros holding dimensions be defined via some +% \edef and \dimexpr rather? +% +% Deliberately the code avoids creating (except by \let) new \dimen variables +% besides the legacy ones already defined. +% +% code-blocks +\let\spxdimen@pre@border\sphinxverbatimborder +\define@key{sphinx}{pre_border-top-width}{\def\spx@pre@border@top{#1}} +\define@key{sphinx}{pre_border-right-width}{\def\spx@pre@border@right{#1}} +\define@key{sphinx}{pre_border-bottom-width}{\def\spx@pre@border@bottom{#1}} +\define@key{sphinx}{pre_border-left-width}{\def\spx@pre@border@left{#1}} +% currently accepts only one dimension specification +\define@key{sphinx}{pre_border-width}{% + \spxdimen@pre@border\dimexpr #1\relax + \def\spx@pre@border@top {\spxdimen@pre@border}% + \let\spx@pre@border@right \spx@pre@border@top + \let\spx@pre@border@bottom\spx@pre@border@top + \let\spx@pre@border@left \spx@pre@border@top } -\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingtop} -\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingright} -\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingbottom} -\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingleft} -\define@key{sphinx}{verbatimsep}{% - \sphinxverbatimsep\dimexpr #1\relax - \def\spx@opt@verbatimpaddingtop{\sphinxverbatimsep}% - \def\spx@opt@verbatimpaddingright{\sphinxverbatimsep}% - \def\spx@opt@verbatimpaddingbottom{\sphinxverbatimsep}% - \def\spx@opt@verbatimpaddingleft{\sphinxverbatimsep}% + \def\spx@pre@border@top {\spxdimen@pre@border}% + \let\spx@pre@border@right \spx@pre@border@top + \let\spx@pre@border@bottom\spx@pre@border@top + \let\spx@pre@border@left \spx@pre@border@top +\expandafter\let\expandafter\KV@sphinx@verbatimborder + \csname KV@sphinx@pre_border-width\endcsname +\newif\ifspx@pre@border@open % defaults to false (at least for 5.x series) +\define@key{sphinx}{pre_box-decoration-break}% + {\edef\spx@tempa{#1}% + \ifx\spx@tempa\spxstring@clone + \spx@pre@border@openfalse + \else\spx@pre@border@opentrue\fi} +% +% MEMO: \sphinxverbatimsep not used anywhere anymore in the code, to be removed +\define@key{sphinx}{pre_padding-top}{\def\spx@pre@padding@top{#1}} +\define@key{sphinx}{pre_padding-right}{\def\spx@pre@padding@right{#1}} +\define@key{sphinx}{pre_padding-bottom}{\def\spx@pre@padding@bottom{#1}} +\define@key{sphinx}{pre_padding-left}{\def\spx@pre@padding@left{#1}} +\define@key{sphinx}{pre_padding}{% + \def\spx@pre@padding@top {#1}% + \let\spx@pre@padding@right \spx@pre@padding@top + \let\spx@pre@padding@bottom\spx@pre@padding@top + \let\spx@pre@padding@left \spx@pre@padding@top } -\DeclareStringOption[\sphinxverbatimradius]{verbatimradiustopleft} -\DeclareStringOption[\sphinxverbatimradius]{verbatimradiustopright} -\DeclareStringOption[\sphinxverbatimradius]{verbatimradiusbottomright} -\DeclareStringOption[\sphinxverbatimradius]{verbatimradiusbottomleft} -\define@key{sphinx}{verbatimradius}{% - \sphinxverbatimradius\dimexpr #1\relax - \def\spx@opt@verbatimradiustopleft{\sphinxverbatimradius}% - \def\spx@opt@verbatimradiustopright{\sphinxverbatimradius}% - \def\spx@opt@verbatimradiusbottomright{\sphinxverbatimradius}% - \def\spx@opt@verbatimradiusbottomleft{\sphinxverbatimradius}% +\edef\spx@pre@padding@top {\number\fboxsep sp}% \sphinxverbatimsep to be removed +\let\spx@pre@padding@right \spx@pre@padding@top +\let\spx@pre@padding@bottom\spx@pre@padding@top +\let\spx@pre@padding@left \spx@pre@padding@top +\expandafter\let\expandafter\KV@sphinx@verbatimsep + \csname KV@sphinx@pre_padding\endcsname +% +% We do not define a new \dimen (in 5.x pre-5.1.0 dev branch there +% was a \sphinxverbatimradius when rounded boxes were first introduced, +% but we removed it). +\define@key{sphinx}{pre_border-top-left-radius}{\def\spx@pre@radius@topleft{#1}} +\define@key{sphinx}{pre_border-top-right-radius}{\edef\spx@pre@radius@topright{#1}} +\define@key{sphinx}{pre_border-bottom-right-radius}{\def\spx@pre@radius@bottomright{#1}} +\define@key{sphinx}{pre_border-bottom-left-radius}{\def\spx@pre@radius@bottomleft{#1}} +\define@key{sphinx}{pre_border-radius}{% + \def\spx@pre@radius@topleft {#1}% + \let\spx@pre@radius@topright \spx@pre@radius@topleft + \let\spx@pre@radius@bottomright\spx@pre@radius@topleft + \let\spx@pre@radius@bottomleft \spx@pre@radius@topleft } -\AtBeginDocument{\if1\ifdim\spx@opt@verbatimradiustopleft>\z@0\fi - \ifdim\spx@opt@verbatimradiustopright>\z@0\fi - \ifdim\spx@opt@verbatimradiusbottomright>\z@0\fi - \ifdim\spx@opt@verbatimradiusbottomleft>\z@0\fi +\let\spx@pre@radius@topleft \z@ +\let\spx@pre@radius@topright \spx@pre@radius@topleft +\let\spx@pre@radius@bottomright\spx@pre@radius@topleft +\let\spx@pre@radius@bottomleft \spx@pre@radius@topleft +\AtBeginDocument{\if1\ifdim\spx@pre@radius@topleft>\z@0\fi + \ifdim\spx@pre@radius@topright>\z@0\fi + \ifdim\spx@pre@radius@bottomright>\z@0\fi + \ifdim\spx@pre@radius@bottomleft>\z@0\fi 1\else\spx@RequirePackage@PictIIe\fi} -% topics -\let\sphinxtopicborder\sphinxshadowrule -\DeclareStringOption[\sphinxtopicborder]{topicbordertop} -\DeclareStringOption[\sphinxtopicborder]{topicborderright} -\DeclareStringOption[\sphinxtopicborder]{topicborderbottom} -\DeclareStringOption[\sphinxtopicborder]{topicborderleft} -\define@key{sphinx}{topicborder}{% - \sphinxtopicborder\dimexpr #1\relax - \def\spx@opt@topicbordertop{\sphinxtopicborder}% - \def\spx@opt@topicborderright{\sphinxtopicborder}% - \def\spx@opt@topicborderbottom{\sphinxtopicborder}% - \def\spx@opt@topicborderleft{\sphinxtopicborder}% +% +\newif\ifspx@pre@withshadow +\newif\ifspx@pre@insetshadow +% Attention only "none" or " [optional inset]", no color +\define@key{sphinx}{pre_box-shadow}{\spx@pre@box@shadow@setter #1 {} {} \@nnil}% +% TODO add parsing to fetch color... but this requires a TeX layer to convert +% color spec in CSS format to color/xcolor format +\def\spx@pre@box@shadow@setter #1 #2 #3 #4\@nnil{% + \edef\spx@tempa{#1}% + \ifx\spx@tempa\spxstring@none + \spx@pre@withshadowfalse + \else + \spx@pre@withshadowtrue + \edef\spx@pre@shadow@xoffset{\number\dimexpr#1\relax sp}% + \edef\spx@pre@shadow@yoffset{\number\dimexpr#2+\z@\relax sp}% + \if\relax\detokenize{#3}\relax + \spx@pre@insetshadowfalse + \else + \spx@pre@insetshadowtrue + \fi + \fi +}% +\spx@pre@box@shadow@setter none {} {} \@nnil +% +\newif\ifspx@pre@withbordercolor +\define@key{sphinx}{pre_border-TeXcolor}{% + \spx@pre@withbordercolortrue + \definecolor{VerbatimBorderColor}#1% } -% legacy to be deprecated shadowrule -\define@key{sphinx}{shadowrule}{% - \sphinxtopicborder\dimexpr #1\relax - \def\spx@opt@topicbordertop{\sphinxtopicborder}% - \def\spx@opt@topicborderright{\sphinxtopicborder}% - \def\spx@opt@topicborderbottom{\sphinxtopicborder}% - \def\spx@opt@topicborderleft{\sphinxtopicborder}% +\expandafter\let\expandafter\KV@sphinx@VerbatimBorderColor + \csname KV@sphinx@pre_border-TeXcolor\endcsname +\newif\ifspx@pre@withbackgroundcolor +\define@key{sphinx}{pre_background-TeXcolor}{% + \spx@pre@withbackgroundcolortrue + \definecolor{VerbatimColor}#1% } -\let\sphinxtopicsep\sphinxshadowsep -\DeclareStringOption[\sphinxtopicsep]{topicpaddingtop} -\DeclareStringOption[\sphinxtopicsep]{topicpaddingright} -\DeclareStringOption[\sphinxtopicsep]{topicpaddingbottom} -\DeclareStringOption[\sphinxtopicsep]{topicpaddingleft} -\define@key{sphinx}{topicsep}{% - \sphinxtopicsep\dimexpr #1\relax - \def\spx@opt@topicpaddingtop{\sphinxtopicsep}% - \def\spx@opt@topicpaddingright{\sphinxtopicsep}% - \def\spx@opt@topicpaddingbottom{\sphinxtopicsep}% - \def\spx@opt@topicpaddingleft{\sphinxtopicsep}% +\expandafter\let\expandafter\KV@sphinx@VerbatimColor + \csname KV@sphinx@pre_background-TeXcolor\endcsname +\newif\ifspx@pre@withshadowcolor +\define@key{sphinx}{pre_box-shadow-TeXcolor}{% + \spx@pre@withshadowcolortrue + \definecolor{sphinxVerbatimShadowColor}#1% } -\define@key{sphinx}{shadowsep}{% - \sphinxtopicsep\dimexpr #1\relax - \def\spx@opt@topicpaddingtop{\sphinxtopicsep}% - \def\spx@opt@topicpaddingright{\sphinxtopicsep}% - \def\spx@opt@topicpaddingbottom{\sphinxtopicsep}% - \def\spx@opt@topicpaddingleft{\sphinxtopicsep}% +\definecolor{sphinxVerbatimShadowColor}{rgb}{0,0,0} +% topics +\let\spxdimen@topic@border\sphinxshadowrule +\define@key{sphinx}{aside.topic_border-top-width}{\def\spx@topic@border@top{#1}} +\define@key{sphinx}{aside.topic_border-right-width}{\def\spx@topic@border@right{#1}} +\define@key{sphinx}{aside.topic_border-bottom-width}{\def\spx@topic@border@bottom{#1}} +\define@key{sphinx}{aside.topic_border-left-width}{\def\spx@topic@border@left{#1}} +% attention currently accepts only one dimension specification +\define@key{sphinx}{aside.topic_border-width}{% + \spxdimen@topic@border\dimexpr #1\relax + \def\spx@topic@border@top {\spxdimen@topic@border}% + \let\spx@topic@border@right \spx@topic@border@top + \let\spx@topic@border@bottom\spx@topic@border@top + \let\spx@topic@border@left \spx@topic@border@top } -\newdimen\sphinxtopicradius -\DeclareStringOption[\sphinxtopicradius]{topicradiustopleft} -\DeclareStringOption[\sphinxtopicradius]{topicradiustopright} -\DeclareStringOption[\sphinxtopicradius]{topicradiusbottomright} -\DeclareStringOption[\sphinxtopicradius]{topicradiusbottomleft} -\define@key{sphinx}{topicradius}{% - \sphinxtopicradius\dimexpr #1\relax - \def\spx@opt@topicradiustopleft{\sphinxtopicradius}% - \def\spx@opt@topicradiustopright{\sphinxtopicradius}% - \def\spx@opt@topicradiusbottomright{\sphinxtopicradius}% - \def\spx@opt@topicradiusbottomleft{\sphinxtopicradius}% + \let\spx@topic@border@top \spxdimen@topic@border + \let\spx@topic@border@right \spx@topic@border@top + \let\spx@topic@border@bottom\spx@topic@border@top + \let\spx@topic@border@left \spx@topic@border@top +\expandafter\let\expandafter\KV@sphinx@shadowrule + \csname KV@sphinx@topic_border-width\endcsname +\newif\ifspx@topic@border@open % defaults to false (legacy) +\define@key{sphinx}{aside.topic_box-decoration-break}% + {\edef\spx@tempa{#1}% + \ifx\spx@tempa\spxstring@clone + \spx@topic@border@openfalse + \else\spx@topic@border@opentrue\fi}% +% +% MEMO: \sphinxshadowsep not used anywhere anymore in code base and to be removed +\define@key{sphinx}{topic_padding-top}{\def\spx@topic@padding@top{#1}} +\define@key{sphinx}{topic_padding-right}{\def\spx@topic@padding@right{#1}} +\define@key{sphinx}{topic_padding-bottom}{\def\spx@topic@padding@bottom{#1}} +\define@key{sphinx}{topic_padding-left}{\def\spx@topic@padding@left{#1}} +\define@key{sphinx}{topic_padding}{% + \def\spx@topic@padding@top {#1}% + \let\spx@topic@padding@right \spx@topic@padding@top + \let\spx@topic@padding@bottom\spx@topic@padding@top + \let\spx@topic@padding@left \spx@topic@padding@top } -\AtBeginDocument{\if1\ifdim\spx@opt@topicradiustopleft>\z@0\fi - \ifdim\spx@opt@topicradiustopright>\z@0\fi - \ifdim\spx@opt@topicradiusbottomright>\z@0\fi - \ifdim\spx@opt@topicradiusbottomleft>\z@0\fi +\def\spx@topic@padding@top {5pt}% no usage anymore of \sphinxshadowsep dimen register +\let\spx@topic@padding@right \spx@topic@padding@top +\let\spx@topic@padding@bottom\spx@topic@padding@top +\let\spx@topic@padding@left \spx@topic@padding@top +\expandafter\let\expandafter\KV@sphinx@shadowsep + \csname KV@sphinx@topic_padding\endcsname +% +\def\spx@topic@radius@topleft{\z@} +\def\spx@topic@radius@topright{\z@} +\def\spx@topic@radius@bottomright{\z@} +\def\spx@topic@radius@bottomleft{\z@} +\define@key{sphinx}{aside.topic_border-top-left-radius}{\def\spx@topic@radius@topleft{#1}} +\define@key{sphinx}{aside.topic_border-top-right-radius}{\def\spx@topic@radius@topright{#1}} +\define@key{sphinx}{aside.topic_border-bottom-right-radius}{\def\spx@topic@radius@bottomright{#1}} +\define@key{sphinx}{aside.topic_border-bottom-left-radius}{\def\spx@topic@radius@bottomleft{#1}} +\define@key{sphinx}{aside.topic_border-radius}{% + \def\spx@topic@radius@topleft {#1}% + \let\spx@topic@radius@topright \spx@topic@radius@topleft + \let\spx@topic@radius@bottomright\spx@topic@radius@topleft + \let\spx@topic@radius@bottomleft \spx@topic@radius@topleft +} + \let\spx@topic@radius@topleft \z@ + \let\spx@topic@radius@topright \spx@topic@radius@topleft + \let\spx@topic@radius@bottomright\spx@topic@radius@topleft + \let\spx@topic@radius@bottomleft \spx@topic@radius@topleft +\AtBeginDocument{\if1\ifdim\spx@topic@radius@topleft>\z@0\fi + \ifdim\spx@topic@radius@topright>\z@0\fi + \ifdim\spx@topic@radius@bottomright>\z@0\fi + \ifdim\spx@topic@radius@bottomleft>\z@0\fi 1\else\spx@RequirePackage@PictIIe\fi} -\DeclareStringOption[4pt]{topicshadowxoffset} -\DeclareStringOption[4pt]{topicshadowyoffset} -\define@key{sphinx}{shadowsize}{% legacy - \edef\spx@opt@topicshadowxoffset{\number\dimexpr#1\relax sp}% - \let\spx@opt@topicshadowyoffset\spx@opt@topicshadowxoffset +% +\newif\ifspx@topic@withshadow +\newif\ifspx@topic@insetshadow +% Attention only "none" or " [optional inset]", no color +\define@key{sphinx}{aside.topic_box-shadow}{\spx@topic@box@shadow@setter #1 {} {} \@nnil}% +\def\spx@topic@box@shadow@setter #1 #2 #3 #4\@nnil{% + \edef\spx@tempa{#1}% + \ifx\spx@tempa\spxstring@none + \spx@topic@withshadowfalse + \else + \spx@topic@withshadowtrue + \edef\spx@topic@shadow@xoffset{\number\dimexpr#1\relax sp}% + \edef\spx@topic@shadow@yoffset{\number\dimexpr#2+\z@\relax sp}% + \if\relax\detokenize{#3}\relax + \spx@topic@insetshadowfalse + \else + \spx@topic@insetshadowtrue + \fi + \fi +}% +\spx@topic@box@shadow@setter 4pt 4pt {} \@nnil +% Suport for legacy shadowsize, the \sphinxshadowsize \dimen register +% is not used anymore and should not even be allocated in future +\define@key{sphinx}{shadowsize}{% + \edef\spx@topic@shadow@xoffset{\number\dimexpr#1\relax sp}% + \let\spx@topic@shadow@yoffset\spx@topic@shadow@xoffset + \ifdim\spx@topic@shadow@xoffset=\z@ + \spx@topic@box@withshadowtrue + \else + \spx@topic@box@withshadowfalse + \spx@topic@box@shadow@insetfalse + \fi }% -\DeclareBoolOption[false]{topicwithbackgroundcolor} +\definecolor{sphinxTopicBorderColor}{rgb}{0,0,0} +\definecolor{sphinxTopicBackgroundColor}{rgb}{1,1,1} +\definecolor{sphinxTopicShadowColor}{rgb}{0,0,0} +\newif\ifspx@topic@withbordercolor +\define@key{sphinx}{aside.topic_border-TeXcolor}{% + \spx@topic@withbordercolortrue + \definecolor{sphinxTopicBorderColor}#1% +} +\newif\ifspx@topic@withbackgroundcolor +\define@key{sphinx}{aside.topic_background-TeXcolor}{% + \spx@topic@withbackgroundcolortrue + \definecolor{sphinxTopicBackgroundColor}#1% +} +\newif\ifspx@topic@withshadowcolor +\define@key{sphinx}{aside.topic_box-shadow-TeXcolor}{% + \spx@topic@withshadowcolortrue + \definecolor{sphinxTopicShadowColor}#1% +} +% \DeclareDefaultOption{\@unknownoptionerror} \ProcessKeyvalOptions* diff --git a/sphinx/texinputs/sphinxlatexadmonitions.sty b/sphinx/texinputs/sphinxlatexadmonitions.sty index 00832935819..f78bd6c7f87 100644 --- a/sphinx/texinputs/sphinxlatexadmonitions.sty +++ b/sphinx/texinputs/sphinxlatexadmonitions.sty @@ -71,6 +71,7 @@ \spx@boxes@border@right \FrameRule \spx@boxes@border@bottom\FrameRule \spx@boxes@border@left \FrameRule + \spx@boxes@border \FrameRule % \spx@boxes@padding@top \FrameSep \spx@boxes@padding@right \FrameSep @@ -80,11 +81,11 @@ % \spx@boxes@shadow@xoffset\sphinxshadowsize % A REVOIR % \spx@boxes@shadow@yoffset\sphinxshadowsize % - \spx@boxes@noshadowtrue % no shadow - \spx@boxes@noshadowcolortrue - \spx@boxes@nobackgroundcolorfalse + \spx@boxes@withshadowfalse + \spx@boxes@withshadowcolorfalse + \spx@boxes@withbackgroundcolortrue \sphinxcolorlet{spx@boxes@backgroundcolor}{spx@notice@bgcolor}% - \spx@boxes@nobordercolorfalse + \spx@boxes@withbordercolortrue \sphinxcolorlet{spx@boxes@bordercolor}{spx@notice@bordercolor}% }% % Code adapted from framed.sty's "snugshade" environment. diff --git a/sphinx/texinputs/sphinxlatexliterals.sty b/sphinx/texinputs/sphinxlatexliterals.sty index f6774df2943..de8c15f1ee9 100644 --- a/sphinx/texinputs/sphinxlatexliterals.sty +++ b/sphinx/texinputs/sphinxlatexliterals.sty @@ -111,8 +111,7 @@ % "color push" or "color pop" % About the produced output: % - it obeys current indentation, -% - frame of width \sphinxverbatimborder is \sphinxverbatimsep -arated -% from the contents, +% - frame with 4 padding parameters and 4 border-width parameters % - the contents use the full available text width, limited by indentation, % - #1 = will be typeset above frame, in a non detachable way, % - #2 = will be typeset below frame, in a non detachable way, @@ -128,11 +127,23 @@ \long\def\spx@verb@FrameCommand #1#2#3{% % These \hskips are for fancyvrb.sty measuring and will make the % framing "adapt" to an indented context. - \ifspx@opt@verbatimwithframe\else\sphinxverbatimborder\z@\fi + \ifspx@opt@verbatimwithframe\else\spxdimen@pre@border\z@\fi \hskip\@totalleftmargin - \hskip-\spx@opt@verbatimborderleft\hskip-\spx@opt@verbatimpaddingleft\relax + \hskip-\spx@pre@border@left\hskip-\spx@pre@padding@left\relax + \ifspx@pre@withshadow + \ifspx@pre@insetshadow\else + \ifdim\spx@pre@shadow@xoffset<\z@\hskip\spx@pre@shadow@xoffset\relax + \fi + \fi + \fi \spx@verb@fcolorbox {#1}{#2}{#3}% - \hskip-\spx@opt@verbatimpaddingright\hskip-\spx@opt@verbatimborderright\relax + \hskip-\spx@pre@padding@right\hskip-\spx@pre@border@right\relax + \ifspx@pre@withshadow + \ifspx@pre@insetshadow\else + \ifdim\spx@pre@shadow@xoffset>\z@\hskip-\spx@pre@shadow@xoffset\relax + \fi + \fi + \fi \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth }% \long\def\spx@verb@fcolorbox #1#2#3{% @@ -146,21 +157,25 @@ % \setbox\z@\hbox{#3}% \edef\spx@verb@fcolorbox@width@sp - {\number\dimexpr\wd\z@+\spx@opt@verbatimborderleft - +\spx@opt@verbatimpaddingleft - +\spx@opt@verbatimpaddingright - +\spx@opt@verbatimborderright\relax sp}% + {\number\dimexpr\wd\z@+\spx@pre@border@left + +\spx@pre@padding@left + +\spx@pre@padding@right + +\spx@pre@border@right\relax sp}% \vbox{#1% continuation hint attached above frame, uses \spx@verb@fcolorbox@width@sp % the boxes@fcolorbox constructs an \hbox with bbox containing the border \if1% use rounded boxes only if needed and possible - \ifdim\spx@opt@verbatimradiustopleft >\z@0\fi - \ifdim\spx@opt@verbatimradiustopright >\z@0\fi - \ifdim\spx@opt@verbatimradiusbottomright>\z@0\fi - \ifdim\spx@opt@verbatimradiusbottomleft >\z@0\fi + \ifdim\spx@pre@radius@topleft >\z@0\fi + \ifdim\spx@pre@radius@topright >\z@0\fi + \ifdim\spx@pre@radius@bottomright>\z@0\fi + \ifdim\spx@pre@radius@bottomleft >\z@0\fi 1\spx@boxes@fcolorbox{\box\z@}% \else \@ifpackageloaded{pict2e}% - {\spx@boxes@fcolorbox@rounded{\box\z@}}% + {\ifspx@pre@insetshadow + \spx@boxes@fcolorbox{\box\z@}% + \else + \spx@boxes@fcolorbox@rounded{\box\z@}% + \fi}% {\spx@boxes@fcolorbox{\box\z@}}% \fi % This \nointerlineskip to maintain legacy spacing when a \hrule was @@ -174,12 +189,12 @@ }% \def\spx@verb@fcolorbox@put@r#1{% right align with contents, width hidden \moveright\dimexpr\spx@verb@fcolorbox@width@sp-% - \spx@opt@verbatimpaddingright-% - \spx@opt@verbatimborderright\hb@xt@\z@{\hss#1}% + \spx@pre@padding@right-% + \spx@pre@border@right\hb@xt@\z@{\hss#1}% }% \def\spx@verb@fcolorbox@put@l#1{% left align with contents, width hidden - \moveright\dimexpr\spx@opt@verbatimborderleft+% - \spx@opt@verbatimpaddingleft\hb@xt@\z@{#1\hss}% + \moveright\dimexpr\spx@pre@border@left+% + \spx@pre@padding@left\hb@xt@\z@{#1\hss}% }% % \def\sphinxVerbatim@Continued{% @@ -203,19 +218,19 @@ \spx@verb@FrameCommand\sphinxVerbatim@Before\sphinxVerbatim@After }% \def\sphinxVerbatim@FirstFrameCommand{% - \ifspx@opt@verbatimopenframe + \ifspx@pre@border@open \let\spx@boxes@fcolorbox@init\spx@verb@boxes@fcolorbox@init@openbottom \fi \spx@verb@FrameCommand\sphinxVerbatim@Before\sphinxVerbatim@Continues }% \def\sphinxVerbatim@MidFrameCommand{% - \ifspx@opt@verbatimopenframe + \ifspx@pre@border@open \let\spx@boxes@fcolorbox@init\spx@verb@boxes@fcolorbox@init@openboth \fi \spx@verb@FrameCommand\sphinxVerbatim@Continued\sphinxVerbatim@Continues }% \def\sphinxVerbatim@LastFrameCommand{% - \ifspx@opt@verbatimopenframe + \ifspx@pre@border@open \let\spx@boxes@fcolorbox@init\spx@verb@boxes@fcolorbox@init@opentop \fi \spx@verb@FrameCommand\sphinxVerbatim@Continued\sphinxVerbatim@After @@ -223,30 +238,46 @@ % \def\spx@verb@boxes@fcolorbox@init{% for using \spx@boxes@fcolorbox % - \spx@boxes@border@top \spx@opt@verbatimbordertop - \spx@boxes@border@right \spx@opt@verbatimborderright - \spx@boxes@border@bottom\spx@opt@verbatimborderbottom - \spx@boxes@border@left \spx@opt@verbatimborderleft - \spx@boxes@border \sphinxverbatimborder + \spx@boxes@border@top \spx@pre@border@top + \spx@boxes@border@right \spx@pre@border@right + \spx@boxes@border@bottom\spx@pre@border@bottom + \spx@boxes@border@left \spx@pre@border@left + \spx@boxes@border \spxdimen@pre@border +% + \spx@boxes@padding@top \spx@pre@padding@top + \spx@boxes@padding@right \spx@pre@padding@right + \spx@boxes@padding@bottom\spx@pre@padding@bottom + \spx@boxes@padding@left \spx@pre@padding@left % - \spx@boxes@padding@top \spx@opt@verbatimpaddingtop - \spx@boxes@padding@right \spx@opt@verbatimpaddingright - \spx@boxes@padding@bottom\spx@opt@verbatimpaddingbottom - \spx@boxes@padding@left \spx@opt@verbatimpaddingleft + \spx@boxes@radius@topleft \spx@pre@radius@topleft + \spx@boxes@radius@topright \spx@pre@radius@topright + \spx@boxes@radius@bottomright \spx@pre@radius@bottomright + \spx@boxes@radius@bottomleft \spx@pre@radius@bottomleft % - \spx@boxes@radius@topleft \spx@opt@verbatimradiustopleft - \spx@boxes@radius@topright \spx@opt@verbatimradiustopright - \spx@boxes@radius@bottomright \spx@opt@verbatimradiusbottomright - \spx@boxes@radius@bottomleft \spx@opt@verbatimradiusbottomleft % -% TODO: think about perhaps activating shadows (or rather not...) - \spx@boxes@noshadowtrue % no shadow + \ifspx@pre@withshadow + \spx@boxes@withshadowtrue + \spx@boxes@shadow@xoffset \spx@pre@shadow@xoffset + \spx@boxes@shadow@yoffset \spx@pre@shadow@yoffset\relax + \else + \spx@boxes@withshadowfalse + \fi + \ifspx@pre@insetshadow\spx@boxes@insetshadowtrue\else + \spx@boxes@insetshadowfalse\fi + \ifspx@pre@withshadowcolor\spx@boxes@withshadowcolortrue\else + \spx@boxes@withshadowcolorfalse\fi % - \spx@boxes@nobackgroundcolorfalse % use background color - \sphinxcolorlet{spx@boxes@backgroundcolor}{VerbatimColor}% legacy name + \ifspx@pre@withbackgroundcolor\spx@boxes@withbackgroundcolortrue\else + \spx@boxes@withbackgroundcolorfalse\fi + \sphinxcolorlet{spx@boxes@backgroundcolor}{VerbatimColor}% % - \spx@boxes@nobordercolorfalse % use border color + \ifspx@pre@withbordercolor\spx@boxes@withbordercolortrue\else + \spx@boxes@withbordercolorfalse\fi \sphinxcolorlet{spx@boxes@bordercolor}{VerbatimBorderColor}% + % + \ifspx@pre@withshadowcolor\spx@boxes@withshadowcolortrue\else + \spx@boxes@withshadowcolorfalse\fi + \sphinxcolorlet{spx@boxes@shadowcolor}{sphinxVerbatimShadowColor}% }% \def\spx@verb@boxes@fcolorbox@init@openbottom{% \spx@verb@boxes@fcolorbox@init @@ -711,14 +742,20 @@ \kern\dimexpr-\dp\strutbox+\sphinxbelowcaptionspace % if no frame (code-blocks inside table cells), remove % the "verbatimsep" whitespace from the top (better visually) - \ifspx@opt@verbatimwithframe\else-\sphinxverbatimsep\fi + \ifspx@opt@verbatimwithframe\else + % but we must now check if there is a background color + \ifspx@pre@withbackgroundcolor\else-\spx@pre@padding@top\fi + \fi % caption package adds \abovecaptionskip vspace, remove it \spx@ifcaptionpackage{-\abovecaptionskip}{}\relax}% \else \vskip\sphinxverbatimsmallskipamount \def\sphinxVerbatim@After {\nointerlineskip\kern\dimexpr\dp\strutbox - \ifspx@opt@verbatimwithframe\else-\sphinxverbatimsep\fi + \ifspx@opt@verbatimwithframe\else + % but we must now check if there is a background color + \ifspx@pre@withbackgroundcolor\else-\spx@pre@padding@bottom\fi + \fi \spx@ifcaptionpackage{-\abovecaptionskip}{}\relax \sphinxVerbatim@Title}% \fi @@ -739,7 +776,7 @@ % to decide if to stroke the borders ; ultimately they are also % responsible to attach the "Title". \let\FrameCommand \sphinxVerbatim@FrameCommand - % those will also check status of the verbatimopenframe option + % those will also check status of the pre_box-decoration-break option \let\FirstFrameCommand\sphinxVerbatim@FirstFrameCommand \let\MidFrameCommand \sphinxVerbatim@MidFrameCommand \let\LastFrameCommand \sphinxVerbatim@LastFrameCommand @@ -817,14 +854,24 @@ \ifspx@inframed \egroup % finish \sphinxVerbatim@ContentsBox vbox \nobreak % update page totals - \ifdim\dimexpr\ht\sphinxVerbatim@ContentsBox+ +%%%% +% MEMO (2022/07/09, while preparing 5.1.0 LaTeX CSS-style sphinxsetup options) +% This test will systematically cause to abandon framing if the code-block +% is near bottom of a warning-type notice which TeX has not yet decided whether +% it fits on current page and which is near bottom of page. Indeed the +% \pagetotal will already be very near \pagegoal. This is probably a not +% intended behaviour, and perhaps the whole thing should be removed? Indeed +% the result is surprising then because the notice will be split, code-block +% will be on page 2 and will have no background-color, no border. + \ifdim\dimexpr + \ht\sphinxVerbatim@ContentsBox+ \dp\sphinxVerbatim@ContentsBox+ \ht\sphinxVerbatim@TitleBox+ \dp\sphinxVerbatim@TitleBox+ - \spx@opt@verbatimpaddingleft+ - \spx@opt@verbatimpaddingright+ - \ifspx@opt@verbatimwithframe \spx@opt@verbatimborderleft+ - \spx@opt@verbatimborderright+\fi + \spx@pre@padding@top+ + \spx@pre@padding@bottom+ + \ifspx@opt@verbatimwithframe \spx@pre@border@top+ + \spx@pre@border@bottom+\fi % try to account for external frame parameters % MEMO: this is because the sphinxheavybox (for warning admonitions) % environment sets \FrameSep and \FrameRule diff --git a/sphinx/texinputs/sphinxlatexshadowbox.sty b/sphinx/texinputs/sphinxlatexshadowbox.sty index 1cd3866e8fc..cfd1e562dab 100644 --- a/sphinx/texinputs/sphinxlatexshadowbox.sty +++ b/sphinx/texinputs/sphinxlatexshadowbox.sty @@ -20,32 +20,45 @@ \def\spx@shadowbox@boxes@fcolorbox@init{% % - \spx@boxes@border@top \spx@opt@topicbordertop - \spx@boxes@border@right \spx@opt@topicborderright - \spx@boxes@border@bottom\spx@opt@topicborderbottom - \spx@boxes@border@left \spx@opt@topicborderleft - \spx@boxes@border \sphinxtopicborder + \spx@boxes@border@top \spx@topic@border@top + \spx@boxes@border@right \spx@topic@border@right + \spx@boxes@border@bottom\spx@topic@border@bottom + \spx@boxes@border@left \spx@topic@border@left + \spx@boxes@border \spxdimen@topic@border % - \spx@boxes@padding@top \spx@opt@topicpaddingtop - \spx@boxes@padding@right \spx@opt@topicpaddingright - \spx@boxes@padding@bottom\spx@opt@topicpaddingbottom - \spx@boxes@padding@left \spx@opt@topicpaddingleft + \spx@boxes@padding@top \spx@topic@padding@top + \spx@boxes@padding@right \spx@topic@padding@right + \spx@boxes@padding@bottom\spx@topic@padding@bottom + \spx@boxes@padding@left \spx@topic@padding@left % - \spx@boxes@radius@topleft \spx@opt@topicradiustopleft - \spx@boxes@radius@topright \spx@opt@topicradiustopright - \spx@boxes@radius@bottomright \spx@opt@topicradiusbottomright - \spx@boxes@radius@bottomleft \spx@opt@topicradiusbottomleft + \spx@boxes@radius@topleft \spx@topic@radius@topleft + \spx@boxes@radius@topright \spx@topic@radius@topright + \spx@boxes@radius@bottomright \spx@topic@radius@bottomright + \spx@boxes@radius@bottomleft \spx@topic@radius@bottomleft\relax +% + \ifspx@topic@withshadow + \spx@boxes@withshadowtrue + \spx@boxes@shadow@xoffset \spx@topic@shadow@xoffset + \spx@boxes@shadow@yoffset \spx@topic@shadow@yoffset\relax + \else + \spx@boxes@withshadowfalse + \fi + \ifspx@topic@insetshadow\spx@boxes@insetshadowtrue\else + \spx@boxes@insetshadowfalse\fi + \ifspx@topic@withshadowcolor\spx@boxes@withshadowcolortrue\else + \spx@boxes@withshadowcolorfalse\fi + % + \ifspx@topic@withbackgroundcolor\spx@boxes@withbackgroundcolortrue\else + \spx@boxes@withbackgroundcolorfalse\fi + \sphinxcolorlet{spx@boxes@backgroundcolor}{sphinxTopicBackgroundColor}% % - \spx@boxes@shadow@xoffset\spx@opt@topicshadowxoffset - \spx@boxes@shadow@yoffset\spx@opt@topicshadowyoffset + \ifspx@topic@withbordercolor\spx@boxes@withbordercolortrue\else + \spx@boxes@withbordercolorfalse\fi + \sphinxcolorlet{spx@boxes@bordercolor}{sphinxTopicBorderColor}% % - \spx@boxes@noshadowfalse - \spx@boxes@nobackgroundcolorfalse - \sphinxcolorlet{spx@boxes@backgroundcolor}{sphinxtopicBackgroundColor}% - \spx@boxes@noshadowcolorfalse - \sphinxcolorlet{spx@boxes@shadowcolor}{sphinxtopicShadowColor}% - \spx@boxes@nobordercolorfalse - \sphinxcolorlet{spx@boxes@bordercolor}{sphinxtopicBorderColor}% + \ifspx@topic@withshadowcolor\spx@boxes@withshadowcolortrue\else + \spx@boxes@withshadowcolorfalse\fi + \sphinxcolorlet{spx@boxes@shadowcolor}{sphinxTopicShadowColor}% }% % At 5.1.0 the code formerly here has been refactored and incorporated @@ -53,23 +66,32 @@ \long\def\spx@ShadowFBox#1{% \leavevmode \setbox\z@\hbox{#1}% - % we hide the shadow width - \ifdim\spx@opt@topicshadowxoffset<\z@ - \kern\spx@opt@topicshadowxoffset + \ifspx@topic@withshadow + \ifspx@topic@insetshadow\else + \ifdim\spx@topic@shadow@xoffset<\z@\hskip\spx@topic@shadow@xoffset\relax + \fi + \fi \fi \if1% use rounded boxes only if needed and possible - \ifdim\spx@opt@topicradiustopleft >\z@0\fi - \ifdim\spx@opt@topicradiustopright >\z@0\fi - \ifdim\spx@opt@topicradiusbottomright>\z@0\fi - \ifdim\spx@opt@topicradiusbottomleft >\z@0\fi + \ifdim\spx@topic@radius@topleft >\z@0\fi + \ifdim\spx@topic@radius@topright >\z@0\fi + \ifdim\spx@topic@radius@bottomright>\z@0\fi + \ifdim\spx@topic@radius@bottomleft >\z@0\fi 1\spx@boxes@fcolorbox{\box\z@}% \else \@ifpackageloaded{pict2e}% - {\spx@boxes@fcolorbox@rounded{\box\z@}}% + {\ifspx@topic@insetshadow + \spx@boxes@fcolorbox{\box\z@}% + \else + \spx@boxes@fcolorbox@rounded{\box\z@}% + \fi}% {\spx@boxes@fcolorbox{\box\z@}}% \fi - \ifdim\spx@opt@topicshadowxoffset>\z@ - \kern-\spx@opt@topicshadowxoffset + \ifspx@topic@withshadow + \ifspx@topic@insetshadow\else + \ifdim\spx@topic@shadow@xoffset>\z@\hskip\spx@topic@shadow@xoffset\relax + \fi + \fi \fi } @@ -96,9 +118,9 @@ \let\spx@boxes@fcolorbox@init\spx@shadowbox@boxes@fcolorbox@init \def\FrameCommand {\spx@ShadowFBox }% \advance\spx@image@maxheight - -\dimexpr\spx@opt@topicbordertop+\spx@opt@topicborderbottom - +\spx@opt@topicpaddingtop+\spx@opt@topicpaddingbottom - +\ifdim\spx@opt@topicshadowyoffset<\z@-\fi\spx@opt@topicshadowyoffset + -\dimexpr\spx@topic@border@top+\spx@topic@border@bottom + +\spx@topic@padding@top+\spx@topic@padding@bottom + +\ifdim\spx@topic@shadow@yoffset<\z@-\fi\spx@topic@shadow@yoffset +\baselineskip\relax % configure framed.sty not to add extra vertical spacing \ltx@ifundefined{OuterFrameSep}{}{\OuterFrameSep\z@skip}% diff --git a/sphinx/texinputs/sphinxpackageboxes.sty b/sphinx/texinputs/sphinxpackageboxes.sty index f458d7876c5..d2e535414fd 100644 --- a/sphinx/texinputs/sphinxpackageboxes.sty +++ b/sphinx/texinputs/sphinxpackageboxes.sty @@ -15,10 +15,11 @@ % WIP % Internal dimens, conditionals, and color parameters involved % in \spx@boxes@fcolorbox@init which is to be set by callers -\newif\ifspx@boxes@nobackgroundcolor\spx@boxes@nobackgroundcolortrue -\newif\ifspx@boxes@noshadow \spx@boxes@noshadowtrue -\newif\ifspx@boxes@noshadowcolor \spx@boxes@noshadowcolortrue -\newif\ifspx@boxes@nobordercolor \spx@boxes@nobordercolortrue +\newif\ifspx@boxes@withshadow +\newif\ifspx@boxes@insetshadow +\newif\ifspx@boxes@withbackgroundcolor +\newif\ifspx@boxes@withshadowcolor +\newif\ifspx@boxes@withbordercolor % \newdimen\spx@boxes@border \newdimen\spx@boxes@border@top @@ -38,8 +39,11 @@ \newdimen\spx@boxes@radius@topright \newdimen\spx@boxes@radius@bottomright \newdimen\spx@boxes@radius@bottomleft -% colors be defined by \colorlet or other methods: -% spx@boxes@backgroundcolor, spx@boxes@shadowcolor, spx@boxes@bordercolor +% +% These colours have to be defined in the "init" codes +% spx@boxes@bordercolor +% spx@boxes@backgroundcolor +% spx@boxes@shadowcolor %%%%%%%%%%%%%%%% % MACROS @@ -98,7 +102,7 @@ % The parameters are interpreted as they would as CSS properties. % For the shadow inset variant see separate \spx@boxes@fcolorbox@insetshadow \long\def\spx@boxes@fcolorbox#1{% - \hbox{% + \hbox\bgroup \spx@boxes@fcolorbox@init \setbox\spx@tempboxa \hbox{\kern\dimexpr\spx@boxes@border@left+\spx@boxes@padding@left\relax @@ -108,13 +112,21 @@ \dimexpr\ht\spx@tempboxa+\spx@boxes@border@top+\spx@boxes@padding@top\relax \dp\spx@tempboxa \dimexpr\dp\spx@tempboxa+\spx@boxes@padding@bottom+\spx@boxes@border@bottom\relax + \ifspx@boxes@insetshadow + \expandafter\spx@boxes@fcolorbox@insetshadow + \else + \expandafter\spx@boxes@fcolorbox@externalshadow + \fi +} + +\def\spx@boxes@fcolorbox@externalshadow{% % reserve space to shadow if on left - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@xoffset<\z@\kern-\spx@boxes@shadow@xoffset\fi \fi % BACKGROUND % draw background and move back to reference point - \ifspx@boxes@nobackgroundcolor\else + \ifspx@boxes@withbackgroundcolor {\color{spx@boxes@backgroundcolor}% \vrule\@height\ht\spx@tempboxa \@depth\dp\spx@tempboxa @@ -124,11 +136,11 @@ \fi % BOX SHADOW % draw shadow and move back to reference point - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \vbox{% \moveright\spx@boxes@shadow@xoffset \hbox{\lower\spx@boxes@shadow@yoffset - \vbox{\ifspx@boxes@noshadowcolor\else\color{spx@boxes@shadowcolor}\fi + \vbox{\ifspx@boxes@withshadowcolor\color{spx@boxes@shadowcolor}\fi \ifdim\spx@boxes@shadow@yoffset<\z@ \hrule\@height-\spx@boxes@shadow@yoffset \kern\spx@boxes@shadow@yoffset @@ -155,7 +167,7 @@ }% end of \vbox \fi % end of shadow drawing, and we are back to horizontal reference point % BOX BORDER - \vbox{\ifspx@boxes@nobordercolor\else\color{spx@boxes@bordercolor}\fi + \vbox{\ifspx@boxes@withbordercolor\color{spx@boxes@bordercolor}\fi \hrule\@height\spx@boxes@border@top \kern-\spx@boxes@border@top \setbox\spx@tempboxb\hb@xt@\wd\spx@tempboxa @@ -174,35 +186,25 @@ % end of border drawing % CONTENTS % adjust the total depth to include the bottom shadow - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@yoffset>\z@ \dp\spx@tempboxa\dimexpr\dp\spx@tempboxa+\spx@boxes@shadow@yoffset\relax \fi \fi \box\spx@tempboxa % include lateral shadow in total width - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@xoffset>\z@\kern\spx@boxes@shadow@xoffset\fi \fi - }% + \egroup } %//// \spx@boxes@fcolorbox@insetshadow % The parameters are interpreted as in CSS styling. -\long\def\spx@boxes@fcolorbox@insetshadow#1{% - \hbox{% - \spx@boxes@fcolorbox@insetshadow@init - \setbox\spx@tempboxa - \hbox{\kern\dimexpr\spx@boxes@border@left+\spx@boxes@padding@left\relax - {#1}% - \kern\dimexpr\spx@boxes@padding@right+\spx@boxes@border@right\relax}% - \ht\spx@tempboxa - \dimexpr\ht\spx@tempboxa+\spx@boxes@border@top+\spx@boxes@padding@top\relax - \dp\spx@tempboxa - \dimexpr\dp\spx@tempboxa+\spx@boxes@padding@bottom+\spx@boxes@border@bottom\relax +\def\spx@boxes@fcolorbox@insetshadow{% % BACKGROUND % draw background and move back to reference point - \ifspx@boxes@nobackgroundcolor\else + \ifspx@boxes@withbackgroundcolor {\color{spx@boxes@backgroundcolor}% \vrule\@height\ht\spx@tempboxa \@depth\dp\spx@tempboxa @@ -212,8 +214,8 @@ \fi % BOX SHADOW % draw shadow and move back to reference point - \ifspx@boxes@noshadow\else - \hbox{\vbox{\ifspx@boxes@noshadowcolor\else\color{spx@boxes@shadowcolor}\fi + \ifspx@boxes@withshadow + \hbox{\vbox{\ifspx@boxes@withshadowcolor\color{spx@boxes@shadowcolor}\fi % NOTA BENE % We deliberately draw shadow partially under an area later covered by frame % with the idea to avoid anti-aliasing problems but in fact this may be a bad @@ -245,7 +247,7 @@ }% end of \hbox, attention its depth is only |yoffset| if yoffset<0 \fi % end of inset shadow drawing, and we are back to horizontal reference point % BOX BORDER - \vbox{\ifspx@boxes@nobordercolor\else\color{spx@boxes@bordercolor}\fi + \vbox{\ifspx@boxes@withbordercolor\color{spx@boxes@bordercolor}\fi \hrule\@height\spx@boxes@border@top \kern-\spx@boxes@border@top \setbox\spx@tempboxb\hb@xt@\wd\spx@tempboxa @@ -264,7 +266,7 @@ % end of border drawing % CONTENTS \box\spx@tempboxa - }% + \egroup } @@ -350,12 +352,12 @@ \hbox{% \spx@boxes@fcolorbox@init % reserve space to shadow if on left - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@xoffset<\z@\kern-\spx@boxes@shadow@xoffset\fi \fi \vbox{% % adjust vertical bbox - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@yoffset<\z@ \kern-\spx@boxes@shadow@yoffset \fi @@ -375,26 +377,28 @@ % (we could use the "picture" package, this would add another dependency) (\strip@pt\wd\spx@tempboxa,\strip@pt\dimexpr\ht\spx@tempboxa+\dp\spx@tempboxa)% (\strip@pt\dimexpr-.5\spx@boxes@border,\strip@pt\dimexpr-.5\spx@boxes@border)% -\ifspx@boxes@noshadow\else +\ifspx@boxes@withshadow \color{spx@boxes@shadowcolor}% \put(\dimexpr\ifdim\spx@boxes@shadow@xoffset<\z@-\fi 0.5\spx@boxes@border+\spx@boxes@shadow@xoffset,% \dimexpr\ifdim\spx@boxes@shadow@yoffset<\z@\else-\fi 0.5\spx@boxes@border-\spx@boxes@shadow@yoffset) {\spx@boxes@borderpath\fillpath}% - \ifspx@boxes@nobackgroundcolor + {\ifspx@boxes@withbackgroundcolor\else \color{white}% or rather try to use page color? \spx@boxes@borderpath\fillpath - \fi + \fi}% \fi -\ifspx@boxes@nobackgroundcolor\else +{\ifspx@boxes@withbackgroundcolor \color{spx@boxes@backgroundcolor}% \spx@boxes@borderpath\fillpath -\fi +\fi}% \ifdim\spx@boxes@border>\z@ % even with \spx@boxes@border set to 0pt as done if verbatimwithframe=false % stroke will produce a visible contour, so we exclude doing it in that case + \ifspx@boxes@withbordercolor \color{spx@boxes@bordercolor}% + \fi \linethickness{\spx@boxes@border}% \ifdim\spx@boxes@border@top=\z@ \ifdim\spx@boxes@border@bottom=\z@ @@ -412,7 +416,7 @@ % back-up vertically for outputting the contents \kern-\dimexpr\ht\spx@tempboxa+\dp\spx@tempboxa\relax % adjust vertical bbox - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@yoffset>\z@ \dp\spx@tempboxa\dimexpr\dp\spx@tempboxa+\spx@boxes@shadow@yoffset\relax \fi @@ -420,7 +424,7 @@ \box\spx@tempboxa }% end of \vbox % include lateral shadow in total width - \ifspx@boxes@noshadow\else + \ifspx@boxes@withshadow \ifdim\spx@boxes@shadow@xoffset>\z@\kern\spx@boxes@shadow@xoffset\fi \fi }% end of \hbox