%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%                                                                 %%%
%%%                            smstc.sty                            %%%
%%%                                                                 %%%
%%%   Style file for SMSTC lecture notes (for one or more units).   %%%
%%%                                                                 %%%
%%%                    Use with the REPORT class                    %%%
%%%                                                                 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% load REQUIRED packages:
\usepackage{amsmath,amssymb}   % for Math symbols
\usepackage{cite}              % allows citation labels to be modified
\usepackage{fancybox}          % used for lecture title
\usepackage{graphicx}          % for figure files
\usepackage{ifthen}            % for simple logic
\usepackage{minitoc}           % allows multiple TOCs in one file
\usepackage{url}               % for web or email addresses
\usepackage{xspace}            % flexible spacing after text commands

%% page sizing etc
%%
\textheight = 24.5cm
\textwidth = 16cm
\topmargin = -1.47cm
\oddsidemargin = 0.2cm
%%
\parskip = 0.5ex
\parindent = 0cm

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%  First stuff  %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initialise stuff for minitoc
\newcommand{\initdoc}{\dominitoc \tableofcontents \bigskip
\centerline{\rule{0.3\textwidth}{0.1ex}}
\bigskip 

}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Stream stuff  %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% dummy definitions so redefs use "\renewcommand"
\newcommand{\streamname}{dummy name}
\newcommand{\unitname}{dummy unit}
\newcommand{\thisyear}{dummy year}

