\documentclass[hidelinks,10pt]{book}

%% Differentiate out the prelude to use in standalone markdown builds
\input{prelude.tex}

% Set up glossaries here so they aren't generated in each
\usepackage[toc,section=chapter]{glossaries}
\input{glossary.tex}
\makeglossaries

% Define and set styles so not injected into the markdown
% Pandoc chokes while processing the following, so put them here
\lstdefinestyle{cstyle}
{
	language=C,
	showspaces=false,
	showtabs=false,
	breaklines=true,
	showstringspaces=false,
	breakatwhitespace=true,
	tabsize=4,
	commentstyle=\color{comment}\itshape,
	stringstyle=\color{red}\bfseries,
	basicstyle=\ttfamily,
	keywordstyle=\color{purple}\bfseries,
	otherkeywords = {;,<<,>>,++,<,>,\#include,\#define},
	morekeywords = [2]{;,\#include,\#define},
	keywordstyle = [2]{\color{blue}\bfseries},
	morekeywords = [3]{<<, >>},
	keywordstyle = [3]{\color{yellow}},
	morekeywords = [4]{++},
	keywordstyle = [4]{\color{teal}},
	morekeywords = [5]{<,>},
	keywordstyle = [5]{\color{yellow}},
	literate={\{}{{\CodeSymbol{ \{}}}1
	{\}}{{\CodeSymbol{\}}}}1
}
\lstset{language=C,style=cstyle}

%% Spacing
\titlespacing*{\section}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{5.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsubsection}
{0pt}{5.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}


%% PDF Sizes
\titleformat*{\section}{\LARGE\bfseries}
\titleformat*{\subsection}{\Large\bfseries}
\titleformat*{\subsubsection}{\large\bfseries}
\titleformat*{\paragraph}{\large\bfseries}
\titleformat*{\subparagraph}{\large\bfseries}

%% Go to the next page if a section only has 3 lines
\widowpenalties 3 10000 10000 0

% this is a terrible hack, but pandoc sucks
% we have to call any
\lstnewenvironment{minted}{m}
  {\noindent\minipage{\linewidth}\medskip 
   \lstset{basicstyle=\ttfamily\footnotesize,frame=single,language=#1}}
  {\endminipage}

\usepackage{tocloft}

%% Add some space to the table of contents justification
\addtolength{\cftsecnumwidth}{10pt}

%% Epub command

\ifcsname ifepub\endcsname\else
  \expandafter\let\csname ifepub\expandafter\endcsname
                  \csname iffalse\endcsname
\fi

\begin{document}

\raggedbottom

%% The title so that it isn't included in the chapters
%% Introduction, background, then the book starts
\setcounter{chapter}{0}

\frontmatter
\include{title}
\fancyhf{}

\mainmatter
\input{order.tex}

%% Add glossaries back in when a number of terms have been defined
%% \printglossaries

\end{document}
