Skip to content

Commit

Permalink
LaTeX: CSS-named-alikes 'sphinxsetup' keys for warning type notices
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbu committed Jul 9, 2022
1 parent e89c29a commit 1341fb4
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 49 deletions.
160 changes: 158 additions & 2 deletions sphinx/texinputs/sphinx.sty
Expand Up @@ -171,7 +171,6 @@
\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}}
Expand Down Expand Up @@ -427,7 +426,164 @@
\spx@topic@withshadowcolortrue
\definecolor{sphinxTopicShadowColor}#1%
}
%
% warning, caution, attention, danger, error
\def\spx@tempc#1{%
\expandafter\spx@tempb
% MEMO: the diverging naming of first one is conditioned at this time by the fact
% that sphinxnotice environment must work both for these admonitions and the
% note, tip etc... ones
\csname spx@opt@#1border\expandafter\endcsname
\csname spx@#1@border@top\expandafter\endcsname
\csname spx@#1@border@right\expandafter\endcsname
\csname spx@#1@border@left\expandafter\endcsname
\csname spx@#1@border@bottom\expandafter\endcsname
\csname ifspx@#1@border@open\expandafter\endcsname
\csname spx@#1@border@opentrue\expandafter\endcsname
\csname spx@#1@border@openfalse\endcsname
{#1}%
}%
\def\spx@tempb #1#2#3#4#5#6#7#8#9{%
\define@key{sphinx}{div.#9_border-top-width}{\def#2{##1}}%
\define@key{sphinx}{div.#9_border-right-width}{\def#3{##1}}%
\define@key{sphinx}{div.#9_border-bottom-width}{\def#4{##1}}%
\define@key{sphinx}{div.#9_border-left-width}{\def#5{##1}}%
\define@key{sphinx}{div.#9_border-width}{\def#1{##1}\def#2{#1}\let#3#2\let#4#2\let#5#2}%
\def#1{1pt}\let#2#1\let#3#2\let#4#2\let#5#2%
\newif#6%
\define@key{sphinx}{div.#9_box-decoration-break}%
{\edef\spx@tempa{##1}%
\ifx\spx@tempa\spxstring@clone#8\else#7\fi}%
\expandafter\let\csname KV@sphinx@#9border\expandafter\endcsname
\csname KV@sphinx@div.#9_border-width\endcsname
}
\spx@tempc{warning}
\spx@tempc{caution}
\spx@tempc{attention}
\spx@tempc{danger}
\spx@tempc{error}

\def\spx@tempc#1{%
\expandafter\spx@tempb
\csname spx@#1@padding\expandafter\endcsname
\csname spx@#1@padding@top\expandafter\endcsname
\csname spx@#1@padding@right\expandafter\endcsname
\csname spx@#1@padding@left\expandafter\endcsname
\csname spx@#1@padding@bottom\endcsname
{#1}%
}%
\def\spx@tempb #1#2#3#4#5#6{%
\define@key{sphinx}{div.#6_padding-top}{\def#2{##1}}%
\define@key{sphinx}{div.#6_padding-right}{\def#3{##1}}%
\define@key{sphinx}{div.#6_padding-bottom}{\def#4{##1}}%
\define@key{sphinx}{div.#6_padding-left}{\def#5{##1}}%
\define@key{sphinx}{div.#6_padding}{\def#1{##1}\def#2{#1}\let#3#2\let#4#2\let#5#2}%
\edef#1{\number\dimexpr.6\baselineskip-1pt\relax sp}% (from legacy coding in sphinxheavybox)
\let#2#1\let#3#2\let#4#2\let#5#2%
\expandafter\let\csname KV@sphinx@#6padding\expandafter\endcsname
\csname KV@sphinx@div.#6_padding\endcsname
}
\spx@tempc{warning}
\spx@tempc{caution}
\spx@tempc{attention}
\spx@tempc{danger}
\spx@tempc{error}

\def\spx@tempc#1{%
\expandafter\spx@tempb
\csname spx@#1@radius@topleft\expandafter\endcsname
\csname spx@#1@radius@topright\expandafter\endcsname
\csname spx@#1@radius@bottomright\expandafter\endcsname
\csname spx@#1@radius@bottomleft\endcsname
{#1}%
}%
\def\spx@tempb #1#2#3#4#5{%
\define@key{sphinx}{div.#5_border-top-left-radius}{\def#1{##1}}%
\define@key{sphinx}{div.#5_border-top-right-radius}{\def#2{##1}}%
\define@key{sphinx}{div.#5_border-bottom-right-radius}{\def#3{##1}}%
\define@key{sphinx}{div.#5_border-bottom-left-radius}{\def#4{##1}}%
\define@key{sphinx}{div.#5_border-radius}{\def#1{##1}\let#2#1\let#3#1\let#4#1}%
\let#1\z@\let#2#1\let#3#2\let#4#2%
\AtBeginDocument{\if1\ifdim#1>\z@0\fi
\ifdim#2>\z@0\fi
\ifdim#3>\z@0\fi
\ifdim#4>\z@0\fi
1\else\spx@RequirePackage@PictIIe\fi}%
}
\spx@tempc{warning}
\spx@tempc{caution}
\spx@tempc{attention}
\spx@tempc{danger}
\spx@tempc{error}

\def\spx@tempc#1{%
\expandafter\spx@tempb
\csname ifspx@#1@withshadow\expandafter\endcsname
\csname ifspx@#1@insetshadow\expandafter\endcsname
\csname ifspx@#1@withshadowcolor\expandafter\endcsname
\csname ifspx@#1@withbordercolor\expandafter\endcsname
\csname ifspx@#1@withbackgroundcolor\endcsname
}%
\def\spx@tempb#1#2#3#4#5{\newif#1\newif#2\newif#3\newif#4\newif#5}%
\spx@tempc{warning}
\spx@tempc{caution}
\spx@tempc{attention}
\spx@tempc{danger}
\spx@tempc{error}

\def\spx@tempc#1{%
\expandafter\spx@tempb
\csname spx@#1@withshadowtrue\expandafter\endcsname
\csname spx@#1@withshadowfalse\expandafter\endcsname
\csname spx@#1@insetshadowtrue\expandafter\endcsname
\csname spx@#1@insetshadowfalse\expandafter\endcsname
\csname spx@#1@box@shadow@setter\expandafter\endcsname
\csname spx@#1@box@shadow@xoffset\expandafter\endcsname
\csname spx@#1@box@shadow@yoffset\endcsname
{#1}%
}%
\def\spx@tempb#1#2#3#4#5#6#7#8{%
\define@key{sphinx}{div.#8_box-shadow}{#5##1 {} {} \@nnil}%
\def#5##1 ##2 ##3 ##4\@nnil{%
\edef\spx@tempa{##1}%
\ifx\spx@tempa\spxstring@none
#2%
\else #1\edef#6{\number\dimexpr##1\relax sp}%
\edef#7{\number\dimexpr##2+\z@\relax sp}%
\if\relax\detokenize{##3}\relax#4\else#3\fi
\fi
}#5none {} {} \@nnil
}
\spx@tempc{warning}
\spx@tempc{caution}
\spx@tempc{attention}
\spx@tempc{danger}
\spx@tempc{error}

\def\spx@tempc#1{%
\expandafter\spx@tempb
\csname spx@#1@withbordercolortrue\expandafter\endcsname
\csname spx@#1@withbackgroundcolortrue\expandafter\endcsname
\csname spx@#1@withshadowcolortrue\endcsname
{#1}%
}
\def\spx@tempb#1#2#3#4{%
\definecolor{sphinx#4BorderColor}{rgb}{0,0,0}%
\definecolor{sphinx#4BgColor}{rgb}{1,1,1}%
\definecolor{sphinx#4ShadowColor}{rgb}{0,0,0}%
\define@key{sphinx}{div.#4_border-TeXcolor}{#1\definecolor{sphinx#4BorderColor}##1}%
\define@key{sphinx}{div.#4_background-TeXcolor}{#2\definecolor{sphinx#4BgColor}##1}%
\define@key{sphinx}{div.#4_box-shadow-TeXcolor}{#3\definecolor{sphinx#4ShadowColor}##1}%
\expandafter\let\csname KV@sphinx@#4BorderColor\expandafter\endcsname
\csname KV@sphinx@div.#4_border-TeXcolor\endcsname
\expandafter\let\csname KV@sphinx@#4BgColor\expandafter\endcsname
\csname KV@sphinx@div.#4_background-TeXcolor\endcsname
}
\spx@tempc{warning}
\spx@tempc{caution}
\spx@tempc{attention}
\spx@tempc{danger}
\spx@tempc{error}


\DeclareDefaultOption{\@unknownoptionerror}
\ProcessKeyvalOptions*
Expand Down
122 changes: 95 additions & 27 deletions sphinx/texinputs/sphinxlatexadmonitions.sty
Expand Up @@ -66,49 +66,117 @@
\definecolor{sphinxtipBgColor}{rgb}{1,1,1}

% Others get more distinction
\def\spx@admonitions@boxes@fcolorbox@init{%
\spx@boxes@border@top \FrameRule
\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
\spx@boxes@padding@bottom\FrameSep
\spx@boxes@padding@left \FrameSep
%
% \spx@boxes@shadow@xoffset\sphinxshadowsize % A REVOIR
% \spx@boxes@shadow@yoffset\sphinxshadowsize
\def\spx@admonitions@boxes@fcolorbox@setup{%
\spx@boxes@border@top \@nameuse{spx@\spx@noticetype @border@top}%
\spx@boxes@border@right \@nameuse{spx@\spx@noticetype @border@right}%
\spx@boxes@border@bottom\@nameuse{spx@\spx@noticetype @border@bottom}%
\spx@boxes@border@left \@nameuse{spx@\spx@noticetype @border@left}%
\spx@boxes@border \spx@notice@border
%
\spx@boxes@padding@top \@nameuse{spx@\spx@noticetype @padding@top}%
\spx@boxes@padding@right \@nameuse{spx@\spx@noticetype @padding@right}%
\spx@boxes@padding@bottom\@nameuse{spx@\spx@noticetype @padding@bottom}%
\spx@boxes@padding@left \@nameuse{spx@\spx@noticetype @padding@left}%
%
\spx@boxes@radius@topleft \@nameuse{spx@\spx@noticetype @radius@topleft}%
\spx@boxes@radius@topright \@nameuse{spx@\spx@noticetype @radius@topright}%
\spx@boxes@radius@bottomright \@nameuse{spx@\spx@noticetype @radius@bottomright}%
\spx@boxes@radius@bottomleft \@nameuse{spx@\spx@noticetype @radius@bottomleft}%
\relax
\iftrue\@nameuse{ifspx@\spx@noticetype @withshadow}%
\spx@boxes@withshadowtrue
\spx@boxes@shadow@xoffset \@nameuse{spx@\spx@noticetype @box@shadow@xoffset}%
\spx@boxes@shadow@yoffset \@nameuse{spx@\spx@noticetype @box@shadow@yoffset}\relax
\else
\spx@boxes@withshadowfalse
\fi\@nameuse{fi}%
\iftrue\@nameuse{ifspx@\spx@noticetype @insetshadow}%
\spx@boxes@insetshadowtrue
\else
\spx@boxes@insetshadowfalse
\fi\@nameuse{fi}%
\iftrue\@nameuse{ifspx@\spx@noticetype @withshadowcolor}%
\spx@boxes@withshadowcolortrue
\else
\spx@boxes@withshadowcolorfalse
\fi\@nameuse{fi}%
%
\spx@boxes@withshadowfalse
\spx@boxes@withshadowcolorfalse
\spx@boxes@withbackgroundcolortrue
\iftrue\@nameuse{ifspx@\spx@noticetype @withbackgroundcolor}%
\spx@boxes@withbackgroundcolortrue
\else
\spx@boxes@withbackgroundcolorfalse
\fi\@nameuse{fi}%
\sphinxcolorlet{spx@boxes@backgroundcolor}{spx@notice@bgcolor}%
\spx@boxes@withbordercolortrue
%
\iftrue\@nameuse{ifspx@\spx@noticetype @withbordercolor}%
\spx@boxes@withbordercolortrue
\else
\spx@boxes@withbordercolorfalse
\fi\@nameuse{fi}%
\sphinxcolorlet{spx@boxes@bordercolor}{spx@notice@bordercolor}%
}%
%
\iftrue\@nameuse{ifspx@\spx@noticetype @withshadowcolor}%
\spx@boxes@withshadowcolortrue
\else
\spx@boxes@withshadowcolorfalse
\fi\@nameuse{fi}%
\sphinxcolorlet{spx@boxes@shadowcolor}{sphinx\spx@noticetype ShadowColor}%
}
% Code adapted from framed.sty's "snugshade" environment.
% Nesting works (inner frames do not allow page breaks).
\newenvironment{sphinxheavybox}{\par
\setlength{\FrameRule}{\spx@notice@border}%
\setlength{\FrameSep}{\dimexpr.6\baselineskip-\FrameRule\relax}
\spx@admonitions@boxes@fcolorbox@setup
% Those are used by sphinxVerbatim if the \ifspx@inframed boolean is true
\setlength{\FrameRule}{0.5\dimexpr\spx@boxes@border@top+\spx@boxes@border@bottom\relax}%
% Prior to 5.1.0 \FrameSep served to configure the (unique) padding, via
% \fboxsep parameter of \fcolorbox; it was determined as 0.6\baselineskip -
% borderwidth, increasing borderwidth did not change text location
% vertically as borderwidth+padding remained constant. But this limited
% considerably (at most to 4pt or 5pt) the usual borderwidths.
% Now \FrameSep is not used, but is needed still by sphinxVerbatim (see
% prior comment above). We give it some reasonable definition.
\setlength{\FrameSep}{0.5\dimexpr\spx@boxes@padding@top+\spx@boxes@padding@bottom\relax}%
\advance\spx@image@maxheight
-\dimexpr2\FrameRule
+2\FrameSep
-\dimexpr\spx@boxes@border@top+\spx@boxes@border@bottom
+\spx@boxes@padding@top+\spx@boxes@padding@bottom
+\baselineskip\relax % will happen again if nested, needed indeed!
% MEMO: the next comment is before boxing was extended to allow padding and
% multiple border-widths, not to mention shadows...
% configure framed.sty's parameters to obtain same vertical spacing
% as for "light" boxes. We need for this to manually insert parskip glue and
% revert a skip done by framed before the frame.
\ltx@ifundefined{OuterFrameSep}{}{\OuterFrameSep\z@skip}%
\vspace{\FrameHeightAdjust}
% this will in particular set up colors, formerly passed as first
% two arguments of \fcolorbox
\let\spx@boxes@fcolorbox@init\spx@admonitions@boxes@fcolorbox@init
% copied/adapted from framed.sty's snugshade
% but now using in place of \fcolorbox the Sphinx sophisticated own
\def\FrameCommand##1{\hskip\@totalleftmargin
\spx@boxes@fcolorbox{##1}%
\ifspx@boxes@withshadow
\ifspx@boxes@insetshadow\else
\ifdim\spx@boxes@shadow@xoffset<\z@\hskip\spx@boxes@shadow@xoffset\relax
\fi
\fi
\fi
\if1% use rounded boxes only if needed and possible
\ifdim\spx@boxes@radius@topleft >\z@0\fi
\ifdim\spx@boxes@radius@topright >\z@0\fi
\ifdim\spx@boxes@radius@bottomright>\z@0\fi
\ifdim\spx@boxes@radius@bottomleft >\z@0\fi
1\spx@boxes@fcolorbox{##1}%
\else
\@ifpackageloaded{pict2e}%
{\ifspx@boxes@insetshadow
\spx@boxes@fcolorbox{##1}%
\else
\spx@boxes@fcolorbox@rounded{##1}%
\fi}%
{\spx@boxes@fcolorbox{##1}}%
\fi
\ifspx@boxes@withshadow
\ifspx@boxes@insetshadow\else
\ifdim\spx@boxes@shadow@xoffset>\z@\hskip-\spx@boxes@shadow@xoffset\relax
\fi
\fi
\fi
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\savenotes
% use a minipage if we are already inside a framed environment
Expand Down
21 changes: 9 additions & 12 deletions sphinx/texinputs/sphinxlatexliterals.sty
Expand Up @@ -219,24 +219,24 @@
}%
\def\sphinxVerbatim@FirstFrameCommand{%
\ifspx@pre@border@open
\let\spx@boxes@fcolorbox@init\spx@verb@boxes@fcolorbox@init@openbottom
\let\spx@boxes@fcolorbox@setuphook\spx@verb@boxes@fcolorbox@setuphook@openbottom
\fi
\spx@verb@FrameCommand\sphinxVerbatim@Before\sphinxVerbatim@Continues
}%
\def\sphinxVerbatim@MidFrameCommand{%
\ifspx@pre@border@open
\let\spx@boxes@fcolorbox@init\spx@verb@boxes@fcolorbox@init@openboth
\let\spx@boxes@fcolorbox@setuphook\spx@verb@boxes@fcolorbox@setuphook@openboth
\fi
\spx@verb@FrameCommand\sphinxVerbatim@Continued\sphinxVerbatim@Continues
}%
\def\sphinxVerbatim@LastFrameCommand{%
\ifspx@pre@border@open
\let\spx@boxes@fcolorbox@init\spx@verb@boxes@fcolorbox@init@opentop
\let\spx@boxes@fcolorbox@setuphook\spx@verb@boxes@fcolorbox@setuphook@opentop
\fi
\spx@verb@FrameCommand\sphinxVerbatim@Continued\sphinxVerbatim@After
}%
%
\def\spx@verb@boxes@fcolorbox@init{% for using \spx@boxes@fcolorbox
\def\spx@verb@boxes@fcolorbox@setup{%
%
\spx@boxes@border@top \spx@pre@border@top
\spx@boxes@border@right \spx@pre@border@right
Expand Down Expand Up @@ -279,20 +279,17 @@
\spx@boxes@withshadowcolorfalse\fi
\sphinxcolorlet{spx@boxes@shadowcolor}{sphinxVerbatimShadowColor}%
}%
\def\spx@verb@boxes@fcolorbox@init@openbottom{%
\spx@verb@boxes@fcolorbox@init
\def\spx@verb@boxes@fcolorbox@setuphook@openbottom{%
\spx@boxes@border@bottom \z@
\spx@boxes@radius@bottomright\z@
\spx@boxes@radius@bottomleft \z@
}%
\def\spx@verb@boxes@fcolorbox@init@opentop{%
\spx@verb@boxes@fcolorbox@init
\def\spx@verb@boxes@fcolorbox@setuphook@opentop{%
\spx@boxes@border@top \z@
\spx@boxes@radius@topright\z@
\spx@boxes@radius@topleft \z@
}%
\def\spx@verb@boxes@fcolorbox@init@openboth{%
\spx@verb@boxes@fcolorbox@init
\def\spx@verb@boxes@fcolorbox@setuphook@openboth{%
\spx@boxes@border@top \z@
\spx@boxes@border@bottom \z@
\spx@boxes@radius@topright\z@
Expand Down Expand Up @@ -785,8 +782,8 @@
\let\sphinxVerbatim@Continued\@empty
\let\sphinxVerbatim@Continues\@empty
\fi
% initialization for sphinxpackageboxes provided \spx@boxes@fcolorbox
\def\spx@boxes@fcolorbox@init{\spx@verb@boxes@fcolorbox@init}%
% initialization for \spx@boxes@fcolorbox from sphinxpackageboxes.sty
\spx@verb@boxes@fcolorbox@setup
\ifspx@opt@verbatimwrapslines
% deep hack into fancyvrb's internal processing of input lines
\let\FV@@PreProcessLine\spx@verb@@PreProcessLine
Expand Down

0 comments on commit 1341fb4

Please sign in to comment.