| 1 |
% Copyright 2018 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesPackage{xxcolor}[2003/10/24 ver 0.1] |
| 11 |
\NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 12 |
|
| 13 |
\RequirePackage{xcolor} |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
% Command \newcolormixin{\somecommand} |
| 18 |
% |
| 19 |
% Description: |
| 20 |
% |
| 21 |
% After this command has been called, you can assign a partial color |
| 22 |
% specification to \somecommand. Every time a color is set, the |
| 23 |
% partial color specification in \somecommand will be applied to the |
| 24 |
% current color. |
| 25 |
% |
| 26 |
% Examples: |
| 27 |
% |
| 28 |
% \newcolormixin\mymixin |
| 29 |
% \def\mymixin{!50!white} |
| 30 |
% |
| 31 |
% \newcolormixin\anothermixin |
| 32 |
% \def\anothermixin{!50!red} |
| 33 |
|
| 34 |
\def\newcolormixin#1{% |
| 35 |
\expandafter\def\csname XC@mixin@\the\XC@nummixins\endcsname{#1}% |
| 36 |
\advance\XC@nummixins\@ne% |
| 37 |
\ifx#1\@undefined\def#1{}\fi} |
| 38 |
|
| 39 |
\newcount\XC@nummixins |
| 40 |
\newcount\XC@countmixins |
| 41 |
|
| 42 |
|
| 43 |
% Command \applycolormixins{colorname} |
| 44 |
% |
| 45 |
% Description: |
| 46 |
% |
| 47 |
% Applies all color mixins that have been defined using \newcolormixin |
| 48 |
% to the color named colorname. |
| 49 |
% |
| 50 |
% Examples: |
| 51 |
% |
| 52 |
% \applycolormixins{mycolor} |
| 53 |
|
| 54 |
\def\applycolormixins#1{% |
| 55 |
\XC@countmixins=0\relax% |
| 56 |
\loop% |
| 57 |
\ifnum\XC@countmixins<\XC@nummixins% |
| 58 |
\colorlet{#1}{#1\csname XC@mixin@\the\XC@countmixins\endcsname}% |
| 59 |
\advance\XC@countmixins\@ne\relax% |
| 60 |
\repeat% |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
% Internal: |
| 65 |
|
| 66 |
\ifx\XC@mcolor\relax |
| 67 |
\let\XC@mcolor\@empty |
| 68 |
\fi |
| 69 |
|
| 70 |
\g@addto@macro\XC@mcolor{% |
| 71 |
\ifnum\XC@nummixins>0% |
| 72 |
\colorlet{XC@mixtmp}{.}% |
| 73 |
\applycolormixins{XC@mixtmp}% |
| 74 |
\pgfutil@namelet{current@color}{\string\color@XC@mixtmp}% |
| 75 |
\fi% |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
% Environment colormixin |
| 81 |
% |
| 82 |
% #1 = full xcolor specification after the first ! ("white" may not be |
| 83 |
% omitted) |
| 84 |
% |
| 85 |
% Description: |
| 86 |
% |
| 87 |
% Inside the environment, all colors get the specified mixin. May be |
| 88 |
% nested. |
| 89 |
% |
| 90 |
% Examples: |
| 91 |
% |
| 92 |
% \color{red}This is red. |
| 93 |
% \begin{colormixin}{25!black} |
| 94 |
% This is dark red. |
| 95 |
% \color{blue} |
| 96 |
% This is dark blue. |
| 97 |
% \end{colormixin} |
| 98 |
% This is normal red once more. |
| 99 |
|
| 100 |
\newcolormixin\colorcurrentmixin |
| 101 |
|
| 102 |
\newenvironment{colormixin}[1]% |
| 103 |
{\edef\colorcurrentmixin{!#1\colorcurrentmixin}\color{.}}{} |
| 104 |
|
| 105 |
\def\pgfalternateextension{\colorcurrentmixin} |
| 106 |
|
| 107 |
\endinput |
| 108 |
|