Newer
Older
LaTeX / lectures / otagoslides.cls
\def\classdate{12 December 2024}
\def\classversion{1.4.1}
\def\classshortdate{2024/12/12}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Document class for lecture slides.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Version History
% v1.0    Initial version, rebuilt from deprecated lectureslides class.
% v1.0.1  Stopped hyperref complaining about invalid tokens in PDF metadata.
% v1.1    Added bibliography customisations.
% v1.2    Switched to fontawesome5.
% v1.3    Revamped colour control.
% v1.3.1  fontawesome5 no longer defaults to regular style.
% v1.4    Generalised department type.
% v1.4.1  Normalised package info messages.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}[2001/06/01]
\ProvidesClass{otagoslides}%
         [\classdate\space v\classversion\space Otago lecture slides]


% "Stream of conciousness" chapters vs. explicit individual classes. NOTE:
% you can't have both chapters and classes! This is because we use the same
% chapter macros for both cases, but they're applied differently (e.g., if
% nochapters is set, then \insertchapternumber represents the class number).
\newif\if@chapters \@chapterstrue
\DeclareOption{nochapters}{\@chaptersfalse}


\DeclareOption*{\PassOptionsToClass{\CurrentOption}{beamer}}
\ProcessOptions
\LoadClass{beamer}


% Load required packages.
\RequirePackage{tikz}
% \RequirePackage{pgf} % DEPRECATED: only included for backwards compatibility
\RequirePackage[normalem]{ulem}
\RequirePackage{pifont}
\RequirePackage{xr}
\RequirePackage{multido}
\RequirePackage{boxedminipage}
\RequirePackage{graphicx}
\RequirePackage{hyperref}
\RequirePackage{otagofonts}
% \RequirePackage{otagologo}
% fontawesome5 must load after otagofonts to avoid fontspec option clash
\RequirePackage{fontawesome5}


% Check that the UO logo files are installed somewhere in the TeX path.
\IfFileExists{OU-Logo-Colour.pdf}{}{%
    \PackageError{otagoslides}{The University of Otago logo images are not installed}{%
        You should be able to download a bundle of the UO logo images from\MessageBreak%
        the same place you got this document class. The files should be\MessageBreak%
        put in a folder somewhere inside your local LaTeX tree.%
    }
}

\hypersetup{%
    pdfpagemode=UseNone,%
    colorlinks=true,%
    linkcolor=,%
    anchorcolor=,%
    citecolor=,%
    filecolor=,%
    menucolor=,%
    runcolor=,%
    urlcolor=blue%
}


% graphicx setup.
\graphicspath{{images/}}


