% ueasheet.cls -- A LaTeX class for UEA problem sheets by Robert Whittaker

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{ueasheet}[2022/04/08 Class for UEA Problem Sheets / Coursework]

% This is a LaTeX document class for writing problem sheets and
% handouts for teaching in the School of Mathematics at the University
% of East Anglia.
%                                                                              
% Further information (including a template .tex file that uses this
% class) can be found at: http://robert.mathmos.net/research/latex/

\newif\if@numpoint
\DeclareOption{numquest}{\@numpointfalse}
\DeclareOption{numpoint}{\@numpointtrue}

\newif\if@amsmath
\DeclareOption{amsmath}{\@amsmathtrue}
\DeclareOption{noamsmath}{\@amsmathfalse}

\newif\if@sans
\DeclareOption{serif}{\@sansfalse}
\DeclareOption{sans}{\@sanstrue}

\newif\if@hints
\DeclareOption{nohints}{\@hintsfalse}
\DeclareOption{hints}{\@hintstrue}

\newif\if@logo
\DeclareOption{logo}{\@logotrue}
\DeclareOption{nologo}{\@logofalse}

\newif\if@headerall
\DeclareOption{headerall}{\@headeralltrue}
\DeclareOption{noheaderall}{\@headerallfalse}

\newif\if@showmarks
\DeclareOption{marks}{\@showmarkstrue}
\DeclareOption{nomarks}{\@showmarksfalse}

\newif\if@offwhite
\DeclareOption{offwhite}{\@offwhitetrue}
\DeclareOption{white}{\@offwhitefalse}

\newif\if@access
\DeclareOption{access}{\@accesstrue}
\DeclareOption{noaccess}{\@accessfalse}

\ExecuteOptions{numquest,serif,nohints,noheaderall,nologo,marks,white,noaccess,noamsmath}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions\relax

\LoadClass[a4paper]{article}
\usepackage[hmargin=2cm,vmargin=2cm]{geometry}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{etoolbox}
\if@amsmath\usepackage{amsmath}\fi
\if@logo\RequirePackage{graphicx}\fi

% PDF accessibility improvements
\usepackage{cmap}
\ifpdf\pdfinterwordspaceon\fi
\if@access
  \ifpdf
    \usepackage[tagged]{accessibility}
    %\usepackage{axessibility}
  \fi
\fi

\if@sans
  %\usepackage[sfdefault]{cabin}
  %\usepackage[T1]{fontenc}
  \usepackage[notmath]{sansmathfonts}
  \renewcommand*\familydefault{\sfdefault}
\fi

