% =====================================================================
% LYXLAB.CLS -- A class for formatting lab readers using LyX/LaTeX.
%            -- Compiled by Gregory Plett, November 2000.
%
%======================================================================
% This file:
% ----------
%  0. LaTeX2e initialization.
%  1. Page layout.
%  2. Basic style shanges
%  3. Fonts.
%  4. Float (figures and tables) style changes.
%  5. Headers and footers.
%  6. Sectioning styles.
%  7. Math stuff.
%
% Options:
% --------
% noaftereqnind:  If selected, the line immediately following any 
%                 displayed equation will not be indented.
% narroweqnarray: Fixes a LaTeX2e bug. Makes the space around the
%                 "=" sign in an eqnarray the same as in \[ \]
% inline:         Removes excess space in inline math equations.
%
% Table Captions
% --------------
% One note that needs to be made concerning table captions is that
% all they are capitalized automatically. To circumvent this
% automatic event, such as to have a caption comes out as
% z-TRANSFORM, type \lowercase{z}-Transform, where the \lowercase{z}
% is in LaTeX mode (evil red text).
%
%======================================================================
% *********************************************************************
% ******                          *************************************
% *****   LaTeX2e INITIALIZATION   ************************************
% ******                          *************************************
% *********************************************************************
\NeedsTeXFormat{LaTeX2e}[1993/11/11] % Oldest acceptable version of LaTeX2e
\ProvidesPackage{lyxlab}[1999/02/01]   % Name of package provided, date

% Initial Code & Declaration of Options
% -------------------------------------
\newif\ifno@ftereqnind 		     % indents after equations suppressed.
\no@ftereqnindfalse
				     % regular or compressed "=" spacing in
\def\eqnarr@ysep{\arraycolsep}       % eqnarray (this is the default)
				     % NOTE: we must use "def" and not "="
				     % as arraycolsep not yet defined.

\DeclareOption{12pt}{\OptionNotUsed}
\DeclareOption{noaftereqnind}{\global\no@ftereqnindtrue\typeout{DOTEST: No 
	paragraph indents after equations selected.}}
\DeclareOption{narroweqnarray}{\gdef\eqnarr@ysep{0.28em\relax}\typeout{DOTEST:
	Narrow equation arrays selected.}}
\DeclareOption{inline}{\everymath{\thinmuskip=2mu plus 1mu
	\medmuskip=3mu plus 1mu minus 2mu
	\thickmuskip=4mu plus 2mu\relax}\typeout{DOTEST: Narrower inline 
	equations selected}}

%class: \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}

% Execution of Options/Package Loading
% ------------------------------------
\ProcessOptions
%\RequirePackage{rotating}
\RequirePackage{fancyheadings}
\RequirePackage{ifthen}
\RequirePackage{multicol}
\RequirePackage{pstricks}
\RequirePackage{pifont}

% =====================================================================
% Added Functionality 
% =====================================================================
% *********************************************************************
% ******               ************************************************
% *****   PAGE LAYOUT   ***********************************************
% ******               ************************************************
% *********************************************************************

% Basic Dimensions
% ----------------
\hoffset -0.2in                 % the default offset on the printed page
\voffset -0.7in
\paperwidth 8.5in               % the page size is 8.5x11 inches
\paperheight 11in
\oddsidemargin 0.1in              % margins are 0"
\evensidemargin 0.2in
\oddsidemargin 0.1in              % margins are 0"
\evensidemargin -0.2in
\topmargin  0in

\textwidth 7in                % width of the actual text
\textheight 9.5in               % height of the actual text
\parindent 0pc                  % the paragraph indent is 2 picas
\parskip 1mm plus 0.25mm minus 0.5mm % small skip between paragraphs

% Margin Paragraphs
\marginparsep 6pt
\marginparwidth 17mm 
\marginparpush 6pt

% Headers and Footers
\headheight 0.3in
\headsep 0.1in
% no footer in final mode. (except ch title pages. Put footers in 0
% sized vboxes in that case).
\footskip 0.4in

