1*7f2fe78bSCy Schubert%% NOTICES AND ADMONITIONS 2*7f2fe78bSCy Schubert% 3*7f2fe78bSCy Schubert% change this info string if making any custom modification 4*7f2fe78bSCy Schubert\ProvidesFile{sphinxlatexadmonitions.sty}[2021/01/27 admonitions] 5*7f2fe78bSCy Schubert 6*7f2fe78bSCy Schubert% Provides support for this output mark-up from Sphinx latex writer: 7*7f2fe78bSCy Schubert% 8*7f2fe78bSCy Schubert% - sphinxadmonition (environment) 9*7f2fe78bSCy Schubert% This is a dispatch supporting 10*7f2fe78bSCy Schubert% 11*7f2fe78bSCy Schubert% - note, hint, important, tip (via sphinxlightbox) 12*7f2fe78bSCy Schubert% - warning, caution, attention, danger, error (via sphinxheavybox) 13*7f2fe78bSCy Schubert% 14*7f2fe78bSCy Schubert% Each sphinx<notice name> environment can be redefined by user. 15*7f2fe78bSCy Schubert% The defaults are customizable via various colour and dimension 16*7f2fe78bSCy Schubert% settings, cf sphinx docs (latex customization). 17*7f2fe78bSCy Schubert% 18*7f2fe78bSCy Schubert% Requires: 19*7f2fe78bSCy Schubert\RequirePackage{framed}% used by sphinxheavybox 20*7f2fe78bSCy Schubert% 21*7f2fe78bSCy Schubert% Dependencies (they do not need to be defined at time of loading): 22*7f2fe78bSCy Schubert% - of course the various colour and dimension options handled via sphinx.sty 23*7f2fe78bSCy Schubert% - \sphinxstrong (for sphinxlightbox and sphinxheavybox) 24*7f2fe78bSCy Schubert% - dimension register \spx@image@maxheight from sphinxlatexgraphics.sty 25*7f2fe78bSCy Schubert% - \savenotes/\spewnotes from sphinxpackagefootnote (for sphinxheavybox) 26*7f2fe78bSCy Schubert 27*7f2fe78bSCy Schubert% Provides: (also in sphinxlatexliterals.sty) 28*7f2fe78bSCy Schubert\providecommand*\sphinxvspacefixafterfrenchlists{% 29*7f2fe78bSCy Schubert \ifvmode\ifdim\lastskip<\z@ \vskip\parskip\fi\else\par\fi 30*7f2fe78bSCy Schubert} 31*7f2fe78bSCy Schubert 32*7f2fe78bSCy Schubert% Some are quite plain 33*7f2fe78bSCy Schubert% the spx@notice@bordercolor etc are set in the sphinxadmonition environment 34*7f2fe78bSCy Schubert\newenvironment{sphinxlightbox}{% 35*7f2fe78bSCy Schubert \par 36*7f2fe78bSCy Schubert \noindent{\color{spx@notice@bordercolor}% 37*7f2fe78bSCy Schubert \rule{\linewidth}{\spx@notice@border}}\par\nobreak 38*7f2fe78bSCy Schubert {\parskip\z@skip\noindent}% 39*7f2fe78bSCy Schubert } 40*7f2fe78bSCy Schubert {% 41*7f2fe78bSCy Schubert % counteract previous possible negative skip (French lists!): 42*7f2fe78bSCy Schubert % (we can't cancel that any earlier \vskip introduced a potential pagebreak) 43*7f2fe78bSCy Schubert \sphinxvspacefixafterfrenchlists 44*7f2fe78bSCy Schubert \nobreak\vbox{\noindent\kern\@totalleftmargin 45*7f2fe78bSCy Schubert {\color{spx@notice@bordercolor}% 46*7f2fe78bSCy Schubert \rule[\dimexpr.4\baselineskip-\spx@notice@border\relax] 47*7f2fe78bSCy Schubert {\linewidth}{\spx@notice@border}}\hss}\allowbreak 48*7f2fe78bSCy Schubert }% end of sphinxlightbox environment definition 49*7f2fe78bSCy Schubert% may be renewenvironment'd by user for complete customization 50*7f2fe78bSCy Schubert\newenvironment{sphinxnote}[1] 51*7f2fe78bSCy Schubert {\begin{sphinxlightbox}\sphinxstrong{#1} }{\end{sphinxlightbox}} 52*7f2fe78bSCy Schubert\newenvironment{sphinxhint}[1] 53*7f2fe78bSCy Schubert {\begin{sphinxlightbox}\sphinxstrong{#1} }{\end{sphinxlightbox}} 54*7f2fe78bSCy Schubert\newenvironment{sphinximportant}[1] 55*7f2fe78bSCy Schubert {\begin{sphinxlightbox}\sphinxstrong{#1} }{\end{sphinxlightbox}} 56*7f2fe78bSCy Schubert\newenvironment{sphinxtip}[1] 57*7f2fe78bSCy Schubert {\begin{sphinxlightbox}\sphinxstrong{#1} }{\end{sphinxlightbox}} 58*7f2fe78bSCy Schubert% or just use the package options 59*7f2fe78bSCy Schubert% these are needed for common handling by notice environment of lightbox 60*7f2fe78bSCy Schubert% and heavybox but they are currently not used by lightbox environment 61*7f2fe78bSCy Schubert% and there is consequently no corresponding package option 62*7f2fe78bSCy Schubert\definecolor{sphinxnoteBgColor}{rgb}{1,1,1} 63*7f2fe78bSCy Schubert\definecolor{sphinxhintBgColor}{rgb}{1,1,1} 64*7f2fe78bSCy Schubert\definecolor{sphinximportantBgColor}{rgb}{1,1,1} 65*7f2fe78bSCy Schubert\definecolor{sphinxtipBgColor}{rgb}{1,1,1} 66*7f2fe78bSCy Schubert 67*7f2fe78bSCy Schubert% Others get more distinction 68*7f2fe78bSCy Schubert% Code adapted from framed.sty's "snugshade" environment. 69*7f2fe78bSCy Schubert% Nesting works (inner frames do not allow page breaks). 70*7f2fe78bSCy Schubert\newenvironment{sphinxheavybox}{\par 71*7f2fe78bSCy Schubert \setlength{\FrameRule}{\spx@notice@border}% 72*7f2fe78bSCy Schubert \setlength{\FrameSep}{\dimexpr.6\baselineskip-\FrameRule\relax} 73*7f2fe78bSCy Schubert \advance\spx@image@maxheight 74*7f2fe78bSCy Schubert -\dimexpr2\FrameRule 75*7f2fe78bSCy Schubert +2\FrameSep 76*7f2fe78bSCy Schubert +\baselineskip\relax % will happen again if nested, needed indeed! 77*7f2fe78bSCy Schubert % configure framed.sty's parameters to obtain same vertical spacing 78*7f2fe78bSCy Schubert % as for "light" boxes. We need for this to manually insert parskip glue and 79*7f2fe78bSCy Schubert % revert a skip done by framed before the frame. 80*7f2fe78bSCy Schubert \ltx@ifundefined{OuterFrameSep}{}{\OuterFrameSep\z@skip}% 81*7f2fe78bSCy Schubert \vspace{\FrameHeightAdjust} 82*7f2fe78bSCy Schubert % copied/adapted from framed.sty's snugshade 83*7f2fe78bSCy Schubert \def\FrameCommand##1{\hskip\@totalleftmargin 84*7f2fe78bSCy Schubert \fboxsep\FrameSep \fboxrule\FrameRule 85*7f2fe78bSCy Schubert \fcolorbox{spx@notice@bordercolor}{spx@notice@bgcolor}{##1}% 86*7f2fe78bSCy Schubert \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}% 87*7f2fe78bSCy Schubert \savenotes 88*7f2fe78bSCy Schubert % use a minipage if we are already inside a framed environment 89*7f2fe78bSCy Schubert \ifspx@inframed 90*7f2fe78bSCy Schubert \noindent\begin{minipage}{\linewidth} 91*7f2fe78bSCy Schubert \else 92*7f2fe78bSCy Schubert % handle case where notice is first thing in a list item (or is quoted) 93*7f2fe78bSCy Schubert \if@inlabel 94*7f2fe78bSCy Schubert \noindent\par\vspace{-\baselineskip} 95*7f2fe78bSCy Schubert \else 96*7f2fe78bSCy Schubert \vspace{\parskip} 97*7f2fe78bSCy Schubert \fi 98*7f2fe78bSCy Schubert \fi 99*7f2fe78bSCy Schubert \MakeFramed {\spx@inframedtrue 100*7f2fe78bSCy Schubert \advance\hsize-\width \@totalleftmargin\z@ \linewidth\hsize 101*7f2fe78bSCy Schubert % minipage initialization copied from LaTeX source code. 102*7f2fe78bSCy Schubert \@pboxswfalse 103*7f2fe78bSCy Schubert \let\@listdepth\@mplistdepth \@mplistdepth\z@ 104*7f2fe78bSCy Schubert \@minipagerestore 105*7f2fe78bSCy Schubert \@setminipage }% 106*7f2fe78bSCy Schubert } 107*7f2fe78bSCy Schubert {% 108*7f2fe78bSCy Schubert \par\unskip 109*7f2fe78bSCy Schubert \@minipagefalse 110*7f2fe78bSCy Schubert \endMakeFramed 111*7f2fe78bSCy Schubert \ifspx@inframed\end{minipage}\fi 112*7f2fe78bSCy Schubert % set footnotes at bottom of page 113*7f2fe78bSCy Schubert \spewnotes 114*7f2fe78bSCy Schubert % arrange for similar spacing below frame as for "light" boxes. 115*7f2fe78bSCy Schubert \vskip .4\baselineskip 116*7f2fe78bSCy Schubert }% end of sphinxheavybox environment definition 117*7f2fe78bSCy Schubert% may be renewenvironment'd by user for complete customization 118*7f2fe78bSCy Schubert\newenvironment{sphinxwarning}[1] 119*7f2fe78bSCy Schubert {\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}} 120*7f2fe78bSCy Schubert\newenvironment{sphinxcaution}[1] 121*7f2fe78bSCy Schubert {\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}} 122*7f2fe78bSCy Schubert\newenvironment{sphinxattention}[1] 123*7f2fe78bSCy Schubert {\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}} 124*7f2fe78bSCy Schubert\newenvironment{sphinxdanger}[1] 125*7f2fe78bSCy Schubert {\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}} 126*7f2fe78bSCy Schubert\newenvironment{sphinxerror}[1] 127*7f2fe78bSCy Schubert {\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}} 128*7f2fe78bSCy Schubert% or just use package options 129*7f2fe78bSCy Schubert 130*7f2fe78bSCy Schubert% the \colorlet of xcolor (if at all loaded) is overkill for our use case 131*7f2fe78bSCy Schubert\newcommand{\sphinxcolorlet}[2] 132*7f2fe78bSCy Schubert {\expandafter\let\csname\@backslashchar color@#1\expandafter\endcsname 133*7f2fe78bSCy Schubert \csname\@backslashchar color@#2\endcsname } 134*7f2fe78bSCy Schubert 135*7f2fe78bSCy Schubert% the main dispatch for all types of notices 136*7f2fe78bSCy Schubert\newenvironment{sphinxadmonition}[2]{% #1=type, #2=heading 137*7f2fe78bSCy Schubert % can't use #1 directly in definition of end part 138*7f2fe78bSCy Schubert \def\spx@noticetype {#1}% 139*7f2fe78bSCy Schubert % set parameters of heavybox/lightbox 140*7f2fe78bSCy Schubert \sphinxcolorlet{spx@notice@bordercolor}{sphinx#1BorderColor}% 141*7f2fe78bSCy Schubert \sphinxcolorlet{spx@notice@bgcolor}{sphinx#1BgColor}% 142*7f2fe78bSCy Schubert \spx@notice@border \dimexpr\csname spx@opt@#1border\endcsname\relax 143*7f2fe78bSCy Schubert % start specific environment, passing the heading as argument 144*7f2fe78bSCy Schubert \begin{sphinx#1}{#2}} 145*7f2fe78bSCy Schubert % workaround some LaTeX "feature" of \end command 146*7f2fe78bSCy Schubert {\edef\spx@temp{\noexpand\end{sphinx\spx@noticetype}}\spx@temp} 147*7f2fe78bSCy Schubert 148*7f2fe78bSCy Schubert\endinput 149