Newer
Older
templates / labs / preamble.tex
\documentclass[a4paper, 12pt]{article}

\usepackage[a4paper, portrait, hmargin=20mm, vmargin=25mm]{geometry}
\usepackage[bookmarks, colorlinks]{hyperref}
\usepackage{paralist, float, tabularx, hhline, graphicx, xcolor, todonotes, hyperref}

\hypersetup{
	bookmarks, colorlinks,
	citecolor=black, linkcolor=black,  % don't need colored links
	urlcolor=blue!55!black % blue enough to see, but dark enough to print
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% fonts                                                                     %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{cmap}              % fix PDF searching (ligatures cause problems)
\usepackage{libertine}         % default font set (looks good on both screen and paper)
\usepackage[scaled]{beramono}  % code font
\usepackage[T1]{fontenc}       % force type 1 fonts
\usepackage{microtype}         % general improvements to typography
\usepackage{textcomp}          % additional symbols (like the degrees symbol}
\usepackage{listings}          % syntax highlighting

% make \emph do italics (just in case other environments change it)
\renewcommand{\emph}[1]{\textit{#1}}

% add a \strong command
\newcommand{\strong}[1]{\textbf{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% sections                                                                  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[sf,bf]{titlesec}
\titlespacing{\section}{0pt}{0.75\parskip}{-0.25\parskip}
\titlespacing{\subsection}{0pt}{0.75\parskip}{-0.25\parskip}
\titlespacing{\subsubsection}{0pt}{0.75\parskip}{-0.25\parskip}
\titlespacing{\paragraph}{0pt}{0.75\parskip}{-0.25\parskip}

% repurpose \paragraph as \subsubsubsection (which it sort of is already)
\titleformat{\paragraph}{\normalfont\normalsize\sffamily\bfseries}{\theparagraph}{1em}{}
\titlespacing{\paragraph}{0pt}{0.75\parskip}{-0.25\parskip}
\newcommand{\subsubsubsection}[1]{\paragraph{#1}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% headers/footers                                                           %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{fancyhdr}
\pagestyle{fancyplain}
\fancyhead[L]{\footnotesize\PaperCode~--~\PaperTitle}
\fancyhead[C]{}
\fancyhead[R]{\footnotesize\LabNum\LabTitle}
\fancyfoot[L]{}
\fancyfoot[C]{\thepage}
\fancyfoot[R]{}
\setlength{\headheight}{14pt}
\renewcommand{\footrulewidth}{0pt}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% general layout                                                            %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% relax the justification/hyphenation wrapping settings
\tolerance=800
\emergencystretch=5mm

% try to avoid widows and orphans
\clubpenalty = 10000
\widowpenalty = 10000

% kill the paragraph indenting
\setlength{\parindent}{0 mm}
\setlength{\parskip}{0.7\baselineskip}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% syntax highlighting                                                       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% create the fonts for code highlighting
\newcommand\codesize{\fontsize{11}{8}\selectfont}
\newcommand{\codefont}{\fontfamily{fvm}\selectfont} % beramono
\newcommand{\commentfont}{\rmfamily\itshape}  % standard roman

% define the colors for code highlighting (based on Eclipse colors)
%\definecolor{KeywordColor}{rgb}{0.5,0,0.33}
%\definecolor{CommentColor}{rgb}{0.25,0.5,0.37}
%\definecolor{StringColor}{rgb}{0.16,0,1}

% define the colors for code highlighting (based on NetBeans colors, although darker)
\definecolor{KeywordColor}{rgb}{0.0,0,0.7}
\definecolor{CommentColor}{rgb}{0.3,0.3,0.3}
\definecolor{StringColor}{rgb}{0.4,0.22.0}

\lstdefinelanguage{JavaScript}{
  keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break, this},
  sensitive=false,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morestring=[b]',
  morestring=[b]"
}

% create a new environment for source code blocks
\lstnewenvironment{codeblock}[1][]
{
\lstset{
	language=Java,
	upquote=true,
	basicstyle=\color{black}\codefont\codesize,
	keywordstyle=\color{KeywordColor}\codefont\codesize,
	commentstyle=\color{CommentColor}\commentfont\normalsize,
	stringstyle=\color{StringColor}\codefont\codesize,
	aboveskip=10pt,
	belowskip=0pt,
	showstringspaces=false,
	tabsize=3,
	showtabs=false,
	columns=fullflexible,
	flexiblecolumns=true,
	breaklines=true
}\lstset{#1}}
{}

% command for typesetting inline code
\newcommand{\code}[2][language=java]{%
\lstset{%
	language=Java,
	upquote=true,
	basicstyle=\color{black}\codefont\codesize,
	keywordstyle=\color{black}\codefont\codesize,
	commentstyle=\color{black}\commentfont\normalsize,
	stringstyle=\color{black}\codefont\codesize,
	showstringspaces=false,
	showtabs=false
}%
\mbox{\lstinline[#1]!#2!}}

% centre command that won't add any vertical space before or after
\newcommand{\centre}[1]{\hfill#1\hfill}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% figures                                                                   %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PDF tex graphics extensions
\DeclareGraphicsExtensions{.jpg,.jpeg,.pdf,.png}

% command for figures with captions - first param is scale.
\newcommand{\captionedfig}[3] {
  \begin{figure}[H]
    \begin{center}
      \includegraphics[scale=#1,draft=false]{#2}
		\\
		#3
		\vspace{-25pt}
    \end{center}
  \end{figure}
}

% command for figures - first param is scale.
\newcommand{\fig}[2] {
  \begin{figure}[H]
    \begin{center}
      \includegraphics[scale=#1,draft=false]{#2}
		\vspace{-25pt}
    \end{center}
  \end{figure}
}

% command for figures rotated 90 degrees right - first param is scale.
\newcommand{\rotatedfig}[2] {
  \begin{figure}[H]
    \begin{center}
      \includegraphics[scale=#1,draft=false, angle=270]{#2}
    \end{center}
  \end{figure}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% lists                                                                     %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% fix the extra spacing that itemize/enumerate has when you put have an blank
% line prior to the environment (paralist).
\setlength{\pltopsep}{0.2\baselineskip}
\setlength{\plpartopsep}{-0.2\baselineskip}
\setlength{\plitemsep}{0.2\baselineskip}
\setlength{\plparsep}{0.4\baselineskip}

% use paralist compact versions by default so that above tweaks are used
\renewenvironment{itemize}%
  {\begin{compactitem}}%
  {\end{compactitem}}

\renewenvironment{enumerate}%
  {\begin{compactenum}}%
  {\end{compactenum}}

% rationalise the bullet points
\def\labelitemi{\footnotesize$\bullet$}
\def\labelitemii{\footnotesize$\circ$}
\def\labelitemiii{\footnotesize$\diamond$}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% to-do notes                                                               %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% fix todonotes 'wrong margin' issue
\reversemarginpar
\newcommand{\fix}{\todo[color=red!60,noline,size=\large]{Fix}}
\newcommand{\comment}[1]{\todo[color=yellow!60,inline,size=\large]{#1}}
\newcommand{\incomplete}{\todo[color=red!60,inline,size=\large]{Incomplete}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% misc                                                                      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% a simpler way of getting a right arrow
\newcommand{\ra}[0]{$\rightarrow$~}