% Widow and Orphan control
% ------------------------
\clubpenalty10000\widowpenalty10000%
%\displaywidowpenalty=10000
%\predisplaypenalty=10000
%\postdisplaypenalty=-1000
\displaywidowpenalty=-100
\predisplaypenalty=-100
\postdisplaypenalty=-100

% Footnote spacing
% ----------------
\renewcommand{\footnoterule}{} 		% no rule in PH books.
\skip\footins=1pc minus 1pt		% space between text & footnote
%\skip\footins=10pt 		% space between text & footnote
\settoheight{\footnotesep}{\strut}
	\advance\footnotesep by 2pt 	% 2 pts between footnotes.

% *********************************************************************
% ******                       ****************************************
% *****   BASIC STYLE CHANGES   ***************************************
% ******                       ****************************************
% *********************************************************************

% Skips above and after displayed equations
% -----------------------------------------
\def\resetdisplayskips{%
\abovedisplayskip 6pt plus2pt minus1pt 	% above displayed equations
\belowdisplayskip 6pt plus3pt          	% below displayed equations
\abovedisplayshortskip 4pt plus2pt     	% above narrow displayed equations
\belowdisplayshortskip 6pt plus3pt     	% below narrow displayed equations
}

% Table Of Contents Style
% -----------------------
\setcounter{secnumdepth}{2}	     % Only number down to subsections
\setcounter{tocdepth}{1}	     % Only chapters/ sections in TOC
\renewcommand{\@dotsep}{500}	     % Turn off dots in the toc

