Skip to content

Commit

Permalink
LaTeX: user interface via 'sphinxsetup' to enhanced topic boxes
Browse files Browse the repository at this point in the history
Border widths, padding widths, rounded corners, background color are all
available.

Rounded corners work only with a constant border width.

The shadow xoffset and yoffset may be negative.
  • Loading branch information
jfbu committed Jul 8, 2022
1 parent fc5aed6 commit 717f0e4
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 70 deletions.
109 changes: 93 additions & 16 deletions sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@
\newdimen\sphinxverbatimsep
\newdimen\sphinxverbatimborder
\newdimen\sphinxverbatimradius
\newdimen\sphinxshadowsep
\newdimen\sphinxshadowsize
\newdimen\sphinxshadowrule
%
% \DeclareStringOption is not convenient for the handling of these dimensions
% because we want to assign the values to the corresponding registers. Even if
% we added the code to the key handler it would be too late for the initial
Expand Down Expand Up @@ -114,12 +112,20 @@
[{\makebox[2\fontcharwd\font`\x][r]{\textcolor{red}{\tiny$\m@th\hookrightarrow$}}}]%
{verbatimcontinued}
% topic boxes
\sphinxshadowsep =5pt
\define@key{sphinx}{shadowsep}{\sphinxshadowsep\dimexpr #1\relax}
\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
\sphinxshadowsep=5pt
\define@key{sphinx}{shadowsep}{\sphinxtopicsep\dimexpr #1\relax}%
% redefined below
\sphinxshadowsize=4pt
\define@key{sphinx}{shadowsize}{\sphinxshadowsize\dimexpr #1\relax}
\define@key{sphinx}{shadowsize}{\sphinxshadowsize\dimexpr #1\relax}
% redefined below
\sphinxshadowrule=\fboxrule
\define@key{sphinx}{shadowrule}{\sphinxshadowrule\dimexpr #1\relax}
\define@key{sphinx}{shadowrule}{\sphinxtopicborder\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
Expand Down Expand Up @@ -163,8 +169,19 @@
% 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}}
\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}}
Expand All @@ -181,7 +198,10 @@
\sphinxDeclareSphinxColorOption{attentionBgColor}{{rgb}{1,1,1}}
\sphinxDeclareSphinxColorOption{dangerBgColor}{{rgb}{1,1,1}}
\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}
Expand All @@ -197,7 +217,7 @@
\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingright}
\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingbottom}
\DeclareStringOption[\sphinxverbatimsep]{verbatimpaddingleft}
\define@key{sphinx}{verbatimpadding}{%
\define@key{sphinx}{verbatimsep}{%
\sphinxverbatimsep\dimexpr #1\relax
\def\spx@opt@verbatimpaddingtop{\sphinxverbatimsep}%
\def\spx@opt@verbatimpaddingright{\sphinxverbatimsep}%
Expand All @@ -220,13 +240,70 @@
\ifdim\spx@opt@verbatimradiusbottomright>\z@0\fi
\ifdim\spx@opt@verbatimradiusbottomleft>\z@0\fi
1\else\spx@RequirePackage@PictIIe\fi}
\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}%
% 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}%
}
% 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}%
}
\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}%
}
\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}%
}
\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}%
}
\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
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
}%
\DeclareBoolOption[false]{topicwithbackgroundcolor}

\DeclareDefaultOption{\@unknownoptionerror}
\ProcessKeyvalOptions*
Expand Down
4 changes: 2 additions & 2 deletions sphinx/texinputs/sphinxlatexadmonitions.sty
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
\spx@boxes@padding@bottom\FrameSep
\spx@boxes@padding@left \FrameSep
%
\spx@boxes@shadow@xoffset\sphinxshadowsize
\spx@boxes@shadow@yoffset\sphinxshadowsize
% \spx@boxes@shadow@xoffset\sphinxshadowsize % A REVOIR
% \spx@boxes@shadow@yoffset\sphinxshadowsize
%
\spx@boxes@noshadowtrue % no shadow
\spx@boxes@noshadowcolortrue
Expand Down
63 changes: 42 additions & 21 deletions sphinx/texinputs/sphinxlatexshadowbox.sty
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,57 @@
\RequirePackage{sphinxpackageboxes}

\def\spx@shadowbox@boxes@fcolorbox@init{%
\spx@boxes@border@top \sphinxshadowrule
\spx@boxes@border@right \sphinxshadowrule
\spx@boxes@border@bottom\sphinxshadowrule
\spx@boxes@border@left \sphinxshadowrule
%
\spx@boxes@padding@top \sphinxshadowsep
\spx@boxes@padding@right \sphinxshadowsep
\spx@boxes@padding@bottom\sphinxshadowsep
\spx@boxes@padding@left \sphinxshadowsep
%
\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@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@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@shadow@xoffset\sphinxshadowsize
\spx@boxes@shadow@yoffset\sphinxshadowsize
\spx@boxes@shadow@xoffset\spx@opt@topicshadowxoffset
\spx@boxes@shadow@yoffset\spx@opt@topicshadowyoffset
%
\spx@boxes@noshadowfalse
\spx@boxes@nobackgroundcolortrue
\spx@boxes@nobackgroundcolorfalse
\sphinxcolorlet{spx@boxes@backgroundcolor}{sphinxtopicBackgroundColor}%
\spx@boxes@noshadowcolorfalse
\sphinxcolorlet{spx@boxes@shadowcolor}{sphinxshadowShadowColor}%
\sphinxcolorlet{spx@boxes@shadowcolor}{sphinxtopicShadowColor}%
\spx@boxes@nobordercolorfalse
\sphinxcolorlet{spx@boxes@bordercolor}{sphinxshadowBorderColor}%
\sphinxcolorlet{spx@boxes@bordercolor}{sphinxtopicBorderColor}%
}%

% At 5.1.0 the code formerly here has been refactored and incorporated
% into more powerful \spx@boxes@fcolorbox from sphinxpackageboxes.sty
\long\def\spx@ShadowFBox#1{%
\leavevmode
\setbox\z@\hbox{#1}%
% we hide the shadow width
\ifdim\sphinxshadowsize>\z@
\spx@boxes@fcolorbox{#1}\kern-\sphinxshadowsize
\else
\kern\sphinxshadowsize\spx@boxes@fcolorbox{#1}%
\ifdim\spx@opt@topicshadowxoffset<\z@
\kern\spx@opt@topicshadowxoffset
\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
1\spx@boxes@fcolorbox{\box\z@}%
\else
\@ifpackageloaded{pict2e}%
{\spx@boxes@fcolorbox@rounded{\box\z@}}%
{\spx@boxes@fcolorbox{\box\z@}}%
\fi
\ifdim\spx@opt@topicshadowxoffset>\z@
\kern-\spx@opt@topicshadowxoffset
\fi
}

Expand All @@ -75,9 +96,9 @@
\let\spx@boxes@fcolorbox@init\spx@shadowbox@boxes@fcolorbox@init
\def\FrameCommand {\spx@ShadowFBox }%
\advance\spx@image@maxheight
-\dimexpr2\sphinxshadowrule
+2\sphinxshadowsep
+\sphinxshadowsize
-\dimexpr\spx@opt@topicbordertop+\spx@opt@topicborderbottom
+\spx@opt@topicpaddingtop+\spx@opt@topicpaddingbottom
+\ifdim\spx@opt@topicshadowyoffset<\z@-\fi\spx@opt@topicshadowyoffset
+\baselineskip\relax
% configure framed.sty not to add extra vertical spacing
\ltx@ifundefined{OuterFrameSep}{}{\OuterFrameSep\z@skip}%
Expand Down

0 comments on commit 717f0e4

Please sign in to comment.