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

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

\usepackage[most]{tcolorbox}

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

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

\usepackage{fontspec}

\setmainfont{Lora}
\setsansfont[Ligatures=NoCommon]{Roboto Condensed}
\setmonofont[Scale=MatchLowercase]{Inconsolata}

\usepackage{microtype}         % general improvements to typography


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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\textsf{\PaperCode~---~\PaperTitle}}
\fancyhead[C]{}
\fancyhead[R]{\footnotesize\textsf{\LabNum\LabTitle}}
\fancyfoot[L]{}
\fancyfoot[C]{\footnotesize\textsf{\thepage}}
\fancyfoot[R]{}
\setlength{\headheight}{14pt}
\renewcommand{\footrulewidth}{0pt}


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

% relax the justification/hyphenation wrapping settings
\pretolerance=200
\tolerance=500
\setlength{\emergencystretch}{1.5em}

% try harder to avoid widows and orphans
\clubpenalty=300
\widowpenalty=300

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

% create an indent command that does not rely on \parindent
\renewcommand{\indent}{\hspace*{1em}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% syntax highlighting                                                       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings, lstautogobble}        % syntax highlighting

% create the fonts for code highlighting
\newcommand\codesize{\fontsize{11}{10}\selectfont}
\newcommand{\codefont}{\ttfamily}

% define the colors for code highlighting (based on NetBeans colors, although darker so that they are readable when printed on a black and white printer)
\definecolor{KeywordColor}{rgb}{0.0,0,0.6}
\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]"
}

\lstdefinelanguage{xml}
{
  morestring=[b][\color{black}]",
  moredelim=[s][\color{KeywordColor}]{<}{>},
  morecomment=[s]{<?}{?>},
  morecomment=[s]{<!--}{-->},
  commentstyle=\color{CommentColor},
  stringstyle=\color{StringColor},
  identifierstyle=\color{black},
  alsoletter=-:
}

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


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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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]
		\makebox[\textwidth][c]{\includegraphics[scale=#1,draft=false]{#2}}%
		\vspace{-5pt}
	\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}
}

% command for figures that fit the page width
\newcommand{\fittedfig}[1] {
  \begin{figure}[H]
    \begin{center}
      \resizebox{\textwidth}{!}{\includegraphics[draft=false]{#1}}
		\vspace{-25pt}
    \end{center}
  \end{figure}
}

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

% fix the extra spacing that itemize/enumerate has when you put have an blank
% line prior to the environment (enumitem).

\setlist*{topsep=0.2\baselineskip}
\setlist*{partopsep=-0.5\baselineskip}
\setlist*{itemsep=0.2\baselineskip}
\setlist*{parsep=0.4\baselineskip}

% 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$}



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

% menus, key strokes, paths
\usepackage[os=win]{menukeys}
\renewmenumacro{\menu}[>]{roundedmenus}
\renewmenumacro{\keys}[>]{roundedkeys}
\renewmenumacro{\path}[>]{pathswithfolder}
\changemenucolortheme{roundedmenus}{blacknwhite}
\changemenucolortheme{pathswithfolder}{blacknwhite}
\changemenucolortheme{roundedkeys}{blacknwhite}

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