% Style file for lecture notes, exams, graded homework
% Written: Sept. 1, 1998
% Last modified: January 22, 2001 [Ver. 1.44]
% Last modified: August 25, 1999 [Ver. 1.43]
% Author: Chris Taylor taylor@msoe.edu
\newif\ifpdf
\ifx\pdfoutput\undefined
  \pdffalse
\else
  \pdfoutput=1
  \pdftrue
\fi
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ctdefs}
\RequirePackage{listings}
\ifpdf
  \RequirePackage[pdftex]{graphicx}
  \RequirePackage[pdftex]{color}
%  \RequirePackage[pdftex,pdfpagemode=None]{hyperref}
  \RequirePackage[pdftex,bookmarksopen=true]{hyperref}
\else
  \RequirePackage{graphicx}
  \RequirePackage{color}
  \RequirePackage{hyperref}
\fi
\RequirePackage{fancyhdr}
\RequirePackage{times}  % NEW as of 1-22-2001
\DeclareOption{landscape}
   {\setlength{\textheight}{6.5in}%
    \setlength{\textwidth}{9in}%
    \setlength{\hoffset}{-2.5in}%
    \setlength{\topmargin}{-0.5in}%
    \def\cctland{true}}
\DeclareOption{notes}
   {\setlength{\parindent}{0pt}%
    \setlength{\parskip}{1.5em}%
    \setlength{\hoffset}{-2.0in}%
    \chead{\Acrobatmenu{FullScreen}{\MSOEs}} \cfoot{\CCTc}%
    \def\cctnotes{true}}
\DeclareOption{hw}
   {\chead{\Acrobatmenu{FullScreen}{\MSOEs}} \rfoot{\thepage/\pageref{EndDoc}}%
    \def\ccthw{true}}
%\DeclareOption{hd}
%   {\setlength{\textheight}{13in}%
%    \setlength{\textwidth}{10in}%
%    \setlength{\topmargin}{-3.5in}%
%    \setlength{\hoffset}{-1.0in}%
%    \setlength{\parindent}{0pt}%
%    \setlength{\parskip}{1.5em}%
%    \chead{\MSOEs} \cfoot{\CCTc}%
%    \def\cctnotes{true}}
\ProcessOptions

%Centered section headings
\def\csection{\@startsection {section}{1}{\z@}{-3.5ex plus -1ex minus 
    -.2ex}{2.3ex plus .2ex}{\centering\Large\bf}}
\def\csubsection{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus 
   -.2ex}{1.5ex plus .2ex}{\centering\large\bf}}
\def\csubsubsection{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus
-1ex minus -.2ex}{1.5ex plus .2ex}{\centering\normalsize\bf}}

% Custom initials
%\def\CCT{C \hspace{-1.1em} \raisebox{-.33ex}C \hspace{-1.1em} 
%           \raisebox{-.66ex}{T}}
\def\CCT{C \hspace{-0.9em} \raisebox{-.33ex}C \hspace{-0.9em} 
           \raisebox{-.66ex}{T}} % Revised 1-23-2001 for times package
\def\CCTay{C \hspace{-0.9em} \raisebox{-.33ex}C 
           \hspace{-0.9em} \raisebox{-.66ex}{T{\tiny \hspace{-.2em}AYLOR}}}
\def\CCTc{\copyright{} 2001 by C \hspace{-0.9em} \raisebox{-.33ex}C 
           \hspace{-0.9em} \raisebox{-.66ex}{T{\tiny \hspace{-.2em}AYLOR}}}
\def\MSOE{\framebox[1.8em]{\textcolor{red}{\bf 
           \raisebox{.75ex}[1.9ex][.2ex]{M\hspace{-.1em}S}\hspace{-1.66em}
           \raisebox{-.75ex}[.0ex][.0ex]{\hspace{-.05ex}O\hspace{-.2ex}E}}}}
