Skip to content

Commit

Permalink
LaTeX: refactor sphinxShadowBox to allow colors for frame and shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbu committed Jun 30, 2022
1 parent b9736f2 commit 8153dbf
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 20 deletions.
16 changes: 15 additions & 1 deletion doc/latex.rst
Expand Up @@ -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``

Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion sphinx/texinputs/sphinx.sty
Expand Up @@ -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
Expand Down Expand Up @@ -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}}
Expand Down
73 changes: 55 additions & 18 deletions 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:
%
Expand All @@ -17,37 +17,74 @@
% Requires:
\RequirePackage{framed}

% Again based on use of "framed.sty", this allows breakable framed boxes.
% Let's draw the contents first, then the shadow, then the frame latest
% to avoid problems with some pdf viewers.
\long\def\spx@ShadowFBox#1{%
\leavevmode\begingroup
% first we frame the box #1
% first we box the contents #1 in a larger box
% formerly, it was not drawn first, and the code here looks a bit strange,
% but it is done like this for sake of simplicity of the refactoring
% from the former version to the new one
\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
\hbox{\vbox{\offinterlineskip
\hbox{\copy\@tempboxa\kern-.5\sphinxshadowrule
% add shadow on right side
\kern\sphinxshadowrule}%
\kern\sphinxshadowrule}%
% now we draw it, then the shadow, then the frame
% formerly, we drew the shadow partly on top of frame (up to its middle),
% but at that time colors were hard-coded to black only; so now we draw
% with no overlap. Sorry for artistic indentation of code lines...
\hbox{\vbox{\hbox{\vbox{\offinterlineskip
\hbox{\copy\@tempboxa
% \kern-.5\sphinxshadowrule
% add colored 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
% and add shadow at bottom
\kern-\sphinxshadowsize% shift back vertically to bottom of frame
% and add colored shadow at bottom
\moveright\sphinxshadowsize
\vbox{\hrule\@width\wd\@tempboxa \@height\dimen@}%
}%
% move left by the size of right shadow so shadow adds no width
\vbox{{\color{sphinxshadowShadowColor}%
\hrule\@width\wd\@tempboxa \@height\sphinxshadowsize}}%
% move back vertically to hide this from the vertical rules next
\kern-\sphinxshadowsize
}%
% move back horizontally to hide the right shadow from horizontal
% rules next and also from framed measurement
\kern-\sphinxshadowsize
}%
% move back vertically
\kern-\sphinxshadowrule\relax
% draw the bottom border
{\color{sphinxshadowBorderColor}\hrule\@height\sphinxshadowrule}%
% move back to top
\kern-\ht\@tempboxa
% draw the top border
{\color{sphinxshadowBorderColor}\hrule\@height\sphinxshadowrule}%
% move again to bottom
\kern\dimexpr\ht\@tempboxa-\sphinxshadowrule\relax
}%
% move left slightly to draw the right border
\kern-\sphinxshadowrule
% draw the right border
{\color{sphinxshadowBorderColor}\vrule\@width\sphinxshadowrule}%
% move left all the way
\kern-\wd\@tempboxa
% draw the left border
{\color{sphinxshadowBorderColor}\vrule\@width\sphinxshadowrule}%
% move back to right border so the box has kept correct width
\kern\dimexpr\wd\@tempboxa-\sphinxshadowrule\relax
}%
% move down vertically to account for the bottom shadow
\kern\sphinxshadowsize
\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)
Expand Down

0 comments on commit 8153dbf

Please sign in to comment.