| 1 |
\documentclass[a4paper,dvipdfmx,10pt,english]{article} |
| 2 |
\usepackage{babel} |
| 3 |
\usepackage[T1]{fontenc} |
| 4 |
\usepackage{geometry} |
| 5 |
\usepackage[straightquotes,ttzdefault]{newtxtt} |
| 6 |
\usepackage{framed} |
| 7 |
\usepackage[dvipsnames]{xcolor} |
| 8 |
\usepackage{colorframed} |
| 9 |
% we put this here but it does not have to be in preamble of |
| 10 |
% course |
| 11 |
% titled-frame |
| 12 |
\colorlet{TFFrameColor}{teal!20} |
| 13 |
\colorlet{TFTitleColor}{purple} |
| 14 |
\def\colorframedTFconlabcolorcommand{\color{purple}} |
| 15 |
% shaded |
| 16 |
%\colorlet{shadecolor}{orange!10} |
| 17 |
\colorlet{shadecolor}{lightgray!25} |
| 18 |
|
| 19 |
% framed |
| 20 |
\FrameRule5pt\relax |
| 21 |
\FrameSep9pt\relax % this is framed.sty default anyhow, 3\fboxsep |
| 22 |
% attention that \FrameSep influences framed but also shaded, shaded* and |
| 23 |
% oframed, which is not so clear from reading only framed documentation |
| 24 |
\def\colorframedbordercolorcommand{\color{red!20}} |
| 25 |
|
| 26 |
\title{The \colorframed package% |
| 27 |
\vadjust{\vtop to 0pt{\hbox |
| 28 |
to\linewidth{\strut\footnotesize Release 0.9b of |
| 29 |
2022/10/01\hss report issues at \url{https://github.com/jfbu/colorframed/issues}}\vss}}% |
| 30 |
} |
| 31 |
\author{Jean-François Burnol} |
| 32 |
\date{} |
| 33 |
\usepackage{shortvrb}\MakeShortVerb\| |
| 34 |
%\usepackage{url}\urlstyle{same} |
| 35 |
\usepackage{hyperref} |
| 36 |
\def\ctanpackage#1{\href{https://ctan.org/pkg/#1}{#1}} |
| 37 |
|
| 38 |
\usepackage{amssymb} |
| 39 |
|
| 40 |
\usepackage{parskip} |
| 41 |
\usepackage{xspace} |
| 42 |
\usepackage{metalogo} |
| 43 |
\setlogokern{La}{-0.258em} |
| 44 |
\setlogokern{aT}{-0.08em} |
| 45 |
\setlogokern{eL}{-0.1em} |
| 46 |
%\setlogokern{X2}{0em} |
| 47 |
\usepackage{enumitem} |
| 48 |
|
| 49 |
\definecolor{joli}{RGB}{225,95,0} |
| 50 |
\definecolor{JOLI}{RGB}{225,95,0} |
| 51 |
\newcommand\colorframed{% |
| 52 |
\texorpdfstring{{\color{joli}\bfseries colorframed}}{colorframed}\xspace} |
| 53 |
|
| 54 |
|
| 55 |
% ATTENTION: dvipdfmx syntax here! |
| 56 |
{\makeatletter |
| 57 |
\sbox0{\color{RawSienna}% |
| 58 |
\xdef\verbatimpushcolor{\special{color push \current@color}}}% |
| 59 |
} |
| 60 |
\def\verbatimpopcolor{\special{color pop}} |
| 61 |
\AddToHook{env/verbatim/before}{\verbatimpushcolor} |
| 62 |
\AddToHook{env/verbatim/end}{\verbatimpopcolor} |
| 63 |
|
| 64 |
\newcommand\ghissue[2][]{\href{https://github.com/jfbu/colorframed/issues/#2}{#1\##2}} |
| 65 |
|
| 66 |
\makeatletter |
| 67 |
%\show\verbatim@font % pas changé at begin doc |
| 68 |
\def\verbatim@font{\normalfont\ttfamily\color{RawSienna}}% |
| 69 |
\makeatother |
| 70 |
|
| 71 |
\begin{document} |
| 72 |
\maketitle |
| 73 |
|
| 74 |
\vskip-1.75\baselineskip |
| 75 |
|
| 76 |
{\footnotesize |
| 77 |
\halign{\tabskip1em\bfseries#\unskip&\hfil(#\unskip)\hfil&#\unskip\hfil\cr |
| 78 |
0.9 & 2022/09/22 & initial release\cr |
| 79 |
0.9a & 2022/09/23 & doc fixes, mention \ctanpackage{longfbox}\cr |
| 80 |
0.9b & 2022/10/01 & - fix "placement of titled-frame title |
| 81 |
is not backwards compatible" (\ghissue{2})\cr |
| 82 |
\omit&\omit& - |\colorframedTitleBarFrame| as workaround to upstream issues with titled-frame |
| 83 |
(\ghissue{3}, \ghissue{4})\cr |
| 84 |
\omit&\omit& - add link to \ghissue{5} for usage with list items, other doc improvements |
| 85 |
such as \ghissue{1}\cr |
| 86 |
}} |
| 87 |
|
| 88 |
\vskip-\baselineskip\vskip0pt\relax |
| 89 |
|
| 90 |
\section{Description} |
| 91 |
|
| 92 |
|
| 93 |
This package fixes various colour leaks one encounters with |
| 94 |
the environments from Donald Arseneau's package |
| 95 |
\ctanpackage{framed}. Typically, colour leaks occur if using |
| 96 |
|\color| (at top level or whose scope involves a page break) inside the |
| 97 |
environments, or more subtly also when using |\textcolor| with |
| 98 |
an argument ending up being split at a page break. |
| 99 |
|
| 100 |
This latter type of colour leak (or colour disappearance) is the |
| 101 |
more challenging one as the fix requires modifications or |
| 102 |
replacements not only of some of the \ctanpackage{framed}.sty |
| 103 |
macros (such as its |\CustomFBox|, which \colorframed overwrites) |
| 104 |
but also to some \LaTeX{} internals, as some environments of |
| 105 |
\ctanpackage{framed}.sty rely on usage of |\fbox| or |\colorbox|. |
| 106 |
Rather than overwriting internal \LaTeX{} macros such as |
| 107 |
|\@frameb@x| or |\color@b@x|, \colorframed simply replaces |\fbox| |
| 108 |
and |\colorbox| in the \ctanpackage{framed}.sty environments by |
| 109 |
appropriate substitutes. |
| 110 |
|
| 111 |
I am aware \ctanpackage{tcolorbox} package documentation explains at |
| 112 |
least one colour issue which looks similar to those fixed |
| 113 |
here in \ctanpackage{framed} context, and that the fix overthere uses |
| 114 |
an extra colour stack, hence is not \XeLaTeX{} compatible |
| 115 |
currently. |
| 116 |
|
| 117 |
The problems are solved here without involving an extra |
| 118 |
colour stack, hence the fixes work also with \XeLaTeX. |
| 119 |
|
| 120 |
\section{The environments from \ctanpackage{framed}} |
| 121 |
|
| 122 |
We refer the reader to \ctanpackage{framed} for the official |
| 123 |
documentation and provide here only a few relevant details, |
| 124 |
particularly |
| 125 |
regarding the `titled-frame' environment. |
| 126 |
\begin{titled-frame}{A list of the environments from package \ctanpackage{framed}} |
| 127 |
This list indicates which boxing macros are |
| 128 |
used in the original, and their replacement. |
| 129 |
% (investigate later why something such as shortverb |#| in |
| 130 |
% preamble does not work) |
| 131 |
\halign{\bfseries#\hfil&(#\unskip)~\hfil&#\hfil\cr |
| 132 |
% |
| 133 |
framed & |\fbox| & Replaced by specialization of own \rlap{\expandafter|\string\CustomFBox|.}\cr |
| 134 |
% |
| 135 |
oframed & |\CustomFBox| & \colorframed uses a redefined |\CustomFBox|.\cr |
| 136 |
% |
| 137 |
titled-frame & |\CustomFBox| & \emph{id.}\cr |
| 138 |
% |
| 139 |
shaded & |\colorbox| & Replaced by |\colorframedcolorbox|.\cr |
| 140 |
% |
| 141 |
shaded* & |\colorbox| & \emph{id.}\cr |
| 142 |
% |
| 143 |
snugshade & |\colorbox| & \emph{id.}\cr |
| 144 |
% |
| 145 |
snugshade* & |\colorbox| & \emph{id.}\cr |
| 146 |
% |
| 147 |
leftbar & none & This one does not use any boxing macro.\cr |
| 148 |
} |
| 149 |
\end{titled-frame} |
| 150 |
The previous box gives an example of use of `titled-frame' environment. |
| 151 |
It is an environment with |
| 152 |
one mandatory argument which provides the title of the |
| 153 |
frame, which is repeated after a page break with |(cont)| |
| 154 |
appended. The colours |TFFrameColor| and |
| 155 |
|TFTitleColor| must have been defined by the user. |
| 156 |
\colorframed adds the possibility to colorize separately the continuation |
| 157 |
label. For example we used |
| 158 |
\begin{verbatim} |
| 159 |
\renewcommand\colorframedTFconlabcolorcommand{\color{purple}} |
| 160 |
\end{verbatim} |
| 161 |
and the default definition of this macro is to do nothing (and then the |
| 162 |
symbol obeys the |TFFrameColor|). |
| 163 |
|
| 164 |
\medskip |
| 165 |
% check why topsep influences separation of item 1 and 2 |
| 166 |
% it shouldn't? hmm... ah yes I think framed itself uses \topsep... |
| 167 |
%\begin{enumerate}[noitemsep,topsep=6pt,font=\normalcolor] |
| 168 |
% j'utilise enumitem+noitemsep sinon je vois dans la partie ombrée |
| 169 |
% de l'espace supplémentaire au début de l'item (peut-être aussi |
| 170 |
% lié à l'emploi du package parskip) |
| 171 |
% \colorlet{shadecolor}{lightgray!25} |
| 172 |
|
| 173 |
\begin{footnotesize} |
| 174 |
\begin{itemize}[noitemsep,topsep=3pt,% influences strangely item separation |
| 175 |
parsep=3pt] |
| 176 |
\begin{shaded} |
| 177 |
\item |
| 178 |
\emph{The current box is an example of \emph{`shaded'} |
| 179 |
environment; The |
| 180 |
|shadecolor| must have been defined by user. See the |
| 181 |
\ghissue[repository issue ]{5} for some comments about how to use |
| 182 |
such environment with list items, if the environment is to start |
| 183 |
at start of the item, as here. } |
| 184 |
\end{shaded} |
| 185 |
|
| 186 |
\begin{snugshade} |
| 187 |
\item \emph{This is an example of \emph{`snugshade'} |
| 188 |
environment. It shares with \emph{`shaded'} the usage of |shadecolor|.} |
| 189 |
\end{snugshade} |
| 190 |
|
| 191 |
\begin{snugshade*} |
| 192 |
\item \emph{This is an example of \emph{`snugshade*'}.} |
| 193 |
\end{snugshade*} |
| 194 |
|
| 195 |
\begin{snugshade} |
| 196 |
\item |
| 197 |
% |
| 198 |
The `titled-frame' environment was in effect broken in recent \LaTeX\ which |
| 199 |
has modified how |\smash| behaves (the continuation label created a blank |
| 200 |
line interrupting the framing); \colorframed fixes this infelicity in |
| 201 |
passing. |
| 202 |
|
| 203 |
To customize |
| 204 |
further usage of `titled-frame' one must renew its definition, |
| 205 |
which is left untouched by \colorframed. |
| 206 |
Here is its source from \ctanpackage{framed}.sty: (code and |
| 207 |
comments by Donald Arseneau)% |
| 208 |
\begin{verbatim} |
| 209 |
% A particular type of titled frame with continuation marks. |
| 210 |
% Parameter #1 is the title, repeated on each page. |
| 211 |
\newenvironment{titled-frame}[1]{% |
| 212 |
\def\FrameCommand{\fboxsep8pt\fboxrule2pt |
| 213 |
\TitleBarFrame{\textbf{#1}}}% |
| 214 |
\def\FirstFrameCommand{\fboxsep8pt\fboxrule2pt |
| 215 |
\TitleBarFrame[$\blacktriangleright$]{\textbf{#1}}}% |
| 216 |
\def\MidFrameCommand{\fboxsep8pt\fboxrule2pt |
| 217 |
\TitleBarFrame[$\blacktriangleright$]{\textbf{#1\ (cont)}}}% |
| 218 |
\def\LastFrameCommand{\fboxsep8pt\fboxrule2pt |
| 219 |
\TitleBarFrame{\textbf{#1\ (cont)}}}% |
| 220 |
\MakeFramed{\advance\hsize-20pt \FrameRestore}}% |
| 221 |
% note: 8 + 2 + 8 + 2 = 20. Don't use \width because the frame title |
| 222 |
% could interfere with the width measurement. |
| 223 |
{\endMakeFramed} |
| 224 |
\end{verbatim} |
| 225 |
The continuation label used in the `titled-frame' environment |
| 226 |
is |$\blacktriangleright$| |
| 227 |
(which despite its name reacts to current text colour setting). |
| 228 |
It requires to |
| 229 |
the best of the author knowledge loading \ctanpackage{amssymb} or |
| 230 |
some other math symbols package and it is up to user to do it. |
| 231 |
\end{snugshade} |
| 232 |
|
| 233 |
% \begin{shaded} % nesting does not work |
| 234 |
\begin{framed} |
| 235 |
\item |
| 236 |
\emph{(one can not nest environments of \ctanpackage{framed}.sty, else we would |
| 237 |
have done so here.)} |
| 238 |
|
| 239 |
\textcolor{blue}{(Here is an attempt to use the {`framed'} environment |
| 240 |
around a list item; we can see an unexpected |
| 241 |
induced indentation of the |
| 242 |
paragraph. And, by the way, there is no {`snugframe'} environment which would |
| 243 |
let the border fit not the whole width but only the indented item.)} |
| 244 |
\end{framed} |
| 245 |
% \end{shaded} % nesting does not work |
| 246 |
|
| 247 |
\begin{snugshade} |
| 248 |
\item To customize the `titled-frame' output, one may simply redefine the |
| 249 |
environment via suitable changes e.g. to the setting of |\fboxsep| and |
| 250 |
|\fboxrule|. But doing so, one quickly discovers that the layout from |
| 251 |
|\TitleBarFrame| has problems (see on this the repository issues \ghissue{3} |
| 252 |
and \ghissue{4}). So \colorframed |0.9b| provides |
| 253 |
|\colorframedTitleBarFrame|, which can be used as a replacement to |
| 254 |
|\TitleBarFrame| in a redefined custom `titled-framed' environment. Check |
| 255 |
the source code for comments. This alternative |
| 256 |
obeys added customizing |
| 257 |
macros whose defaults are shown here: |
| 258 |
\begin{verbatim} |
| 259 |
% (such \fboxsep should be set by environment itself, like titled-frame does) |
| 260 |
\def\colorframedTFtitlesep{\fboxsep}% hor. distance of title from left border |
| 261 |
\def\colorframedTFconlabsep{3pt}% hor. distance of continuation label from border |
| 262 |
\end{verbatim} |
| 263 |
This variant handles differently than its model the horizontal and vertical |
| 264 |
placement of the title. It is provided as an exception |
| 265 |
to the general rule that this package should take care only of fixing colour |
| 266 |
problems (addition of \emph{new} environments may be considered in future, |
| 267 |
but fixing existing environments will not be done beyond what is described here). |
| 268 |
|
| 269 |
\end{snugshade} |
| 270 |
\end{itemize} |
| 271 |
As was already |
| 272 |
mentioned `titled-frame' had been broken some years ago by an |
| 273 |
upstream \LaTeX\ change and we did not change it beyond |
| 274 |
fixing this problem. The alternative |\colorframedTitleBarFrame| must be |
| 275 |
opted-for explicitly by user in a re-definition of `titled-frame' |
| 276 |
environment, the default remaining with the problematic |
| 277 |
|\TitleBarFrame|. Or the user can do |
| 278 |
|\let\TitleBarFrame\colorframedTitleBarFrame| |
| 279 |
and use `titled-frame', not a new environment. |
| 280 |
\par |
| 281 |
\end{footnotesize} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
% The aim of \colorframed regarding \ctanpackage{framed} existing |
| 286 |
% code base is strictly limited to fixing the colour leak issues, |
| 287 |
% there is no general intent to modify the existing environments of |
| 288 |
% \ctanpackage{framed} for them to acquire additional capabilities and |
| 289 |
% customizability. |
| 290 |
|
| 291 |
Already we have mentioned |
| 292 |
\begin{verbatim} |
| 293 |
\colorframedTFconlabcolorcommand |
| 294 |
\end{verbatim} |
| 295 |
whose default definition let it expands to nothing at all (the continuation label |
| 296 |
then inherits the |TFFrameColor| colour). |
| 297 |
|
| 298 |
Regarding the `framed' environment, \colorframed adds the |
| 299 |
\begin{verbatim} |
| 300 |
\colorframedbordercolorcommand |
| 301 |
\end{verbatim} |
| 302 |
which expands by default to |\normalcolor|. It influences the colour of the |
| 303 |
framing done by environment `framed', the original having no such |
| 304 |
customizability. Do not redefine it to do nothing, it always should set some |
| 305 |
colour, else the borders may display colour loss after a page break. |
| 306 |
|
| 307 |
For example |
| 308 |
\begin{verbatim} |
| 309 |
\setlength{\FrameRule}{5pt} |
| 310 |
\setlength{\FrameSep}{9pt} |
| 311 |
\renewcommand\colorframedbordercolorcommand{\color{gray!50}} |
| 312 |
\end{verbatim} |
| 313 |
configures the next usage of `framed'. |
| 314 |
|
| 315 |
\setlength{\FrameRule}{5pt} |
| 316 |
\setlength{\FrameSep}{9pt} |
| 317 |
\renewcommand\colorframedbordercolorcommand{\color{gray!50}} |
| 318 |
\begin{framed} |
| 319 |
This environment allows indeed customization of the border width |
| 320 |
and of the separation with contents, via |\FrameRule| and |
| 321 |
|\FrameSep|. |
| 322 |
|
| 323 |
The length |\FrameSep| influences also `oframed', `shaded', and `shaded*', |
| 324 |
but `snugshade' and `snugshade*' employ |\fboxsep| rather. |
| 325 |
|
| 326 |
|\FrameRule| influences both `framed' and `oframed'. |
| 327 |
\end{framed} |
| 328 |
|
| 329 |
\section{Technicalities, musings about future} |
| 330 |
|
| 331 |
\begin{snugshade} |
| 332 |
I first developed the analysis of the colour leaks/losses at page breaks with |
| 333 |
\ctanpackage{framed} on occasion of some contributions I made to |
| 334 |
the \href{https://github.com/sphinx-doc/sphinx}{Sphinx project} and I am |
| 335 |
transferring here the gained knowledge. |
| 336 |
|
| 337 |
The key thing is that the boxes handled by \ctanpackage{framed}.sty may |
| 338 |
contain isolated colour push or colour pop. We must make |
| 339 |
sure an isolated colour push, if followed by colour changes, |
| 340 |
is always followed by paired ones, and never by a colour pop |
| 341 |
from a colour command originated "prior" and symmetrically that a sole |
| 342 |
colour pop does not follow a yet unpaired colour push from some other |
| 343 |
colour command related to the framing. |
| 344 |
|
| 345 |
This means we can not ever use things such as |\fbox|, |\colorbox| or |
| 346 |
|\fcolorbox| (whether or not \ctanpackage{xcolor} is loaded) as they will |
| 347 |
cause colour pops after a possibly isolated colour push contained in the |
| 348 |
(already boxed) contents which are fetched to them as arguments by |
| 349 |
\ctanpackage{framed}.sty internals. We must re-implement them otherwise. |
| 350 |
This is what is done here, without touching the \LaTeX\ internal macros |
| 351 |
themselves. |
| 352 |
|
| 353 |
Some portion of the macro file is occupied with the |
| 354 |
`titled-frame' environment of \ctanpackage{framed}.sty, which was broken by an |
| 355 |
upstream LaTeX change related to |\smash|, and has obvious problems |
| 356 |
apart from that. |
| 357 |
Further "obvious problems" do exist for the other \ctanpackage{framed}.sty |
| 358 |
environments but it is not the matter of this package to fix them. |
| 359 |
Perhaps in future another package will be provided based upon the |
| 360 |
work here and adding a completely new environment fixing the "obvious |
| 361 |
problems" (some of them being simply lack of customizability). |
| 362 |
|
| 363 |
The author has developed based upon usage of \ctanpackage{pict2e} |
| 364 |
breakable boxes with round corners, background colour, optional |
| 365 |
shadow (possibly inset), and other goodies and was planning on |
| 366 |
incorporating this environment into the package at some time in future. |
| 367 |
|
| 368 |
% Hopefully this addition will be done when time will permit. |
| 369 |
|
| 370 |
% \thispagestyle{empty} |
| 371 |
% \enlargethispage{2\baselineskip} |
| 372 |
|
| 373 |
%\colorlet{shadecolor}{lightgray!50} |
| 374 |
% \footnotesize |
| 375 |
But after initial release made it to CTAN on |
| 376 |
2022/09/22 I became aware of \ctanpackage{longfbox} which |
| 377 |
provides already such \ctanpackage{pict2e} breakable boxes with |
| 378 |
rounded corners (even elliptical arcs), and furthermore with a |
| 379 |
CSS-like interface which is exactly what I had done on my side |
| 380 |
too... I need to check more \ctanpackage{longfbox} before a |
| 381 |
decision is made here! Perhaps it will be better to keep |
| 382 |
\colorframed as it is currently and |
| 383 |
extras such as new \ctanpackage{pict2e}-based boxes with a key-value |
| 384 |
interface to `inline' or `display' boxing macros and environments |
| 385 |
should make it to another package (loading \colorframed of course). |
| 386 |
|
| 387 |
Of course, such a package would remain limited in its graphics abilities |
| 388 |
(and customizability) in comparison to the customizable boxing environments |
| 389 |
provided by package \ctanpackage{mdframed} or \ctanpackage{tcolorbox} but |
| 390 |
testing with my own \ctanpackage{pict2e}-based boxes showed significant |
| 391 |
speed-up in build time compared to using \ctanpackage{framed}+|\tcbox| or |
| 392 |
the "breakable" option of \ctanpackage{tcolorbox}. |
| 393 |
|
| 394 |
\end{snugshade} |
| 395 |
\centerline{\hrulefill documentation ends here\hrulefill} |
| 396 |
\end{document} |