summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/colorframed/colorframed.sty
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/colorframed/colorframed.sty')
-rw-r--r--macros/latex/contrib/colorframed/colorframed.sty156
1 files changed, 156 insertions, 0 deletions
diff --git a/macros/latex/contrib/colorframed/colorframed.sty b/macros/latex/contrib/colorframed/colorframed.sty
new file mode 100644
index 0000000000..db6a5d5e2f
--- /dev/null
+++ b/macros/latex/contrib/colorframed/colorframed.sty
@@ -0,0 +1,156 @@
+% colorframed.sty v0.9 2022/09/22
+% Copyright (c) 2022 Jean-François Burnol
+% Distributed under the terms of the LPPL 1.3c, see README.md
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{colorframed}
+ [2022/09/22 v0.9 fix `framed' breakable boxes colour leaks (JFB)]
+\RequirePackage{framed}
+\RequirePackage{color}
+% First we must make \MakeFramed/\endMakeFramed colour safe.
+\expandafter\def\expandafter\MakeFramed\expandafter#\expandafter1\expandafter
+ {\MakeFramed{#1}\color@begingroup}
+\expandafter\def\expandafter\endMakeFramed\expandafter
+ {\expandafter\color@endgroup\endMakeFramed}
+%
+% `framed'
+\def\FrameCommand{%
+ \setlength\fboxrule{\FrameRule}\setlength\fboxsep{\FrameSep}%
+ \CustomFBox{}{}\fboxrule\fboxrule\fboxrule\fboxrule % replaces \fbox
+}
+% The frame colour can be set via modifying this macro.
+\def\colorframedbordercolorcommand{\normalcolor}
+%
+% `shaded', `shaded*', `snugshade', `snugshade*'
+% The \colorbox in \FrameCommand is replaced by \colorframedcolorbox
+\renewenvironment{shaded}{%
+ \def\FrameCommand{\fboxsep=\FrameSep
+ \colorframedcolorbox{shadecolor}}%<<<< MODIFIED
+ \MakeFramed {\FrameRestore}}%
+ {\endMakeFramed}
+\renewenvironment{shaded*}{%
+ \def\FrameCommand{\fboxsep=\FrameSep
+ \colorframedcolorbox{shadecolor}}%<<<< MODIFIED
+ \MakeFramed {\advance\hsize-\width \FrameRestore}}%
+ {\endMakeFramed}
+\renewenvironment{snugshade}{%
+ \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
+ \colorframedcolorbox{shadecolor}{##1}%<<<< MODIFIED
+ \hskip-\fboxsep
+ % There is no \@totalrightmargin, so:
+ \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
+ \MakeFramed {\advance\hsize-\width
+ \@totalleftmargin\z@ \linewidth\hsize
+ \@setminipage}%
+ }{\par\unskip\@minipagefalse\endMakeFramed}
+\renewenvironment{snugshade*}{%
+ \def\FrameCommand##1{\hskip\@totalleftmargin
+ \colorframedcolorbox{shadecolor}{##1}%<<<< MODIFIED
+ % There is no \@totalrightmargin, so:
+ \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
+ \MakeFramed {\advance\hsize-\width
+ \@totalleftmargin\z@ \linewidth\hsize
+ \advance\labelsep\fboxsep
+ \@setminipage}%
+ }{\par\unskip\@minipagefalse\endMakeFramed}
+% The \colorframedcolorbox was obtained via a process of trimming from some
+% far more capable box, hence some possibly strange looking or sub-optimal
+% code; but we did not want to keep extra capabilities and have to provide
+% interface for that...
+\def\colorframedcolorbox#1#2{%
+ % #1 is in our usage always "shadecolor" (which has to be defined by user)
+ % #2 is in our usage always a box or rule
+ \leavevmode% this is not needed in our usage
+ \hbox{%
+ \setbox\@tempboxa\hbox{\kern\fboxsep{#2}\kern\fboxsep}%
+ \ht\@tempboxa
+ \dimexpr\ht\@tempboxa+\fboxsep\relax
+ \dp\@tempboxa
+ \dimexpr\dp\@tempboxa+\fboxsep\relax
+ % BACKGROUND
+ % draw background and move back to reference point
+ {\color{#1}%
+ \vrule\@height\ht\@tempboxa
+ \@depth\dp\@tempboxa
+ \@width\wd\@tempboxa
+ \kern-\wd\@tempboxa
+ }%
+ % CONTENTS
+ \box\@tempboxa
+ }%
+}
+%
+% `oframed' and `titled-frame'
+% The \CustomFBox redefinition.
+% Refer to framed.sty for significance of the parameters.
+% We have not wrapped #3, #4, #5, #6 thicknesses in \dimexpr.
+% Generally speaking, no attempt here to make this macro more
+% versatile than is the original.
+% Our version tries to let #1 and #2 have same effect as in original
+% (where they are only used for titled-frame environment, and
+% it thus seems to be sort of a convention that #2 has no height.)
+\long\def\CustomFBox#1#2#3#4#5#6#7{%
+ \leavevmode\begingroup
+ \setbox\@tempboxa\hbox{%
+ \color@begingroup
+ \kern\fboxsep{#7}\kern\fboxsep
+ \color@endgroup}%
+ \hbox{%
+ \ht\@tempboxa
+ \dimexpr\ht\@tempboxa+\fboxsep+#3\relax % cf "overlap" remark below
+ \dp\@tempboxa
+ \dimexpr\dp\@tempboxa+\fboxsep+#4\relax
+ \setbox\z@\hbox
+ {\vrule\@width#5\relax
+ \kern\wd\@tempboxa
+ \vrule\@width#6\relax
+ }%
+ \ht\z@\ht\@tempboxa
+ \dp\z@\dp\@tempboxa
+ \vbox{%
+ \colorframedbordercolorcommand % defaults to \normalcolor
+ \hrule\@height#3\relax
+ \kern-#3\relax
+ #1%
+ \copy\z@ % deliberate overlap hrules+vrules to avoid anti-aliasing artefacts
+ \kern-#4\relax
+ #2%
+ \hrule\@height#4\relax
+ \kern-\dp\@tempboxa
+ }%
+ \kern-\wd\z@
+ \kern#5\relax
+ \box\@tempboxa
+ \kern#6\relax
+ }%
+ \endgroup
+}
+% The titled-frame environment depends in part on this macro,
+% whose original in framed.sty has various colour problems.
+% We have indicated the modifications, additionally to using
+% our modified \CustomFBox.
+% Original let the continuation label use same colour as frame.
+% Let make this customizable.
+\let\colorframedTFconlabcolorcommand\empty
+\renewcommand\TitleBarFrame[3][]{\begingroup
+ \ifx\delimiter#1\delimiter
+ \let\TF@conlab\@empty
+ \else
+ \def\TF@conlab{%
+ \nointerlineskip
+ \hbox{%<<<< ADDED (needed due to \smash doing \leavevmode nowadays)
+ \colorframedTFconlabcolorcommand%<<<< ADDED
+ \smash{\rlap{\kern\wd\@tempboxa\kern\fboxrule\kern\fboxsep #1}}}%
+ }%<<<< ADDED
+ \fi
+ %\let\TF@savecolor\current@color%<<<< REMOVED
+ %\textcolor{TFFrameColor}{% <<<< REMOVED
+ \def\colorframedbordercolorcommand{\color{TFFrameColor}}%<<<< ADDED
+ \CustomFBox
+ {\TF@Title{#2}}{\TF@conlab}%
+ \fboxrule\fboxrule\fboxrule\fboxrule
+ {%\let\current@color\TF@savecolor\set@color%<<<< REMOVED
+ #3}%
+ %}% <<<< REMOVED
+ \endgroup
+}
+\endinput