summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/xxcolor.sty
blob: 9a4bb4e5b69a7d47c5132899adc30f0ea2cb9704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
% Copyright 2018 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesPackage{xxcolor}[2003/10/24 ver 0.1]
\NeedsTeXFormat{LaTeX2e}[1995/12/01]

\RequirePackage{xcolor}



% Command \newcolormixin{\somecommand}
%
% Description:
%
% After this command has been called, you can assign a partial color
% specification to \somecommand. Every time a color is set, the
% partial color specification in \somecommand will be applied to the
% current color.
%
% Examples:
%
% \newcolormixin\mymixin
% \def\mymixin{!50!white}
%
% \newcolormixin\anothermixin
% \def\anothermixin{!50!red}

\def\newcolormixin#1{%
  \expandafter\def\csname XC@mixin@\the\XC@nummixins\endcsname{#1}%
  \advance\XC@nummixins\@ne%
  \ifx#1\@undefined\def#1{}\fi}

\newcount\XC@nummixins
\newcount\XC@countmixins


% Command \applycolormixins{colorname}
%
% Description:
%
% Applies all color mixins that have been defined using \newcolormixin
% to the color named colorname.
%
% Examples:
%
% \applycolormixins{mycolor}

\def\applycolormixins#1{%
  \XC@countmixins=0\relax%
  \loop%
  \ifnum\XC@countmixins<\XC@nummixins%
    \colorlet{#1}{#1\csname XC@mixin@\the\XC@countmixins\endcsname}%
    \advance\XC@countmixins\@ne\relax%
  \repeat%
}


% Internal:

\ifx\XC@mcolor\relax
  \let\XC@mcolor\@empty
\fi
  
\g@addto@macro\XC@mcolor{%
  \ifnum\XC@nummixins>0%
    \colorlet{XC@mixtmp}{.}%
    \applycolormixins{XC@mixtmp}%
    \pgfutil@namelet{current@color}{\string\color@XC@mixtmp}%
  \fi%
}



% Environment colormixin
%  
% #1 = full xcolor specification after the first ! ("white" may not be
%      omitted)
%
% Description:
%
% Inside the environment, all colors get the specified mixin. May be
% nested. 
%
% Examples:
%
% \color{red}This is red.
% \begin{colormixin}{25!black}
%   This is dark red. 
%   \color{blue}
%   This is dark blue.
% \end{colormixin}
% This is normal red once more.

\newcolormixin\colorcurrentmixin

\newenvironment{colormixin}[1]%
{\edef\colorcurrentmixin{!#1\colorcurrentmixin}\color{.}}{}

\def\pgfalternateextension{\colorcurrentmixin}

\endinput