% eclcolor.sty by Hideki Isozaki (isozaki@ntt-20.ntt.jp)
%                 Kazuhiro Kazama (kazama@expert-sun.ntt.jp)
%                 Yaski Saito (yaski@ntt-20.ntt.jp)
% February 25, 1992
\typeout{color macro package for dvi2ps-j. 
version 1.5 - Released July 1, 1992}

\def\prgb#1{\aftergroup\set@color\edef\curr@color{RGB=#1}\set@color}
\def\pcmyk#1{\aftergroup\set@color\edef\curr@color{CMYK=#1}\set@color}
\def\phsb#1{\aftergroup\set@color\edef\curr@color{HSB=#1}\set@color}

\def\rgb{\protect\prgb}
\def\cmyk{\protect\pcmyk}
\def\hsb{\protect\phsb}

% color definitions
% CMYK (cyan-magenta-yellow-black)
\def\cyan{\cmyk{1 0 0 0}}
\def\lightcyan{\cmyk{0.5 0 0 0}}
\def\pastelcyan{\cmyk{0.25 0 0 0}}
\def\magenta{\cmyk{0 1 0 0}}
\def\yellow{\cmyk{0 0 1 0}}
\def\lightyellow{\cmyk{0 0 0.5 0}}
\def\pastelyellow{\cmyk{0 0 0.25 0}}
\def\black{\cmyk{0 0 0 1}}
\def\darkgray{\cmyk{0 0 0 0.75}}
\def\gray{\cmyk{0 0 0 0.5}}
\def\lightgray{\cmyk{0 0 0 0.25}}
\def\white{\cmyk{0 0 0 0}}
\def\red{\cmyk{0 1 1 0}}
\def\orange{\cmyk{0 0.5 1 0}}
\def\scarlet{\cmyk{0 1 0.5 0}}
\def\brown{\cmyk{0.5 0.75 1 0}}
\def\camel{\cmyk{0.25 0.375 0.5 0}}
\def\cream{\cmyk{0 0.2 0.3 0}}
\def\green{\cmyk{1 0 1 0}}
\def\lightgreen{\cmyk{0.5 0 0.5 0}}
\def\pastelgreen{\cmyk{0.25 0 0.25 0}}
\def\mossgreen{\cmyk{0.64 0.4 1 0}}
\def\yellowgreen{\cmyk{0.5 0 1 0}}
\def\skyblue{\cmyk{0.4 0.16 0 0}}
\def\nttblue{\cmyk{0.91 0.44 0 0}}
\def\navyblue{\cmyk{0.9 0.75 0.5 0}}
\def\blue{\cmyk{1 1 0 0}}
\def\lightblue{\cmyk{0.5 0.5 0 0}}
\def\lavender{\cmyk{0.25 0.25 0 0}}
\def\violet{\cmyk{0.75 1 0.25 0}}
\def\purple{\cmyk{0.5 1 0.5 0}}
\def\pink{\cmyk{0 0.5 0 0}}
\def\pastelpink{\cmyk{0 0.25 0 0}}

% \colorbox{fgcolor}{bgcolor} <- \makebox

\newdimen\colorboxsep
\colorboxsep=2pt