% Simple code listing setup.
\newcommand{\keyword}[1]{\texttt{\uppercase{#1}}}
\newcommand{\nonterminal}[1]{\textit{\texttt{#1}}}
% Note: maximum 13 tab stops in a tabbing environment. (Bah.)
\newenvironment{codesyntaxblock}[1][\normalsize]%
    {\begingroup\ttfamily#1\begin{tabbing}mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=\kill}%
    {\end{tabbing}\endgroup}


% Environment for boxed exercises.
\newcounter{exercise}
\setcounter{exercise}{0}
% Arguments: #1 width of box to set the exercise text in (defaults to \columnwidth).
\newenvironment{exercise}[1][\columnwidth]%
    {\noindent\refstepcounter{exercise}\begin{boxedminipage}{#1}\textbf{Exercise \theexercise: }}%
    {\end{boxedminipage}}
% Starred form produces an unnumbered exercise.
\newenvironment{exercise*}[1][\columnwidth]%
    {\noindent\begin{boxedminipage}{#1}\textbf{Exercise: }}%
    {\end{boxedminipage}}


% Standard variables for various things, and macros for initialising them.
% These can be used (or not) as necessary.

% Paper variables: subject code.
\newcommand{\SubjectCode}{UNDEFINED}
\newcommand{\SetSubjectCode}[1]{\renewcommand{\SubjectCode}{#1}}

% Paper number.
\newcommand{\PaperNumber}{UNDEFINED}
\newcommand{\SetPaperNumber}[1]{\renewcommand{\PaperNumber}{#1}}

% Convenience macro for printing out the full paper code.
\newcommand{\PaperCode}{\SubjectCode~\PaperNumber}

% Paper title.
\newcommand{\PaperTitle}{UNDEFINED}
\newcommand{\SetPaperTitle}[1]{\renewcommand{\PaperTitle}{#1}}

% Department name.
\newcommand{\DepartmentType}{Department of}
\newcommand{\SetDepartmentType}[1]{\renewcommand{\DepartmentType}{#1}}

% Department name.
\newcommand{\DepartmentName}{UNDEFINED}
\newcommand{\SetDepartmentName}[1]{\renewcommand{\DepartmentName}{#1}}

% Teaching period.
\newcommand{\TeachingPeriod}{UNDEFINED}
\newcommand{\SetTeachingPeriod}[1]{\renewcommand{\TeachingPeriod}{#1}}

% Year offered.
\newcommand{\YearOffered}{UNDEFINED}
\newcommand{\SetYearOffered}[1]{\renewcommand{\YearOffered}{#1}}

% Oracle version.
\newcommand{\Oracle}{UNDEFINED}
\newcommand{\SetOracleVersion}[1]{\renewcommand{\Oracle}{#1}}

% Class number.
\newcounter{chapterplusone}
\newcommand{\ClassNumber}{\thechapter}
\newcommand{\ClassNumberPlusOne}{\thechapterplusone}
\newcommand{\SetClassNumber}[1]{%
    \setcounter{chapter}{#1}%
    \setcounter{chapterplusone}{#1}%
    \stepcounter{chapterplusone}%
}

% Backwards compatibility with the old syntax
% \newcommand{\ChapterNumber}{\ClassNumber}
% \newcommand{\ChapterNumberPlusOne}{\ClassNumberPlusOne}
% \newcommand{\SetChapterNumber}[1]{\SetClassNumber{#1}}

% Class title.
\newcommand{\ClassTitle}{UNDEFINED}
\newcommand{\SetClassTitle}[1]{\renewcommand{\ClassTitle}{#1}}

\newcommand{\ShortClassTitle}{UNDEFINED}
\newcommand{\SetShortClassTitle}[1]{\renewcommand{\ShortClassTitle}{#1}}

% Backwards compatibility with the old syntax
% \newcommand{\ChapterTitle}{\ClassTitle}
% \newcommand{\SetChapterTitle}[1]{\SetClassTitle{#1}}
% \newcommand{\ShortChapterTitle}{\ShortClassTitle}
% \newcommand{\SetShortChapterTitle}[1]{\SetShortClassTitle{#1}}

% Class type.
\newcommand{\ClassType}{Lecture}
\newcommand{\SetClassType}[1]{\renewcommand{\ClassType}{#1}}


% Beamer setup.
\mode<presentation>
{
	\usetheme{OtagoPlain}
	\setbeamertemplate{navigation symbols}{}
}


\if@chapters
    \SetClassType{Chapter}
\fi


% hyperref setup. We have to use a slightly convoluted method, because the
% macros referenced here haven't been set yet. Define the hyperref setup
% as a new macro, and call this AFTER initialising the paper and chapter
% variables.
\newcommand{\inithyperref}{%
    \hypersetup{%
        pdftitle={\PaperCode\ \ClassType\ \thechapter\ Slides},%
        pdfsubject={\ShortClassTitle}%
    }%
}

% Disable certain commands in PDF metadata to stop hyperref complaining
% about invalid tokens. This is caused by \insertchapternumber in the
% Otago Beamer theme, which calls \usebeamerfont and \usebeamercolor.
\pdfstringdefDisableCommands{%
    \def\usebeamercolor#1{}%
    \def\usebeamerfont#1{}%
}

% Document setup.
\author{}
\if@chapters
    \title{\PaperCode}
\else
    \title{\PaperCode \\ \PaperTitle}
\fi
\subtitle{\ClassType\ \insertchapternumber: \ClassTitle}
\institute{\DepartmentType\ \DepartmentName}
\date{\TeachingPeriod, \YearOffered}


% Some useful miscellaneous macros.

% B-I-G braces {} with a text label
%
% Arguments: [#1] height of brace; if missing, defaults to the height of the label box
%            {#2} width of box for label
%            {#3} the text of the label
%
% TODO: This could possibly be refactored into a single macro with a l/r argument?
\newcommand{\BIGL}[3][]{%
    \( \left\}%
       \ifx&#1&\else\parbox[c][#1]{0cm}{}\right.\fi%
       \begin{minipage}{#2}\flushleft\mbox{}#3\end{minipage}%
       \ifx&#1&\right.\fi%
    \)%
}
\newcommand{\BIGR}[3][]{%
    \( \ifx&#1&\left.\fi%
       \begin{minipage}{#2}\flushright\mbox{}#3\end{minipage}%
       \ifx&#1&\else\left.\parbox[c][#1]{0cm}{}\fi%
       \right\{%
    \)%
}

% Bold-face text using the structure or alert colour.
\newcommand<>{\structurebf}[1]{\structure#2{\textbf{#1}}}
\newcommand<>{\alertbf}[1]{\alert#2{\textbf{#1}}}

% Define the standard beamer colours as actual colours, as we use them
% in \color and \textcolor rather a lot.
\usebeamercolor*[fg]{structure}\colorlet{beamerstructure}{fg}
\usebeamercolor*[fg]{alerted text}\colorlet{beameralert}{fg}

% Beamer-aware strikeout.
\newcommand<>{\strikeout}[1]{\alt#2{\sout{#1}}{#1}}

% Coloured highlighting of text (via Mark George).
% \vphantom gives correct ascender and descender height for box.
\newcommand{\highlight}[2][yellow!75]{\setlength{\fboxsep}{1pt}\hskip-1pt\colorbox{#1}{\vphantom{dy}#2}\hskip-1pt}
% Uses the same spacing as \highlight, but does no highlighting.  Use on the
% original code when using incremental highlighting.
\newcommand{\nohighlight}[1]{\highlight[white!0]{#1}}
\newcommand{\error}[1]{\highlight[red!75]{#1}}

% Create an "invisible" cell in a table for consistent spacing purposes.
% It does so by taking the width of the supplied text and generating an
% empty box 1pt wider.
\newcommand{\InvisibleCell}[2]{%
	\multicolumn{1}{#1}{\makebox[\widthof{#2} + 1pt]{}}%
}

% Draw a grid to aid PGF picture drawing/debugging.
% DEPRECATED: Use \DrawGridTikZ instead.
\newcommand{\DrawGrid}[2]{%
	\begin{pgfscope}%
		\color{lightgray}%
		\pgfsetlinewidth{0.5pt}%
		\pgfpathgrid[step={\pgfxy(0.2,0.2)}]{\pgfxy(0,0)}{\pgfxy(#1,#2)}%
		\pgfusepath{stroke}%
		\pgfsetlinewidth{1pt}%
		\pgfpathgrid[step={\pgfxy(1,1)}]{\pgfxy(-0.1,-0.1)}{\pgfxy(#1+0.1,#2+0.1)}%
		\pgfusepath{stroke}%
		\pgfputat{\pgfxy(0,-0.2)}{\pgfbox[center,top]{\tiny 0}}%
		\pgfputat{\pgfxy(-0.2,0)}{\pgfbox[right,center]{\tiny 0}}%
		\multido{\nx=1+1}{#1}{\pgfputat{\pgfxy(\nx,-0.2)}{\pgfbox[center,top]{\tiny\nx}}}%
		\multido{\ny=1+1}{#2}{\pgfputat{\pgfxy(-0.2,\ny)}{\pgfbox[right,center]{\tiny\ny}}}%
	\end{pgfscope}%
}

% Draw a grid to aid TikZ picture drawing/debugging.
\newcommand{\DrawGridTikZ}[2]{%
	\begin{scope}[color=lightgray]
		\draw[thin,step=1mm]  (0.0,0.0)   grid (#1,#2);%
		\draw[thick,step=1cm] (-0.1,-0.1) grid (#1+0.1,#2+0.1);%
		\pgftext[top,at={\pgfxy(0.0,-0.2)}]{\tiny 0}%
		\pgftext[right,at={\pgfxy(-0.2,0.0)}]{\tiny 0}%
		\foreach \x in {1,...,#1} {\pgftext[top,at={\pgfxy(\x,-0.2)}]{\tiny\x}}%
		\foreach \y in {1,...,#2} {\pgftext[right,at={\pgfxy(-0.2,\y)}]{\tiny\y}}%
	\end{scope}
}

% For numbered notes, add note number references to the slides when generating notes.
\ifbeamer@notes
    \newcounter{noteitem}[page]
    \newcommand<>{\noteitem}[1]{\only#2{\refstepcounter{noteitem}\unskip\ \fbox{\textbf{\scriptsize\thenoteitem}}\note[item]{#1}}}
\else
    \newcommand<>{\noteitem}[1]{\only#2{\note[item]{#1}}}
\fi

% Sometimes we want to put a comment in tiny text on the next line, but the default line skip
% will insert too much vertical space. Put a \tinyskip at the end of the line instead.
\def\tinyskip{\\[-0.33\baselineskip]}

% Increase item separation of level 1 list items. Can't use enumitem because it breaks beamer lists :(.
% See: <https://tex.stackexchange.com/a/31524>
\makeatletter
\patchcmd{\@listI}{\itemsep3\p@}{\itemsep6\p@}{}{}
\makeatother


% Bibliography customisations for beamer. Uses FontAwesome icons.
% Use: \setbeamertemplate{bibliography item}[faArticle]
\setbeamercolor{bibliography item}{use=normal text,fg=normal text.fg}
\setbeamercolor{bibliography entry author}{use=normal text,fg=normal text.fg}
\setbeamercolor{bibliography entry location}{use=normal text,fg=normal text.fg}
\setbeamercolor{bibliography entry note}{use=normal text,fg=normal text.fg}
\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry location}{}
\setbeamertemplate{bibliography entry note}{}

\defbeamertemplate{bibliography item}{faArticle}{\hfill\faNewspaper}
\defbeamertemplate{bibliography item}{faBook}{\hfill\faBook}
\defbeamertemplate{bibliography item}{faDocument}{\hfill\faFile*}
\defbeamertemplate{bibliography item}{faImage}{\hfill\faImage}
\defbeamertemplate{bibliography item}{faLink}{\hfill\faLink}
\defbeamertemplate{bibliography item}{faMovie}{\hfill\faFilm}
\defbeamertemplate{bibliography item}{faWeb}{\hfill\faCloud}
\defbeamertemplate{bibliography item}{faWikipedia}{\hfill\faWikipediaW}

\endinput