%%% ====================================================================
%%% This style file redefines sectional headings to set them in the
%%% official Utah red color (default, but changeable by the user by,
%%% e.g.,
%%%     \definecolor{utahheadings} {rgb}  {0.0, 0.8, 0.0}
%%% AFTER loading this package
%%%
%%% [16-Mar-2016] -- require rgb package too for convenient X11-style
%%%                  color names
%%% [05-Jan-2016] -- version 1.00
%%% ====================================================================

\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{utahheadings}[2016/03/16 v1.01]

\immediate \write16 {===============================================================================}
\immediate \write16 {}
\immediate \write16 {This is utahheadings.sty version 1.01 <16 March 2016>}
\immediate \write16 {}
\immediate \write16 {WARNING: Color in theses is still experimental, and subject to approval by}
\immediate \write16 {the University of Utah Thesis Office!  One of their concerns is that color}
\immediate \write16 {pages printed on black-and-white printers should not have text disappear}
\immediate \write16 {because it is too light to see against a white paper background.}
\immediate \write16 {===============================================================================}

\RequirePackage{color}
\RequirePackage{rgb}

\definecolor{utahblue}     {rgb}  {0.0, 0.0, 0.8}
\definecolor{utahgreen}    {rgb}  {0.0, 0.6, 0.0}
\definecolor{utahred}      {rgb}  {0.8, 0.0, 0.0} % official definition for University of Utah Printing Services
\definecolor{utahheadings} {rgb}  {0.8, 0.0, 0.0} % official definition for University of Utah Printing Services

% \def \@seccntformat #1{\color{utahred}{\csname the#1\endcsname}\quad}
% \def \@seccntformat #1{XXX\csname the#1\endcsnameYYY\quad}

\def \mainheadingtext #1#2{% #1=text, #2=font size and style
  \begin{center}%
    \parbox{\mainheadingwidth}{%
     \begin{center}%
        #2%
        \color{utahheadings}{\uppercase{{\nohyphenation #1}}}%
      \end{center}%
      \removelastskip
    }% end parbox
   \end{center}%
}

\def \@Usect #1#2#3#4#5#6[#7]#8{%
\testsize{#8}{#6}\@testsizetrue
\ifnum #2>\c@secnumdepth\relax
     \def \@svsec{}\else
     \refstepcounter{#1}\edef\@svsec{\csname the#1\endcsname\hskip 1em }\fi
     \@tempskipa #5\relax
     \ifdim \@tempskipa>\z@
        \begingroup #6 \relax
          \@hangfrom{\hskip #3\relax \color{utahheadings}{\@svsec}}{\interlinepenalty \@M {\color{utahheadings}{#8}}\par}%
        \endgroup
        \csname #1mark\endcsname{#7}%
        \ifnum\c@tocdepth>\z@\relax
          \ifnum \c@section = 1 \addtocontents{toc}{\vspace{\uuthesis@chaptersectionspace}}\fi
          \addcontentsline{toc}{#1}%
           {\ifnum #2>\c@secnumdepth \else
            \protect\numberline{\csname the#1\endcsname}\fi #7}%
        \fi
     \else
        \def \@svsechd{#6\hskip #3\relax  %% \relax added 2 May 90
            \@svsec {\color{utahheadings}{#8}}\csname #1mark\endcsname {#7}%
            \ifnum\c@tocdepth>\z@\relax
               \ifnum \c@section = 1 \addtocontents{toc}{\vspace{\uuthesis@chaptersectionspace}}\fi
               \addcontentsline{toc}{#1}%
                {\ifnum #2>\c@secnumdepth \else
                 \protect\numberline{\csname the#1\endcsname}\fi #7}%
            \fi
        }
     \fi
     \@xsect{#5}%
   \typeout{DEBUG: ========================================================================}
   \typeout{DEBUG: @Usect: arg 1 = [#1]}
   \typeout{DEBUG: @Usect: arg 2 = [#2]}
%%:    \typeout{DEBUG: @Usect: arg 3 = [#3]}
%%:    \typeout{DEBUG: @Usect: arg 4 = [#4]}
%%:    \typeout{DEBUG: @Usect: arg 5 = [#5]}
%%:    \typeout{DEBUG: @Usect: arg 6 = [#6]}
   \typeout{DEBUG: @Usect: arg 7 = [#7]}
   \typeout{DEBUG: @Usect: arg 8 = [#8]}
}

\def \@Ussect #1#2#3#4#5{\testsize{#5}{#4}\@testsizetrue
\@tempskipa #3\relax
  \ifdim \@tempskipa>\z@
     \begingroup {\color{utahheadings}{#4}}%
     \@hangfrom{\hskip #1}{\interlinepenalty \@M%
     \nopagebreak[4]%
     {\color{utahheadings}{#5}}\par}%
     \endgroup
   \else \def \@svsechd{{\color{utahheadings}{#4}}\hskip #1\relax {\color{utahheadings}{#5}}}\fi
    \@xsect{#3}%
   \typeout{DEBUG: ------------------------------------------------------------------------}
   \typeout{DEBUG: @Ussect: arg 1 = [#1]}
   \typeout{DEBUG: @Ussect: arg 2 = [#2]}
   \typeout{DEBUG: @Ussect: arg 3 = [#3]}
   \typeout{DEBUG: @Ussect: arg 4 = [#4]}
   \typeout{DEBUG: @Ussect: arg 5 = [#5]}
}

\let \@oldbegintheorem = \@begintheorem
\def \@begintheorem #1#2{\@oldbegintheorem{\color{utahblue}{#1}}{\color{utahblue}{#2}}}

%%% Original definitions from uuthesis2e.cls
\def \fnum@figure {\bfseries Figure \thefigure}
\def \fnum@table  {\bfseries Table  \thetable}

%%% Modified definitions with colored text
\def \fnum@figure {\bfseries \color{utahgreen}{Figure \thefigure}}
\def \fnum@table  {\bfseries \color{utahgreen}{Table  \thetable}}
