1%% TOPIC AND CONTENTS BOXES
2%
3% change this info string if making any custom modification
4\ProvidesFile{sphinxlatexshadowbox.sty}[2021/01/27 sphinxShadowBox]
5
6% Provides support for this output mark-up from Sphinx latex writer:
7%
8% - sphinxShadowBox (environment)
9%
10% Dependencies (they do not need to be defined at time of loading):
11%
12% - of course the various colour and dimension options handled via sphinx.sty
13% - dimension register \spx@image@maxheight from sphinxlatexgraphics.sty
14% - \savenotes/\spewnotes from sphinxpackagefootnote
15% - \ifspx@inframed defined in sphinx.sty
16%
17% Requires:
18\RequirePackage{framed}
19
20% Again based on use of "framed.sty", this allows breakable framed boxes.
21\long\def\spx@ShadowFBox#1{%
22  \leavevmode\begingroup
23  % first we frame the box #1
24  \setbox\@tempboxa
25   \hbox{\vrule\@width\sphinxshadowrule
26         \vbox{\hrule\@height\sphinxshadowrule
27               \kern\sphinxshadowsep
28               \hbox{\kern\sphinxshadowsep #1\kern\sphinxshadowsep}%
29               \kern\sphinxshadowsep
30               \hrule\@height\sphinxshadowrule}%
31         \vrule\@width\sphinxshadowrule}%
32  % Now we add the shadow, like \shadowbox from fancybox.sty would do
33  \dimen@\dimexpr.5\sphinxshadowrule+\sphinxshadowsize\relax
34  \hbox{\vbox{\offinterlineskip
35              \hbox{\copy\@tempboxa\kern-.5\sphinxshadowrule
36                    % add shadow on right side
37                    \lower\sphinxshadowsize
38                          \hbox{\vrule\@height\ht\@tempboxa \@width\dimen@}%
39                    }%
40              \kern-\dimen@ % shift back vertically to bottom of frame
41              % and add shadow at bottom
42              \moveright\sphinxshadowsize
43                    \vbox{\hrule\@width\wd\@tempboxa \@height\dimen@}%
44              }%
45        % move left by the size of right shadow so shadow adds no width
46        \kern-\sphinxshadowsize
47       }%
48  \endgroup
49}
50
51% use framed.sty to allow page breaks in frame+shadow
52% works well inside Lists and Quote-like environments
53% produced by ``topic'' directive (or local contents)
54% could nest if LaTeX writer authorized it
55\newenvironment{sphinxShadowBox}
56  {\def\FrameCommand {\spx@ShadowFBox }%
57   \advance\spx@image@maxheight
58   -\dimexpr2\sphinxshadowrule
59           +2\sphinxshadowsep
60           +\sphinxshadowsize
61           +\baselineskip\relax
62   % configure framed.sty not to add extra vertical spacing
63   \ltx@ifundefined{OuterFrameSep}{}{\OuterFrameSep\z@skip}%
64   % the \trivlist will add the vertical spacing on top and bottom which is
65   % typical of center environment as used in Sphinx <= 1.4.1
66   % the \noindent has the effet of an extra blank line on top, to
67   % imitate closely the layout from Sphinx <= 1.4.1; the \FrameHeightAdjust
68   % will put top part of frame on this baseline.
69   \def\FrameHeightAdjust {\baselineskip}%
70   % use package footnote to handle footnotes
71   \savenotes
72   \trivlist\item\noindent
73    % use a minipage if we are already inside a framed environment
74    \ifspx@inframed\begin{minipage}{\linewidth}\fi
75    \MakeFramed {\spx@inframedtrue
76    % framed.sty puts into "\width" the added width (=2shadowsep+2shadowrule)
77    % adjust \hsize to what the contents must use
78    \advance\hsize-\width
79    % adjust LaTeX parameters to behave properly in indented/quoted contexts
80    \FrameRestore
81    % typeset the contents as in a minipage (Sphinx <= 1.4.1 used a minipage and
82    % itemize/enumerate are therein typeset more tightly, we want to keep
83    % that). We copy-paste from LaTeX source code but don't do a real minipage.
84    \@pboxswfalse
85    \let\@listdepth\@mplistdepth \@mplistdepth\z@
86    \@minipagerestore
87    \@setminipage
88    }%
89  }%
90  {% insert the "endminipage" code
91    \par\unskip
92    \@minipagefalse
93   \endMakeFramed
94     \ifspx@inframed\end{minipage}\fi
95   \endtrivlist
96   % output the stored footnotes
97   \spewnotes
98  }
99
100\endinput
101