\if@hints
  \newcommand{\hints}[1]{\emph{\textbf{Hint:} #1}\par\vspace{1em}}
  \newcommand{\onlyhints}[1]{#1}
  \newcommand{\nohints}[1]{}
\else
  \newcommand{\hints}[1]{}
  \newcommand{\onlyhints}[1]{}
  \newcommand{\nohints}[1]{#1}
\fi

\setlength{\parindent}{0pt}
\setlength{\skip\footins}{\baselineskip}

\newcommand{\module}[2]{\def\@modcode{#1}\def\@modname{#2}}
\newcommand{\semester}[1]{\def\@semester{#1}}
\newcommand{\email}[1]{\def\@email{#1}}
%\newcommand{\author}[1]{\def\@author{#1}}
\renewcommand{\title}[2][\null]{%
  \def\@title{#2}
  \def\p@title{\def\\{\relax\ifhmode\unskip\fi\space\ignorespaces}#2}
  \ifx\null#1\let\r@title\p@title\else\def\r@title{#1}\fi
}

\if@offwhite
  \usepackage{pagecolor}
  \definecolor{cream}{RGB}{255,230,205}
  \pagecolor{cream}
\fi

% Headers and footers, without fancyhdr
% (to avoid conflict with accessibilityMeta)

\if@showmarks
  \newcommand{\mmark}[1]{\mbox{}\nobreak\hfill\ifthenelse{\equal{#1}{1}}{\textbf{[1~mark]}}{\textbf{[{#1}~marks]}}\ignorespaces}
\else
  \newcommand{\mmark}[1]{}
\fi

\def\ps@ueasheetfooter{
  \let\@mkboth\@gobbletwo
  \let\@oddhead\@empty
  \def\@oddfoot{\reset@font\makebox[0pt][l]{\@author}\hfill\thepage\hfill\makebox[0pt][r]{\tt\@email}}
  \let\@evenhead\@oddhead
  \let\@evenfoot\@oddfoot
}

\def\ps@ueasheetboth{
  \let\@mkboth\@gobbletwo
  \def\@oddhead{\reset@font\makebox[0pt][l]{\@modcode}\hfill\r@title\hfill\makebox[0pt][r]{\@semester}}
  \def\@oddfoot{\reset@font\makebox[0pt][l]{\@author}\hfill\thepage\hfill\makebox[0pt][r]{\tt\@email}}
  \let\@evenhead\@oddhead
  \let\@evenfoot\@oddfoot
}

\if@headerall{
  \pagestyle{ueasheetboth}
\else
  \pagestyle{ueasheetfooter}
\fi

\newcommand{\heading}[1]{%
  \begin{center}%
    {\bf \Large {#1}}%
  \end{center}%
}

\newenvironment{aside}{%
  \em\paragraph*{Aside:}%
  }{%
  }

\newenvironment{note}{%
  \em\paragraph*{Note:}%
  }{%
  }

%\pagestyle{plain}

\AfterEndPreamble{%
  \thispagestyle{ueasheetfooter}
  \makebox[0pt][l]{\bf\@modcode}\hfill{\bf\@modname}\hfill\makebox[0pt][r]{\bf\@semester}\par
  \vspace{0.5em}
  \if@logo
  \parbox[b][4em][c]{0.8\textwidth}
         {\LARGE\centering{\if@sans\bf\@title\else\sc\@title\fi}}
  \hfill
  \makebox[0.15\textwidth][r]{%
    \includegraphics[width=0.14\textwidth]{UEA_NEW_BRAND_Magenta_N_A}%
  }%
  \vspace{0.75em}%
  \else
      {\LARGE\centering{\if@sans\bf\@title\else\sc\@title\fi}\par}
      \vspace{1em}
  \fi
  
}

%nested enumerate counters
\if@numpoint
  \renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}}
  \renewcommand{\labelenumiii}{(\alph{enumiii})}
\else  
  \renewcommand{\theenumi}{\arabic{enumi}}
  \renewcommand{\theenumii}{\roman{enumii}}
  \renewcommand{\theenumiii}{\alph{enumiii}}
  \renewcommand{\labelenumi}{\textbf{\theenumi.}}
  \renewcommand{\labelenumii}{(\theenumii)}
  \renewcommand{\labelenumiii}{(\theenumiii)}
\fi

%starred question numbers
\let\origlabeleni\labelenumi
\let\origlabelenii\labelenumii
\let\origlabeleniii\labelenumiii
\let\unstarred@item\item
\newcommand{\qstar}{\raisebox{0.1em}{\textasteriskcentered}}
\newcommand{\label@prefix}{}
\renewcommand{\labelenumi}{\label@prefix\origlabeleni}
\renewcommand{\labelenumii}{\label@prefix\origlabelenii}
\renewcommand{\labelenumiii}{\label@prefix\origlabeleniii}
\newcommand{\starred@item}{%
  \def\label@prefix{\qstar}
  \unstarred@item%
  \def\label@prefix{}%
}
\renewcommand{\item}{\@ifstar\starred@item\unstarred@item}

\newlength{\infoboxwidth}

\newcommand{\infobox}[1]{%
  \setlength{\fboxsep}{0.5em}
  \setlength{\infoboxwidth}{\textwidth}
  \addtolength{\infoboxwidth}{-2\fboxsep}
  \addtolength{\infoboxwidth}{-2\fboxrule}
  \fbox{\parbox{\infoboxwidth}{\em {#1}}}%
}

\newenvironment{readinglist}{%
  \begin{itemize}%
}{
  \end{itemize}%
}


\newcommand{\book}[6][\null]{%
  \item \textsc{#2}
  \textit{#3},
  {#4} ({#5}).
  #6
}

\newenvironment{references}{%
  \item[References]~
  \renewcommand{\section}[2]{}
  \begin{thebibliography}{1}%
}{
  \end{thebibliography}
}

\newcounter{refcntr}

\newcommand{\bibpaper}[9][\null]{%
  \ifx\null#1\bibitem{ref@\arabic{refcntr}}\stepcounter{refcntr}%
  \else\bibitem{#1}\fi
  \textsc{#2} (#3) #4, \textit{#5}
  \textbf{#6}\ifx\null#7\else~(#7)\fi\ifx\null#8\else, p#8\fi.\ifx\null#9\else\\#9\fi
}

\newcommand{\bibbook}[6][\null]{%
  \ifx\null#1\bibitem{ref@\arabic{refcntr}}\stepcounter{refcntr}%
  \else\bibitem{#1}\fi
  \textsc{#2} (#3) \textit{#4},
  #5.\ifx\null#6\else\\#6\fi
}

\newcommand{\bibincol}[7][\null]{%
  \ifx\null#1\bibitem{ref@\arabic{refcntr}}\stepcounter{refcntr}%
  \else\bibitem{#1}\fi
  \textsc{#2} (#3) #4 in \textit{#5},
  #6.\ifx\null#7\else\\#7\fi
}

\hypersetup{
  colorlinks = true,
  linkcolor = blue,
  citecolor = blue,
  pdflang = en-GB
}

\AtBeginDocument{
  \pdfstringdefDisableCommands{\def\\{\relax\ifhmode\unskip\fi\space\ignorespaces}}
  \hypersetup{
    pdftitle = {\@modcode\ \@title},
    pdfauthor = {\@author}
  }
}

\endinput