%% macros to redefine them
\newcommand{\Streamname}[1]{\renewcommand{\streamname}{#1}}
\newcommand{\Unitname}[1]{\renewcommand{\unitname}{#1}}
\newcommand{\Thisyear}[1]{\renewcommand{\thisyear}{#1}}

\newcommand{\smstc}{$\mathcal{SMSTC}$\xspace}  %% logo: in page head
\newcommand{\stream}{\smstc: \streamname}
\newcommand{\smstcweb}{\url{www.smstc.ac.uk}}  %% SMSTC main web address

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Author stuff  %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\authstrut}{\rule[-2ex]{0mm}{5ex}}
\newcommand{\et}{\authstrut\\}

%% dummy definition so redef uses "\renewcommand"
\newcommand{\authinfo}{dummy author}

%% macro to redefine it
\newcommand{\Author}[1]{\renewcommand{\authinfo}{#1}}

\newcommand{\AuthorFt}[1]{
  \renewcommand{\et}{\footnotemark\authstrut\\}
  \renewcommand{\authinfo}{#1\footnotemark}
}

%% A lot of complicated stuff to get email footnotes to work
%% (called via \AuthorFt and \Email).
%% It DOESN'T WORK if there are too few \Email commands for
%% the number of authors.

\newcounter{numauth}  %% number of authors, set by footnote counter 
\newcounter{emind}    %% counter for email addresses
\renewcommand{\theemind}{\alph{emind}} \setcounter{emind}{0}

\def\mkft#1#2{%
\expandafter\def\csname #1\endcsname{#2}%
}

\newcommand{\Email}[1]{
  \addtocounter{emind}{1}
  \mkft{email\theemind}{    %% defines commands \emaila, \emailb ,...
    \setcounter{footnote}{\value{emind}}
%    \addtocounter{footnote}{1}
    \footnotetext{\url{#1}}
  }
}

\def\emailfooter#1{%      %% creates name \emaila from \email a 
\csname email#1\endcsname }

\newcounter{authcount}

\newcommand{\dofoot}{    %% used in \begin{unit}
  \setcounter{emind}{\value{authcount}}
  \emailfooter{\theemind}
  \addtocounter{authcount}{1}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Numbering  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Sectional units
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}

%% Page includes unit number:
\renewcommand{\thepage}{\thechapter--\arabic{page}}

%% Equation numbers subsidiary to units:
\renewcommand{\theequation}{\thechapter.\arabic{equation}}

%% Theorem-like things numbered within chapters
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}{Lemma}[chapter]
\newtheorem{proposition}{Proposition}[chapter]
\newtheorem{corollary}{Corollary}[chapter]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%  Unit environment  %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% "Unit" table of contents.   Needs minitoc package
\newcommand{\unittoc}{
%\setlength{\arrayrulewidth}{1pt}
\minitoc
%\setlength{\arrayrulewidth}{1pt}
}

%% "Unit" environment: uses two compulsory arguments
%% #1 is unit number
%% #2 is unit title
%%
\newenvironment{unit}[2]{
\renewcommand{\thefootnote}{\textit{\alph{footnote}}}
\pagestyle{myheadings} \markboth{\stream}{\stream}
\renewcommand{\thepage}{(\roman{page})}
\setcounter{page}{1}
\setcounter{chapter}{#1}\addtocounter{chapter}{-1}
\chapter{#2}
\unittoc
\setcounter{page}{1}
\renewcommand{\thepage}{\thechapter--\arabic{page}}
\setcounter{numauth}{\value{footnote}} \addtocounter{numauth}{1}
\setcounter{footnote}{0} \setcounter{authcount}{1}
\whiledo{\theauthcount<\thenumauth}{\dofoot}
} {
\setcounter{emind}{0}\setcounter{footnote}{0}\clearpage}

%% Chapter header
\def\@makechapterhead#1{%
\begin{center}
\shadowbox{\begin{minipage}{0.95\textwidth} \begin{center} \vsf{0.5}
\textbf{\st\LARGE SMSTC (\thisyear)} \medskip

\textbf{\st\LARGE \streamname } \medskip

\textbf{\st\Large \unitname\ \thechapter: #1} \vs{1}

\textbf{\large \authinfo \st}

\bigskip

\textbf{\LARGE \smstcweb \medskip}

\end{center}\end{minipage}}
\end{center}
\bigskip
}

%% Header for page (i)
\def\@makeschapterhead#1{%
\begin{center}
\shadowbox{\begin{minipage}{0.95\textwidth} \begin{center} \vsf{1}

\textbf{\st\LARGE SMSTC (\thisyear)} \bigskip

\textbf{\st\LARGE \streamname } \bigskip

\textbf{\LARGE \smstcweb\st}\medskip
\end{center}
\end{minipage}}\bigskip

\textbf{\Large  Contents}
\end{center}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%  Bibliography  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Uses article style.  Can put \AddCite in front of labels if required.

%% \newcommand{\AddCite}{\thechapter--}
%%\newcommand{\bibl}{\AddCite99}  %% Correct indent for bibitems
%%\renewcommand\citeform{\AddCite}  % by chapter: [2--18]
\newcommand{\bibl}{99}  %% Correct indent for bibitems

\newcommand{\refname}{References}

\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
      \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
     \list{\@biblabel{\@arabic\c@enumiv}}%
%%      \list{\@biblabel{\AddCite\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
%%           \renewcommand\theenumiv{\AddCite\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% Miscellanous macros %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Exercises
\renewcommand{\theenumi}{\textbf{\thechapter--\arabic{enumi}}}

\newenvironment{exercise}
{\begin{enumerate}
}{\end{enumerate}}

%% Proof environment
\newenvironment{proof}
{\textbf{Proof}\,\ }
{\hfill$\Box$\smallskip}

%% Equation labelling
\newcommand{\deq}[1]{(\ref{eq:#1})}  %% see pjd.tex for how to use

\newcommand{\vs}[1]{\vspace{#1 ex}}
\newcommand{\vsf}[1]{\vspace*{#1 ex}}
\newcommand{\st}{\rule[-1.5ex]{0mm}{4ex}}

\newcommand{\C}{\mathbb{C}}  %% Needs amssymb package
\newcommand{\R}{\mathbb{R}}  %% Needs amssymb package

\newcommand{\aside}[1]{{\em[#1]}} %% \aside{text} for "text" in italics
\newcommand{\cut}[1]{}            %% \cut{text} displays nothing

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% Other macro suggestions %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% Uncomment and copy to start of your file to use them %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Equations
%\newcommand{\be}{\begin{equation}}
%\newcommand{\ee}{\end{equation}}
%\newcommand{\eq}[1]{(\ref{eq:#1})}  %% same as \deq above

%% Itemize
%\newcommand{\bi}{\begin{itemize}}
%\newcommand{\ei}{\end{itemize}}
%\newcommand{\itbf}[1]{\item[{\bf{#1}}]}  %% Puts item name in bold

%\newcommand{\ben}{\begin{enumerate}}
%\newcommand{\een}{\end{enumerate}}

%\newcommand{\noi}{\noindent}

%\newcommand{\ceil}[1]{\lceil #1 \rceil}
%\newcommand{\floor}[1]{\lfloor #1 \rfloor}
%\newcommand{\ol}[1]{\overline{#1}}
%\newcommand{\ul}[1]{\underline{#1}}

