r3tex

custom LuaTeX format
git clone git://git.rr3.xyz/r3tex
Log | Files | Refs | README | LICENSE

color.tex (1786B)


      1 % TODO: tmp; use attributes instead
      2 
      3 % Convert 4 digit hex number #2#3#4#5 to decimal in range [0,1) and store
      4 % it in #1.
      5 \def\@hextodec#1#2#3#4#5{%
      6 	\dimenA="#2#3#4#5sp
      7 	\edef#1{\decimal\dimenA}%
      8 }
      9 
     10 % if (\pdfoutput undefined) OR (\pdfoutput <= 0)
     11 \if1\ifx\pdfoutput\@undefined 1\else\ifnum\pdfoutput>0 0\else 1\fi\fi
     12 	% dvips
     13 	\def\@colorpush#1{\special{color push #1}}
     14 	\def\@colorpop{\special{color pop}}
     15 	\def\@colorset#1{\@colorpush{#1}\aftergroup\@colorpop}
     16 	\def\Colorrgb#1#2#3{\@colorset{rgb #1 #2 #3}}
     17 	\def\Colorgrey#1{\@colorset{gray #1}}
     18 \else
     19 	% pdfTeX
     20 	% TODO: make this an event
     21 	\everyjob={%
     22 		\pdfpageresources{/ExtGState <<
     23 			/R3texGsAlpha0 << /ca 0 /CA 0 >>
     24 			/R3texGsAlpha1 << /ca 1 /CA 1 >>
     25 		>>}%
     26 		\mathchardef\@colorstackn=\pdfcolorstackinit page {%
     27 			0 g 0 G /R3texGsAlpha1 gs
     28 		}%
     29 	}%
     30 	\def\@colorpush#1{\pdfcolorstack\@colorstackn push {#1}}
     31 	\def\@colorpop{\pdfcolorstack\@colorstackn pop}
     32 	\def\@colorset#1{\@colorpush{#1}\aftergroup\@colorpop}
     33 	\def\Colorrgb#1#2#3{\@colorset{#1 #2 #3 rg #1 #2 #3 RG}}
     34 	\def\Colorgrey#1{\@colorset{#1 g #1 G}}
     35 	\def\Cinvis{\@colorset{/R3texGsAlpha0 gs}}
     36 \fi
     37 
     38 % Basic colors
     39 \def\Cblack{\Colorgrey{0}}
     40 \def\Cwhite{\Colorgrey{1}}
     41 \def\Cred{\Colorrgb    {1}{0}{0}}
     42 \def\Cgreen{\Colorrgb  {0}{1}{0}}
     43 \def\Cblue{\Colorrgb   {0}{0}{1}}
     44 \def\Ccyan{\Colorrgb   {0}{1}{1}}
     45 \def\Cmagenta{\Colorrgb{1}{0}{1}}
     46 \def\Cyellow{\Colorrgb {1}{1}{0}}
     47 
     48 % Arbitrary HTML-style hex colors
     49 \def\Chex"#1#2#3#4#5#6{%
     50 	\beggroup
     51 	\@hextodec\csA#1#2#1#2% red
     52 	\@hextodec\csB#3#4#3#4% green
     53 	\@hextodec\csC#5#6#5#6% blue
     54 	\edef\@{\endgroup\noexpand\Colorrgb{\csA}{\csB}{\csC}}%
     55 	\@\ignorespaces
     56 }
     57 
     58 % 16 shades of grey
     59 \def\Cgrey"#1{%
     60 	\beggroup
     61 	\@hextodec\csA#1#1#1#1%
     62 	\edef\@{\endgroup\noexpand\Colorgrey{\csA}}%
     63 	\@\ignorespaces
     64 }
     65 
     66 \endinput