%\def\MSOEs{\framebox[1.8em]{\textcolor{red}{\bf \hspace{-1.0em}
%           \raisebox{.75ex}[1.9ex][.2ex]{M\hspace{-.1em}S}\hspace{-1.66em}
%           \raisebox{-.75ex}[.0ex][.0ex]{\hspace{-.05ex}O\hspace{-.2ex}E}
%   \raisebox{.3ex}{\tiny \hspace{-7.6ex}..}\raisebox{-0.5ex}{\tiny \hspace{-2.6ex}$\smile$}}}}
\def\MSOEs{\framebox[1.8em]{\textcolor{red}{\bf \hspace{-1.0em}
           \raisebox{.75ex}[1.9ex][.2ex]{M\hspace{-.1em}S}\hspace{-1.61em}
           %\raisebox{.75ex}[1.9ex][.2ex]{M\hspace{-.1em}S}\hspace{-1.66em}
           \raisebox{-.75ex}[.0ex][.0ex]{\hspace{-.05ex}O\hspace{-.2ex}E}
   \raisebox{.3ex}{\tiny \hspace{-5.8ex}..}\raisebox{-0.5ex}{\tiny \hspace{-2.1ex}$\smile$}}}} % Revised 1-23-2001 for times package
\def\C{$\circ$}
\def\D{$\cdot$}
\def\B{$\bullet$}

% Degree and C++ symbols
\def\DEGREE{$^\circ$}
%\def\DEGREE{\raisebox{1.2ex}{\tiny o}}
\def\Cpp{{\rm C\kern-.05em\raise.3ex\hbox{\footnotesize ++}}}

\newenvironment{setindent}[1]
{
  \begin{list}{}{\leftmargin#1 \topsep0in \partopsep0in \parskip0in}
  \item[]
}{
  \end{list}
}
% Example of setindent:
% \begin{setindent}{1em}
%    ... text ...
% \end{setindent}

\newenvironment{setmargin}[2]
{
  \begin{list}{}{\leftmargin#1\rightmargin#2\topsep0in\partopsep0in\parskip0in}
  \item[]
}{
  \end{list}
}
% Example of setmargin:
% \begin{setmargin}{leftmargin}{rightmargin}
%    ... text ...
% \end{setmargin}

\def\h{\hspace*{1.2em}}   % \h = Space left by 1.2 times the width of an M
\def\v{\vspace*{1.2ex}}   % \v = Space down by 1.2 times the height of an x
\def\vneg{\vspace*{-1ex}} % \vneg = Space up by the height of an x
\def\vss{\vspace*{1ex}}   % \vss = Space down by the height of an x
\def\vin{\vspace*{1in}}   % \vin = Space down by one inch
\def\vnone{\relax}

\def\ctbox{\rule{.5ex}{.5ex}}        % Create a small box

% Create empty boxes
\def\boxin#1{\fbox{\rule{0in}{#1}{}\rule{#1}{0in}{}}}
\def\Boxin#1#2{\fbox{\rule{0in}{#2}{}\rule{#1}{0in}{}}}

% Create empty axes
\def\Axs{\begin{picture}(150,150)(-10,-10)
         \put(0,0){\vector(1,0){120}}
         \put(0,0){\vector(0,1){120}}
         \put(-5,120){\makebox(0,0){$y$}}
         \put(120,-5){\makebox(0,0){$x$}}
         \end{picture}
        }
\def\Axes3{\begin{picture}(170,170)(-60,-60)
          \put(0,0){\vector(1,0){90}}
          \put(0,0){\vector(0,1){90}}
          \put(0,0){\vector(-1,-1){45}}
          \put(-5,90){\makebox(0,0){$y$}}
          \put(90,-5){\makebox(0,0){$x$}}
          \put(-38,-40){\makebox(0,0){$z$}}
          \end{picture}
          }
\def\axes3{\begin{picture}(80,80)(-30,-30)
          \put(0,0){\vector(1,0){34}}
          \put(0,0){\vector(0,1){34}}
          \put(0,0){\vector(-1,-1){17}}
          \put(-5,34){\makebox(0,0){$y$}}
          \put(34,-5){\makebox(0,0){$x$}}
          \put(-13,-15){\makebox(0,0){$z$}}
          \end{picture}
          }

% Create an environment called "blist" for bullet listings
% Same as itemize, but items are closer together.
\newenvironment{blist}
{
  \begin{setindent}{0pt}
  \begin{itemize} \squashitems
}{
  \end{itemize}
  \end{setindent}
}
% Example of blist
% \begin{blist}
%    \item blah
%    \item blah
% \end{blist}

\newenvironment{ctabstract}
{
  \centerline{\small \bf Abstract}
  \begin{setmargin}{3em}{3em}
}{
  \end{setmargin}
}

\def\mc#1#2#3{\multicolumn{#1}{#2}{#3}}
\def\squashitems{\itemsep 0pt \parskip 0pt}
\def\closeitems{\itemsep 2pt \parskip 2pt}

\@ifundefined{cctland}%
  {\def\ctsec{\@startsection{section}{1}{\z@}{-3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}{\centering\Large\bf\color{slate}}}%
   \def\ctssec{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}{\centering\large\bf\color{slate}}}%
   \def\ctsssec{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}{\centering\normalsize\bf\color{slate}}}}
  {\def\ctsec{\@startsection{section}{1}{\z@}{-3.5ex plus -1ex minus -.2ex}{2.3ex plus .2ex}{\centering\Huge\bf\color{slate}}}%
   \def\ctssec{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}{\centering\LARGE\bf\color{slate}}}%
   \def\ctsssec{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus -1ex minus -.2ex}{1.5ex plus .2ex}{\centering\Large\bf\color{slate}}}}