% Numbered List Style
% -------------------
\renewcommand{\labelenumi}{\theenumi.}
\renewcommand{\labelenumii}{(\theenumii)}
\renewcommand{\labelenumiii}{\theenumiii.}
\renewcommand{\labelenumiv}{\theenumiv.}
\def\enumerate{\ifnum \@enumdepth >3 \@toodeep\else
      \advance\@enumdepth \@ne
      \edef\@enumctr{enum\romannumeral\the\@enumdepth}\list
      {\csname label\@enumctr\endcsname}{\usecounter
        {\@enumctr}\def\makelabel##1{\hss\llap{##1}}}\fi\itemsep 0pt\parsep 0pt}
\topsep 1pc plus 1pt minus 1pt

% redefine description label so it will be \sf
\renewcommand\descriptionlabel[1]{\hspace\labelsep
                                \bfseries #1}

% Gray colors for text
%---------------------
\newgray{WHITE}{1.0}
\newgray{BLACK}{0.0}
\def\textcolor{\BLACK}

% *********************************************************************
% ******              *************************************************
% *****   BOOK FONTS   ************************************************
% ******              *************************************************
% *********************************************************************

% Define special fonts
% --------------------
\newfont{\f@ntsfbHuge}{cmssbx10 scaled\magstep5}    %-- 25pt sans serif bold
\newfont{\f@ntsfbhuge}{cmssbx10 scaled\magstep4}    %-- 20pt sans serif bold
\newfont{\f@ntsfbLarge}{cmssbx10 scaled\magstep2}   %-- 14pt sans serif bold
\newfont{\f@ntsfblarge}{cmssbx10 scaled\magstep1}   %-- 12pt sans serif bold

% Large, special purpose fonts
% ----------------------------
\def\sfbitHuge{\reset@font\Huge%\f@ntsfbHuge
\sffamily\slshape\bfseries}
\def\sfbHuge{\reset@font\Huge\bfseries\sffamily}
\def\sfbhuge{\reset@font\huge\bfseries\sffamily}
\def\sfbithuge{\reset@font\huge\sffamily\slshape\bfseries}
\def\sfbLARGE{\reset@font\LARGE\bfseries\sffamily}
\def\sfbitLARGE{\reset@font\LARGE\bfseries\sffamily\slshape}
\def\sfitLARGE{\reset@font\LARGE\sffamily\slshape}
\def\sfitLarge{\reset@font\Large\sffamily\slshape}
\def\sfitlarge{\reset@font\large\sffamily\slshape}
\def\sfbLarge{\reset@font\Large\bfseries\sffamily}
\def\sfblarge{\reset@font\large\bfseries\sffamily}

% Twelve point
% ------------
\def\sfbtwelve{\reset@font\large\bfseries\sffamily}
\def\sftwelve{\reset@font\large\sffamily}
\def\rmbtwelve{\reset@font\large\bfseries}
\def\rmtwelve{\reset@font\large}

% Ten point
% ---------
\def\sfbten{\reset@font\normalsize\bfseries\sffamily}
\def\sfiten{\reset@font\normalsize\sffamily\itshape}
\def\sften{\reset@font\normalsize\sffamily}
\def\rmbten{\reset@font\normalsize\bfseries}
\def\rmiten{\reset@font\normalsize\itshape}
\def\rmten{\reset@font\normalsize}

% Nine point
% ----------
\def\sfbnine{\reset@font\small\bfseries\sffamily}
\def\sfnine{\reset@font\small\sffamily}
\def\rmbnine{\reset@font\small\bfseries}
\def\rmnine{\reset@font\small}

% Eight point
% -----------
\def\sfbeight{\reset@font\footnotesize\bfseries\sffamily}
\def\sfeight{\reset@font\footnotesize\sffamily}
\def\rmbeight{\reset@font\footnotesize\bfseries}
\def\rmeight{\reset@font\footnotesize}

% Seven point
% -----------
\def\sfbseven{\reset@font\scriptsize\bfseries\sffamily}
\def\sfseven{\reset@font\scriptsize\sffamily}
\def\rmbseven{\reset@font\scriptsize\bfseries}
\def\rmseven{\reset@font\scriptsize}

% Five point
% -----------
\def\sfbfive{\reset@font\tiny\bfseries\sffamily}
\def\sffive{\reset@font\tiny\sffamily}
\def\rmbfive{\reset@font\tiny\bfseries}
\def\rmfive{\reset@font\tiny}

% Figure fonts. Use these macros to ensure 
% consistancy in figures.
% ----------------------------------------
\let\figten=\rmten
\let\fignine=\rmnine		% Large figure text size
\let\figseven=\rmseven		% Normal figure text size
\let\figfive=\rmfive

% *********************************************************************
% ******                       ****************************************
% *****   FLOAT STYLE CHANGES   ***************************************
% ******                       ****************************************
% *********************************************************************

% Float placement parameters
% --------------------------
\setcounter{topnumber}{4}
\setcounter{bottomnumber}{4}
\renewcommand{\topfraction}{.9}
\renewcommand{\bottomfraction}{.9}
\renewcommand{\textfraction}{.05}
\renewcommand{\floatpagefraction}{.6}
\setlength{\floatsep}{20pt plus 2pt minus 4pt}

% Make sure that captions for tables work differently 
% than captions for figures.
% ---------------------------------------------------
\newif\ift@ble@orf@gure % true if in table
\renewcommand{\tablename}{\sfbeight TABLE}

% Redefine the \@makecaption command
% ----------------------------------
\def\tablewidth{\hsize}
\def\maxtablewidth{\hsize}
\long\def\@makecaption#1#2{%
\ifthenelse{\equal{\@captype}{table}}{%if a table
  \setbox\@tempboxa\hbox{{\sfbeight #1}\quad\uppercase{\sfeight #2}}
  \ifdim \tablewidth >\maxtablewidth \let\tablewidth\maxtablewidth \fi
  \ifdim \wd\@tempboxa > \tablewidth
    \noindent\hfil\parbox{\tablewidth}{%
    \raggedright{\sfbeight #1}\quad\uppercase{\sfeight #2}\par}\hfil%
  \else
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}% 
  \fi\vskip 4pt}{% else a figure
  \vskip 4pt\setbox\@tempboxa\hbox{{\rmbeight #1}\quad\rmeight #2}
  \ifdim \wd\@tempboxa >\hsize
    {\rmbeight #1}\quad\rmeight #2\par    
  \else
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}%   
  \fi}%
}%

% *********************************************************************
% ******                       ****************************************
% *****   HEADERS AND FOOTERS   ***************************************
% ******                       ****************************************
% *********************************************************************
\pagestyle{fancyplain}
\def\thepage{\thechapter--\arabic{page}}

\def\LHa{\small\sffamily\bfseries \longcoursename}
\def\LHb{\small\sffamily\coursename, \leftmark}
\lhead[\fancyplain{\LHa}{\LHb}]{\fancyplain{\LHa}{\LHb}}
\def\RHa{\normalsize\sffamily\thepage}
\def\RHb{\normalsize\sffamily\thepage}
\rhead[\fancyplain{\RHa}{\RHb}]{\fancyplain{\RHa}{\RHb}}
\chead[]{}
\def\author{I DON'T KNOW!}
\def\LHc{\footnotesize\sffamily Lab reader prepared by \author,
	ECE Department, University of Colorado at 
	Colorado Springs}
\let\LHd=\LHc
\lfoot[\fancyplain{\LHc}{\LHd}]{\fancyplain{\LHc}{\LHd}}
\rfoot[]{}
\cfoot[]{}
\headrulewidth 0.5pt
\plainheadrulewidth 0.5pt
\footrulewidth 0.5pt
\plainfootrulewidth 0.5pt

\newsavebox{\widthb@x}
\def\@shortchapapp{}
\def\@chapapp{\coursename}
\renewcommand{\appendix}{\par
  \setcounter{chapter}{0}%
  \setcounter{section}{0}%
  \renewcommand{\@chapapp}{\appendixname}%
  \renewcommand{\@shortchapapp}{App.\ }%
  \renewcommand{\thechapter}{\Alph{chapter}}
}

% Section mark
% ------------
\let\sectionmark\@gobble

% Regular chapter mark
% --------------------
\def\chaptermark#1{\markboth{#1.\qquad \@shortchapapp}{%
	\@shortchapapp \thechapter\qquad{#1}}}%

% Chapter mark for unnumbered chapters
% ------------------------------------
\def\nonumchaptermark#1{\markboth{#1}{#1}}
\def\twolinechapterA{\let\oldmarkboth=\markboth\let\markboth=\@gobbletwo}
\def\twolinechapterB#1{\let\markboth=\oldmarkboth\nonumchaptermark{#1}}

% *********************************************************************
% ******                     ******************************************
% *****   SECTIONING STYLES   *****************************************
% ******                     ******************************************
% *********************************************************************
%----------------------------- part ---------------------------------
% 

\def\partname{Unit}
\def\thepart{\arabic{part}}
\def\@endpart{\vspace*{1in}\thispagestyle{empty}}

\def\centermsg{\thispagestyle{empty}\vfill\centerline{(mostly blank)}%
\vfill}
\def\clearquadpage{\clearpage\ifodd\c@page\else\hbox{}%
\centermsg\newpage\fi}

\renewcommand\chapter{\clearquadpage
                    \thispagestyle{plain}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}

%------------------------- chapter -----------------------------------
\def\@makechapterhead#1{ \setcounter{page}{1} \vspace*{-10pt}  {\parindent 0pt 
 \begin{center}\sfbitHuge \begin{tabular}{c} #1\/ \\
	\hline\hline\end{tabular}\end{center}\par
 \nobreak \vskip 40pt plus 10pt minus 4pt} }

\def\@makeschapterhead#1{ \setcounter{page}{1} \vspace*{-10pt}  {\parindent 0pt 
 \begin{center}\sfbitHuge\begin{tabular}{c} #1\/ \\
	\hline\hline\end{tabular}\end{center}\par
 \nobreak \vskip 40pt plus 10pt minus 4pt} }

\long\def\@schapter#1{\if@twocolumn
                   \@topnewpage[\@makeschapterhead{#1}]%
                 \else
                   \@makeschapterhead{#1}%
                   \@afterheading
                 \fi
		 \nonumchaptermark{#1}}

%------------------------ section -----------------------------------
\def\section{%\global\everypar{} \suppressfloats[t]
\@startsection{section}{1}%
{\z@}{-22pt plus -4pt minus -4pt}{12pt plus 2pt minus 3pt}{\sfblarge}}

%--------------------- subsection -----------------------------------
\def\subsection{%\global\everypar{} \suppressfloats[t]
\@startsection{subsection}{2}{\z@}{%
	-12pt plus -4pt minus -4pt}{12pt plus 4pt minus 4pt}{\sfitlarge}}

%-------------------- subsubsection --------------------------------
\def\subsubsection{%\global\everypar{} \suppressfloats[t]
\@startsection{subsubsection}{3}{\z@}{%
	-1pc plus -0.25pc minus -0.25pc}{6pt plus 2pt minus 2pt}{
	\sfitlarge}}

%----------------------- paragraph ----------------------------------
\def\paragraph{%\suppressfloats[t]
\@startsection{paragraph}{4}{\z@}{1.25ex plus
     1ex minus .2ex}{-1em}{\sfitlarge}}

%---------------------- subparagraph --------------------------------
\def\subparagraph{%\suppressfloats[t]
\@startsection{subparagraph}{4}%
	{\parindent}{1.25ex plus 1ex minus .2ex}{-1em}{\normalsize\sfbten}}

%\long\def\underline#1{\relax\ifmmode
  %\@@underline{#1}\else $\@@underline{\mbox{#1}}\m@th$\relax\fi}

\def\@ssect#1#2#3#4#5{%
  \@tempskipa #3\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #4{%
        \@hangfrom{\hskip #1}%
          \interlinepenalty \@M \underline{\smash{#5}}\@@par}%
    \endgroup
  \else
    \def\@svsechd{#4{\hskip #1\relax #5}}%
  \fi
  \@xsect{#3}}

\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thechapter}
			  #1}%
                       \else
                         \addcontentsline{toc}{chapter}{
			  #1}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{
			  #1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi\global\@specialtocfalse}

\long\def\@schapter#1{%
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp.}%
                    \if@twocolumn
                      \@topnewpage[\@makeschapterhead{#1}]%
                    \else
                      \@makechapterhead{#1}%
                      \@afterheading
                    \fi
		    \nonumchaptermark{#1}}
		
% *********************************************************************
% ******              *************************************************
% *****   MATH STUFF   ************************************************
% ******              *************************************************
% *********************************************************************

% Change to the end of the eqnarray*, eqnarray, equation, 
% equation*, $$...$$, \[...\], environments to remove indent 
% on following paragraph.				       
% ----------------------------------------------------------
% The general fix is this:
\def\@mydisplay#1$${#1$$\m@thfix}
\everydisplay{%
\resetdisplayskips%
\abovedisplayskip \baselinestretch\abovedisplayskip%
\belowdisplayskip \baselinestretch\belowdisplayskip%
\abovedisplayshortskip \baselinestretch\abovedisplayshortskip%
\belowdisplayshortskip  \baselinestretch\belowdisplayshortskip%
%\interlinepenalty=10000%
\interdisplaylinepenalty=100%
%\displaywidowpenalty=10000%
%\predisplaypenalty=10000%
\lineskip 0pt plus 2pt%
\lineskiplimit 16383pt%
\ifddm@th\@mydisplay\fi}

% not pretty -- we shouldn't need to do the "global". This may have
% bad side effects (math mode in tables, minipages etc)
\def\m@thfix{\ifno@ftereqnind%
\global\everypar{\hskip-\parindent\everypar{}\ignorespaces}\fi%
\ddm@thtrue\par}

% If we entered $$ mode through LaTeX's various \[ ... modes, this
% macro gets confused (since it looks for a terminating $$ which isn't there.)
% Thus, we have to know how we got into display math mode:
\newif\ifddm@th	\ddm@thtrue	% true if in $$ (double dollar) math mode

% Fixes for {equation},{displaymath},\[\] modes
\def\equation{\ddm@thfalse $$ % $$ BRACE MATCHING HACK
\refstepcounter{equation}}
\def\endequation{\eqno \hbox{\@eqnnum}% $$ BRACE MATCHING HACK
$$\global\@ignoretrue\m@thfix\ddm@thtrue}

\def\displaymath{\ddm@thfalse\[}
\def\enddisplaymath{\]\global\@ignoretrue\m@thfix}

\def\[{\relax\ifmmode\@badmath\else
    \ifvmode \nointerlineskip \makebox[.6\linewidth]\fi\ddm@thfalse$$%
	%$$ BRACE MATCH HACK
    \fi}
\def\]{\relax\ifmmode\ifinner\@badmath\else$$\m@thfix%
	\fi%%$$ BRACE MATCH HACK
        \else \@badmath \fi\ignorespaces\ddm@thtrue}

% Fix for eqnarray which also changes colsep
\def\eqnarray{\ddm@thfalse%
%\def\int{\intop}% put limits on top & bottom for prentice hall in eqnarray
\stepcounter{equation}\let\@currentlabel\theequation
\global\@eqnswtrue\m@th
\global\@eqcnt\z@\tabskip\@centering\let\\\@eqncr
$$\halign to\displaywidth\bgroup\@eqnsel\hskip\@centering
  $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne
  \hskip\eqnarr@ysep\hfil${##}$\hfil
  &\global\@eqcnt\tw@\hskip\eqnarr@ysep$\displaystyle\tabskip\z@{##}$\hfil
   \tabskip\@centering&\llap{##}\tabskip\z@\cr}
 
\def\endeqnarray{\@@eqncr\egroup
      \global\advance\c@equation\m@ne$$\global\@ignoretrue\m@thfix}

% Make the "dot" commands produce larger dots
% -----------------------------------------
%\def\dot#1{\mathord{\stackrel{\mbox{\large.}}{#1}}}
%\def\ddot#1{\mathord{\stackrel{\mbox{\large.\hskip-1.3pt.}}{#1}}}
%\def\dddot#1{\mathord{\stackrel{\mbox{\large.\hskip-1.3pt.\hskip
  %-1.3pt.}}{#1}}}
%\def\ddddot#1{\mathord{\stackrel{\mbox{\large.\hskip-1.3pt.\hskip
  %-1.3pt.\hskip-1.3pt.}}{#1}}}

%-----------------------------------------------
% etc
%-----------------------------------------------
%\AtBeginDocument{\raggedright\def\baselinestretch{1.15}%
%\LARGE\sffamily\def\jot{10pt}} % extra spacing between equation lines.
\AtEndDocument{\clearquadpage}

\newfont{\Bb}{msbm10 scaled 1600}
\def\Translate#1{\ensuremath{\mbox{\Bb T}\bigl[ #1 \bigr]}}
\def\translate#1{\ensuremath{\mbox{\Bb T}\left[ #1 \right]}}
\def\defeq{\ensuremath{\stackrel{\triangle}{=}}}
\def\checkmark{\mbox{\ding{51}}} % ZaphDingbat checkmark (ok)
\def\xmark{\mbox{\ding{55}}} % ZaphDingbat x-mark (not ok)

%\let\textrm=\textsf

%---------------------------------------------------------------
% Footnote stuff
%---------------------------------------------------------------
\long\def\@footnotetext#1{\insert\footins{\def\baselinestretch{1}
    \Large\footnotesize\interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}\@makefntext
    {\rule{\z@}{\footnotesep}\ignorespaces
      #1\strut}}}

%---------------------------------------------------------------
% Stuff for drawing sumary boxes
%---------------------------------------------------------------
\fboxrule 1pt
\fboxsep 10pt
\newdimen\bhsize \bhsize=\textwidth 
\advance\bhsize by -7.5\fboxrule
\advance\bhsize by -1pt
\advance\bhsize by -2\fboxsep
\newenvironment{DBoxedminipage}%
 {\begin{Sbox}\begin{minipage}}%
 {\end{minipage}\end{Sbox}\doublebox{\TheSbox}}