\def\colorbox#1#2{\def\fg@color{#1}\def\bg@color{#2}%
\@ifnextchar({\@colorpicbox}{\@ifnextchar[{\@colorbox}{\fl@box}}}

\def\@colorbox[#1]{\leavevmode
	\@ifnextchar [{\@icolorbox[#1]}{\@icolorbox[#1][x]}}

\long\def\@icolorbox[#1][#2]#3{%
   \setbox\@tempboxa\hbox{#3}\edef\bg@dpa{\the\dp\@tempboxa}%
   \setbox\@tempboxa\hbox{\vbox
   {\vskip\colorboxsep\hbox to#1{\hskip\colorboxsep\let\mb@l\hss \let\mb@r\hss 
   \expandafter\let\csname mb@#2\endcsname\relax
   \mb@l\@nameuse{\fg@color}#3\mb@r\hskip\colorboxsep}\vskip\colorboxsep}}%
   \@tempdima=\colorboxsep \advance\@tempdima \bg@dpa
   \edef\bg@dp{\the\@tempdima}%
   \edef\bg@wd{\the\wd\@tempboxa}%
   \edef\bg@ht{\the\ht\@tempboxa}%
   \hbox{\smash{\rlap{\@nameuse{\bg@color}\rule
   [-\bg@dp]{\bg@wd}{\bg@ht}}}\lower\bg@dp\box\@tempboxa}}

\def\@colorpicbox(#1,#2){\leavevmode\@ifnextchar 
   [{\@icolorpicbox(#1,#2)}{\@icolorpicbox(#1,#2)[]}}

\long\def\@icolorpicbox(#1,#2)[#3]#4{%
   \let\mb@l\hss \let\mb@r\hss \let\mb@t\vss \let\mb@b\vss 
   \@tfor\mb@mk:=#3\do{\expandafter\let\csname mb@\mb@mk\endcsname\relax}%
   \setbox\@tempboxa\hbox{\vbox to #2\unitlength
	{\mb@t\hbox to #1\unitlength
		{\mb@l\@nameuse{\fg@color}#4\mb@r}\mb@b}}%
   \edef\bg@dp{\the\dp\@tempboxa}%
   \hbox{\smash{\rlap{\@nameuse{\bg@color}\rule
   {#1\unitlength}{#2\unitlength}}}\raise \bg@dp\hbox{\box\@tempboxa}}}

\long\def\fl@box#1{\leavevmode
   \setbox\@tempboxa\hbox{#1}\edef\bg@dpa{\the\dp\@tempboxa}%
   \setbox\@tempboxa
   \hbox{\vbox{\vskip\colorboxsep\hbox{\hskip\colorboxsep
	\@nameuse{\fg@color}#1\hskip\colorboxsep}\vskip\colorboxsep}}%
   \@tempdima=\colorboxsep \advance\@tempdima \bg@dpa
   \edef\bg@dp{\the\@tempdima}\edef\bg@wd{\the\wd\@tempboxa}%
   \edef\bg@ht{\the\ht\@tempboxa}%
   \hbox{\smash{\rlap{\@nameuse{\bg@color}\rule
   [-\bg@dp]{\bg@wd}{\bg@ht}}}\lower\bg@dp\hbox{\box\@tempboxa}}}


\def\@outputpage{\begingroup\catcode`\ =10 
     \let\-\@dischyph \let\'\@acci \let\`\@accii \let\=\@acciii
    \if@specialpage 
     \global\@specialpagefalse\@nameuse{ps@\@specialstyle}\fi
     \if@twoside 
       \ifodd\count\z@ 
		\let\@thehead\@oddhead \let\@thefoot\@oddfoot
            		\let\@themargin\oddsidemargin
          \else 
		\let\@thehead\@evenhead \let\@thefoot\@evenfoot 
			\let\@themargin\evensidemargin
     \fi\fi
     \shipout
     \vbox{\normalsize \baselineskip\z@ \lineskip\z@ 
           \let\par\@@par %% 15 Sep 87
           \vskip \topmargin \moveright\@themargin
           \vbox{\setbox\@tempboxa
                   \vbox to\headheight{\vfil \hbox to\textwidth
                                       {\let\label\@gobble \let\index\@gobble
                                         \@thehead}} %% 22 Feb 87
                 \dp\@tempboxa\z@
                 \box\@tempboxa
                 \vskip \headsep
		 \edef\curr@color{\prev@color}\special{\curr@color}%
		 \xdef\prev@color{\expandafter\@colormark\botmark}%
                 \box\@outputbox
                 \baselineskip\footskip
                 \hbox to\textwidth{\let\label\@gobble 
                           \let\index\@gobble  %% 22 Feb 87
                           \@thefoot}}}\global\@colht\textheight
           \endgroup\stepcounter{page}\let\firstmark\botmark}

\def\markboth#1#2{%
     {\let\protect\noexpand
      \let\label\relax \let\index\relax 
      \expandafter\@markboth\@themark{#1}{#2}%
      \mk@wcl}%
     \if@nobreak\ifvmode\nobreak\fi\fi}

\def\markright#1{%
     {\let\protect\noexpand
      \let\label\relax \let\index\relax 
      \expandafter\@markright\@themark{#1}%
      \mk@wcl}%
     \if@nobreak\ifvmode\nobreak\fi\fi}

\def\set@color{%
     {\let\protect\noexpand
      \let\label\relax \let\index\relax 
      \expandafter\@markcolor\@themark{\curr@color}%
      \mk@wcl}%
     \special{\curr@color}}

\def\mk@wcl{\let\mk@wcl=\relax \mark{\@themark}}

\def\@markboth#1#2#3#4#5{\gdef\@themark{{#4}{#5}{#3}}}
\def\@markright#1#2#3#4{\gdef\@themark{{#1}{#4}{#3}}}
\def\@markcolor#1#2#3#4{\gdef\@themark{{#1}{#2}{#4}}}
\def\@leftmark#1#2#3{#1}
\def\@rightmark#1#2#3{#2}
\def\@colormark#1#2#3{#3}

\newdimen\color@ratio
{\catcode`\p=12\catcode`\t=12\gdef\remove@dim#1pt{#1}}
% (1-#1)*(#2,#3,#4) + #1*(#5,#6,#7)
%   = (#2,#3,#4) + #1*(#5-#2,#6-#3,#7-#4)
\def\cmymix#1(#2 #3 #4)(#5 #6 #7){%
	\color@ratio=#5pt \advance\color@ratio by -#2pt
	\color@ratio=#1\color@ratio
	\advance\color@ratio by #2pt
	\edef\color@mix{\expandafter\remove@dim\the\color@ratio}%
	\color@ratio=#6pt \advance\color@ratio by -#3pt
	\color@ratio=#1\color@ratio
	\advance\color@ratio by #3pt
	\edef\color@mix{\color@mix\space
		\expandafter\remove@dim\the\color@ratio}%
	\color@ratio=#7pt \advance\color@ratio by -#4pt
	\color@ratio=#1\color@ratio
	\advance\color@ratio by #4pt
	\edef\color@mix{\color@mix\space
		\expandafter\remove@dim\the\color@ratio\space0}%
	\cmyk{\color@mix}}

%

\def\prev@color{CMYK=0 0 0 1}
\def\curr@color{CMYK=0 0 0 1}
\def\@themark{{}{}{\curr@color}}
\mark{\@themark}

\def\leftmark{\expandafter\@leftmark\botmark{}}
\def\rightmark{\expandafter\@rightmark\firstmark{}}