%\def\line#1{\rule{#1}{.01in}}
\def\blackbox#1{\rule{#1}{#1}}

\def\floor#1{\lfloor #1 \rfloor}
\def\ceil#1{\lceil #1 \rceil}
\def\lgfloor#1{\floor{\log_{2} #1}}
\def\lgceil#1{\ceil{\log_{2} #1}}
\def\lgg#1{\log_{2} #1}
\def\qeq{\stackrel{?}{=}}
\def\xor{\raisebox{.20ex}{$\,\hat{}\:$}}
\def\toinfty{\rightarrow\infty}

%% if ansFlag = 1 show the answer
%\newcount\ansFlag \ansFlag=0
%% if probFlag = 1 show the problem
%% \newcount\probFlag \probFlag=1   

%%\newcount\ctFlag
%%\def\setCT#1{\ctFlag=#1}
%%\long\def\ifCTFlag <<#1>><<#2>>{\ifnum \ctFlag=0 #1 \else #2 \fi}
%\long\def\ans <<#1>>{\ifnum \ansFlag>0 \@ansString #1 \fi}
%\long\def\noans <<#1>>{\ifnum \ansFlag=0 \@ansString #1 \fi}
%\long\def\noAns <<#1>>{\ifnum \ansFlag=0 #1 \fi}
%\long\def\ifAns <<#1>><<#2>>{\ifnum \ansFlag=0 #1 \else #2 \fi}
%\long\def\probAns#1#2<<#3>>{\ifnum \probFlag=1 \problem{#1} #2 \fi
%  \ifnum \ansFlag=1 \ifnum \probFlag=0\problem{#1} \fi \@ansString #3 \fi}
%\long\def\selShow#1#2{\ifnum #1=1 #2 \fi}    %% sel show #2 based on #1

\def\useProbAns{SEE CTDEFS.STY useProbAns macro \ugh \ansFlag=1 \def\prob{\probAns}}

\newif\ifques
\newif\ifans
\def\showAns{\anstrue}
\def\hideAns{\ansfalse}
\def\showProb{\questrue}
\def\hideProb{\quesfalse}
\def\onlyprob{\questrue\ansfalse}
\def\onlyans{\quesfalse\anstrue}

\def\problem#1{\par\vspace{1.2ex}{\bf #1)}}

\newcount\problemi \newcount\problemii \newcount\problemiii
\def\shownonzero#1#2{\ifnum#1=0\else\number#1#2\fi}
\def\ctproblem#1{\par\vspace{1.2ex} \advance\problemiii by 1
 {\bf \shownonzero{\problemi}{-}\shownonzero{\problemii}{.}\number\problemiii#1)}}
\def\prob{\ctproblem}

\long\def\swallow#1{}

\long\def\setAnsString#1{\def\@ansString{#1}}
\def\normAnsString{\setAnsString{\par{\bf \ \ Answer: }}}
\setAnsString{}
\def\ansString{\@ansString}
\def\qtoa{\fi \ifans}
\long\def\ansnostr <<#1>>{\ifans #1 \fi}
\long\def\ans <<#1>>{\ifans \@ansString #1 \fi}
\long\def\noans <<#1>>{\ifques #1 \fi}
\long\def\noAns <<#1>>{\ifques #1 \fi}
\long\def\ifAns{\quesans}
\long\def\quesans <<#1>><<#2>>{\ifques #1\else\@ansString #2\fi}
\long\def\quesansnostr <<#1>><<#2>>{\ifques #1\else #2 \fi}
\long\def\probAns#1#2<<#3>>{SEE CTDEFS.STY old $\backslash$probAns macro}



%
% Typesetting Commands
%
\newenvironment{command}%
    {\nopagebreak\par\small\addvspace{3.2ex plus 0.8ex minus 0.2ex}%
     \vskip -\parskip
     \noindent%
     \begin{tabular}{|l|}\hline\rule{0pt}{1em}\ignorespaces}%
    {\\\hline\end{tabular}\par\nopagebreak\addvspace{3.2ex plus 0.8ex
        minus 0.2ex}%
     \vskip -\parskip}
%
% Intro Environment
\newenvironment{intro}{\sffamily}{\vspace*{2ex minus 1.5ex}}

%
% Print |--| to show a distance
%
\newcommand{\demowidth}[1]{\rule{0.3pt}{1.3ex}\rule{#1}{0.3pt}\rule{0.3pt}{1.3ex}}

% Example
%\newenvironment{example}[2]%
% {\begin{center}\begin{minipage}{#1}\hrule\medskip%
% {\large{\textsc{Example:} \textsf{#2}}} \medskip\hrlemedskip}
% {\medskip\hrule \end{minipage}\end{center}}
\def\cctge{\noindent\textcolor{slate}{\hspace{\stretch{1}}\B \h %
                  \raisebox{.25em}{\rule{3in}{0.3pt}}%
                  \h \B \hspace{\stretch{1}}} \medskip}
%\def\ccteg#1{\cctge \medskip%
%              \begin{center}\vspace{-2em}%
%              {\Large{\textsc{Example:} \textcolor{slate}{\textsf{#1}}}}%
%              \medskip \end{center}\vspace{-2em}%
%              \cctge}
\def\ccteg#1{\noindent\textcolor{slate}{\hspace{\stretch{1}}\B \h %
             \raisebox{.25em}{\rule{1.5in}{0.3pt}}%
             \fbox{\Large{\textsc{Example:} \textsf{#1}}}%
             \raisebox{.25em}{\rule{1.5in}{0.3pt}} \h \B} \hspace{\stretch{1}}}

% Answer definition
\def\ANS{\v\v \textcolor{red}{\bf Answer:}}

% Redefine some colors:
\definecolor{grn}{rgb}{0,.5,0}
\definecolor{BGred}{rgb}{1,.9,.9}
\definecolor{GCred}{rgb}{1,.5,.5}
\definecolor{slate}{rgb}{0,.4,.8}
\definecolor{purp}{rgb}{.4,0,.6}
\definecolor{deflt}{rgb}{0,0,0}
\definecolor{ttclr}{rgb}{0,.4,.8}

% Coloring of specialized text
\def\emphc#1{\emph{\textcolor{purp}{#1}}}
\def\textbfc#1{\textbf{\textcolor{purp}{#1}}}
\def\textbfs#1{\textbf{\textcolor{slate}{#1}}}
\def\textttc#1{\texttt{\textcolor{ttclr}{#1}}}
\def\keyc#1{\texttt{\textcolor{blue}{#1}}}
\def\codec#1{\textsf{\textcolor{black}{#1}}}

% Grading definitions
\newlength{\xout}
\newdimen\GComwd
\setlength{\GComwd}{\textwidth}
\addtolength{\GComwd}{-2in}
\newenvironment{GCom}%
 {\color{red} \begin{center}\begin{tabular}{|p{\GComwd}|}\hline \sf}
 {\\ \hline \end{tabular}\end{center}}
\ifpdf
\newcommand{\Gout}[2]{\settowidth{\xout}{#1} \Gcom{#1\hspace{-\xout}\rule[.3em]{\xout}{.05em} #2}}
\newcommand{\Gcom}[1]{\fcolorbox{black}{GCred}{\sf #1}}
\newcommand{\Gmin}[1]{\noindent\vspace{-2ex}\hspace{\textwidth}
                      \fcolorbox{black}{GCred}{\large\sf -#1}}
\newcommand{\Gbon}[1]{\noindent\vspace{-2ex}\hspace{\textwidth}
                      \fcolorbox{black}{green}{\large\sf +#1}}
\newcommand{\Gfin}[2]{\noindent\hspace{\textwidth}\fcolorbox{black}{GCred}
                     {\large\sf Grade: #1/#2 \label{EndDoc}}}
\else
\newcommand{\Gout}[2]{\settowidth{\xout}{#1} \Gcom{#1\hspace{-\xout}\rule[.3em]{\xout}{.05em} #2}}
\newcommand{\Gcom}[1]{\color{GCred}\fbox{\sf #1}}
\newcommand{\Gmin}[1]{\noindent\vspace{-2ex}\hspace{\textwidth}
                      \color{GCred}\fbox{\large\sf -#1}}
\newcommand{\Gbon}[1]{\noindent\vspace{-2ex}\hspace{\textwidth}
                      \color{green}\fbox{\large\sf +#1}}
\newcommand{\Gfin}[2]{\noindent\hspace{\textwidth}\color{GCred}
                     \fbox{\large\sf Grade: #1/#2 \label{EndDoc}}}
\fi

\ifpdf
  %Make a big font for MSOE background
  \font\BigFon cmr10 scaled 3\magstep4 
  \font\BigSml cmr10 scaled 2\magstep4 
  %\font\BigSmlb cmr10 scaled 2\magstep4 
  \def\MSOEbg{\setlength{\unitlength}{1in}\begin{picture}(0,0)(0,0)%
                 \put(-2.8,-3.6){\textcolor{BGred}{\BigFon M}}%
                 \put(0.9,-3.6){\textcolor{BGred}{\BigFon S}}%
                 \put(-2.65,-6.65){\textcolor{BGred}{\BigFon O}}%
                 \put(0.5,-6.65){\textcolor{BGred}{\BigFon E}}%
%                 \put(-1.75,-4.8){\textcolor{BGred}{\BigSml ..}}%
%                 \put(-1.35,-6.4){\textcolor{BGred}{\BigSml -}}%
%                 \put(-1.35,-6.0){\textcolor{BGred}{\Huge \\}}%
              \end{picture}}
\else
  \def\MSOEbg{\MSOEs}
\fi

% listings.sty customization
\lstset{language=[Visual]C++}
\@ifundefined{cctland}%
  {\lstset{basicstyle=\sf\footnotesize,%
           keywordstyle=\tt\color{blue},%
           commentstyle=\rm\color{grn},%
           morekeywords={string,vector,map,set,list},%
           labelstyle=\scriptsize,%
           tabsize=2,%
           labelstep=2}}%
  {\@ifundefined{ccthw}%
    {\lstset{basicstyle=\sf\Large,%
             keywordstyle=\tt\color{blue},%
             commentstyle=\rm\color{grn},%
             morekeywords={string,vector,map,set,list},%
             tabsize=2,%
             labelstyle=\large,%
             labelstep=2}}%
    {\lstset{basicstyle=\sf\normalsize,%
             keywordstyle=\tt\color{blue},%
             commentstyle=\rm\color{grn},%
             morekeywords={string,vector,map,set,list},%
             tabsize=2,%
             labelstyle=\small,%
             labelstep=1}}}%
%\selectlisting[vc]{cpp}
%\@ifundefined{cctland}{%
%  \labelstyle[0]{\scriptsize} \commentstyle{\sc\small\color{grn}}}%
% {\labelstyle[0]{\normalsize}\commentstyle{\sc\large\color{grn}}%
%  \prelisting{\large}}
%\keywordstyle{\bfseries\color{blue}}
%\morekeywords{cout,cin,setw,precision,setfill,endl,ws,setf,unsetf,ios,fixed,
%              right,left,showpoint,get,put,getline,open,close,ifstream,
%              ofstream}

\addtolength{\headheight}{6pt}
\setlength{\hfuzz}{1in}
\setlength{\vfuzz}{1in}
