-
Notifications
You must be signed in to change notification settings - Fork 26
/
xcolor-quick-variants.tex
58 lines (52 loc) · 1.53 KB
/
xcolor-quick-variants.tex
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
\RequirePackage{xcolor}
\makeatletter
% Quick \definecolor
% c.f. last lines of \XC@definec@lor
%
% Example:
% \defineqcolor{mycolor}{rgb}{0.5,0,0.3}
%
% #1 = color name
% #2 = color model, one of rgb, cmy, cmyk, and gray
% #3 = color spec, a comma-separated list of numbers in range [0, 1] without extra spaces
\protected\def\defineqcolor#1#2#3{%
\@nameuse{color@#2}\@@drv{#3}%
\ifglobalcolors\global\else\xglobal@\fi
\expandafter\edef\csname\@backslashchar color@#1\endcsname
{\noexpand\xcolor@{}\expandafter{\@@drv}{\detokenize{#2}}{#3}}%
}
% optional further optimization
% \c@lor@arg in \color@<model> checks if its #1 is in range [0, 1]
% \let\c@lor@arg=\@gobble
% Quick \colorlet
\protected\def\qcolorlet#1#2{%
\ifglobalcolors\global\else\xglobal@\fi
\XC@let@cc{\XC@nametocs{#1}}{\XC@nametocs{#2}}%
}
% Quick \color
% c.f. \@declaredcolor
%
% Example:
% \qcolor{mycolor}
% \qcolor[rgb]{.5,0,.3}
%
\protected\def\qcolor{\@ifnextchar[{\@undeclaredqcolor}{\@declaredqcolor}}
\protected\def\@undeclaredqcolor[#1]#2{%
\@nameuse{color@#1}\current@color{#2}%
\edef\XC@current@color{\noexpand\xcolor@{}{\current@color}{#1}{#2}}%
\XC@display
}
\protected\def\@declaredqcolor#1{%
\XC@edef\XC@@tmp{#1}\XC@declaredc@lor
}
% optional further optimization
% use \edef instead of \XC@edef
% \protected\def\@declaredqcolor#1{\edef\XC@@tmp{#1}\XC@declaredc@lor}
% helper
% #1 = color name
\ifdefined\XC@nametocs
\PackageError{xcolorq}{\string\XC@nametocs already exists}{}
\else
\def\XC@nametocs#1{\@backslashchar color@#1}
\fi
\makeatother