\documentclass[openright,11pt]{book}

%
% Packages
%

\usepackage{makeidx}
\usepackage{graphics}
\usepackage{color}
\usepackage{verbatim}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{tocbibind}
\usepackage{colortbl}
\usepackage{fancyheadings}
\usepackage{float}
\usepackage{letterspace}
\usepackage{ifthen}
\usepackage{upquote}


%
% Page configuration
%

% Page size
\setlength{\paperwidth}{7.375in}
\setlength{\paperheight}{9.25in}
\pdfpagewidth=7.375in
\pdfpageheight=9.25in

% Kill the margin
\setlength{\marginparwidth}{0in}

% Header settings
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0.5in}
\setlength{\headsep}{0.25in}

% Footer settings (none)
\setlength{\footskip}{0in}

% Footnote settings
\setlength{\skip\footins}{0.5in}
\makeatletter
\renewcommand{\@makefntext}[1]{\setlength{\parindent}{0pt}%
  \begin{list}{}{%
      \raggedright
      \setlength{\labelwidth}{0.1in}%
      \setlength{\itemindent}{0in}%
      \setlength{\leftmargin}{0.2in}%
      \setlength{\labelsep}{0.1in}%
      \setlength{\listparindent}{0in}%
      \setlength{\itemsep}{0pt}%
      \setlength{\parsep}{0pt}%
      \setlength{\topsep}{0pt}%
      \footnotesize}\item[\hfill\@makefnmark]#1%
\end{list}}
\makeatother

% Margin settings
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

% Body settings
\setlength{\textwidth}{5.375in}
\setlength{\textheight}{7in}

% Paragraph settings
\setlength{\parskip}{0.1in}

% Disable section numbering (set numbering depth to zero).
\setcounter{secnumdepth}{0}
%\setcounter{tocdepth}{3}

% Disable paragraph indentation (we'll space paragraphs out).
\parindent=0in

% Hackity hackity (The LaTeX Companion rocks)
\makeatletter
\renewcommand{\section}{\@startsection
  {section}%
  {1}%
  {0in}%
  {-\baselineskip}%
  {0.25\baselineskip}%
  {\raggedright\normalfont\bfseries\Large}}
\renewcommand{\subsection}{\@startsection
  {subsection}%
  {2}%
  {0in}%
  {-\baselineskip}%
  {0.25\baselineskip}%
  {\raggedright\normalfont\bfseries\large}}
\renewcommand{\subsubsection}{\@startsection
  {subsubsection}%
  {3}%
  {0in}%
  {-\baselineskip}%
  {0.25\baselineskip}%
  {\raggedright\normalfont\itshape\bfseries\large}}
\makeatother

% Custom headers/footers
\pagestyle{fancyplain}
\setlength{\headrulewidth}{0in}
\setlength{\footrulewidth}{0in}
\lhead[\fancyplain{}{\thepage}]{\fancyplain{}{\MakeUppercase{\rightmark}}}
\chead[\fancyplain{}{}]{\fancyplain{}{}}
\rhead[\fancyplain{}{\MakeUppercase{\leftmark}}]{\fancyplain{}{\thepage}}
\lfoot[\fancyplain{}{}]{\fancyplain{}{}}
\cfoot[\fancyplain{}{}]{\fancyplain{}{}}
\rfoot[\fancyplain{}{}]{\fancyplain{}{}}

\newcommand{\figurewidth}{4.375in}
\newcommand{\warnnotewidth}{4.375in}
\newcommand{\apirefdescwidth}{3in}

\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
 \makeatother

%
% Commands and environments
%

\newcommand{\gametitle}[1]{#1}
\newcommand{\ulink}[1]{\texttt{\protect #1}}
\newcommand{\website}[2]{#1\footnote{\ulink{\protect #2}}}
\newcommand{\firstterm}[1]{\textit{\protect #1}}
\newcommand{\filename}[1]{\textbf{\protect #1}}
\newcommand{\code}[1]{\texttt{\textbf{\protect #1}}}
\newcommand{\indexc}[1]{\index{#1@\code{#1}}}
\newcommand{\codei}[1]{\indexc{#1}\code{#1}}
\newcommand{\keysym}[1]{\textbf{#1}}
\newcommand{\cmdline}[1]{\texttt{\textbf{\protect #1}}}
\newcommand{\othertitle}[1]{\textsl{\protect #1}}
\newcommand{\booktitle}[1]{\textsl{\protect #1}}
\newcommand{\menucommand}[1]{\textbf{\protect #1}}
\newcommand{\cplusplus}{\letterspace to 0.85\naturalwidth {C++}}

% An external graphic scaled proportionally to the \figurewidth. \fwgraphic{filename}
\newcommand{\fwgraphic}[1]{\resizebox{\figurewidth}{!}{\includegraphics{#1}}}

% An external graphic of a spacified height. \shgraphic{filename}{height}
\newcommand{\shgraphic}[2]{\begin{center}\resizebox{!}{#2}{\includegraphics{#1}}\end{center}}

% Figure containing an external graphic (EPS probably). \extfigure{filename}{reftag}{caption}
\newcommand{\extfigure}[3]{\begin{figure}[t]\begin{center}\fwgraphic{#1}\textit{\caption{#3}\label{#2}}\end{center}\end{figure}}
\newcommand{\extfigureheight}[4]{\begin{figure}[t]\begin{center}\shgraphic{#1}{#4}\textit{\caption{#3}\label{#2}}\end{center}\end{figure}}
\newcommand{\extfiguren}[2]{\begin{figure*}[t]\begin{center}\fwgraphic{#1}\vspace{10pt}\par\textit{#2}\end{center}\end{figure*}}
\newcommand{\extfigureheightn}[3]{\begin{figure*}[t]\begin{center}\shgraphic{#1}{#3}\vspace{10pt}\par\textit{#2}\end{center}\end{figure*}}

% Warning and note environments. These are not floats. note takes one parameter, a caption
%\newenvironment{warning}{\begin{center}\begin{tabular}{p{\warnnotewidth}}\rowcolor[gray]{0.8}\begin{center}\large{Warning}\end{center} \\ \rowcolor[gray]{0.9}\small\raggedright}{\\ \end{tabular}\end{center}}

%\newenvironment{note}[1]{\begin{center}\begin{tabular}{p{\warnnotewidth}}\rowcolor[gray]{0.8}\begin{center}\large{#1}\end{center} \\ \rowcolor[gray]{0.9}\small\raggedright}{\\ \end{tabular}\end{center}}

%\newenvironment{warning}{%
%  \begin{center}%
%    \begin{tabular}{p{\warnnotewidth}}%
%      \centering\textbf{\large{Warning}}\vspace{0.5\baselineskip} \\%
%      \small\raggedright}%
%	       {\\ \end{tabular}\end{center}}
	       
%\newenvironment{note}[1]{%
%  \begin{center}%
%    \begin{tabular}{p{\warnnotewidth}}%
%      \centering\textbf{\large{#1}}\vspace{0.5\baselineskip} \\%
%      \small\raggedright}%
%	       {\\ \end{tabular}\end{center}}

\newenvironment{note}[1]
	       {%
		 \goodbreak%
		 \begin{center}%
		 \textbf{\large{#1}} \\%
		 \begin{list}{}{%
		     \setlength{\topsep}{0pt}%
		     \setlength{\leftmargin}{0.5in}%
		     \setlength{\rightmargin}{0.5in}%
		     \setlength{\listparindent}{\parindent}%
		     \setlength{\itemindent}{\parindent}%
		     \setlength{\parsep}{\parskip}%
		   }%
		   \small\raggedright%
		   \item[]%
	       }%
	       {%
		 \end{list}%
		 \end{center}%
		 \goodbreak%
	       }

\newenvironment{warning}{\begin{note}{Warning}}{\end{note}}

% API quick references

%\newenvironment{apiref} {\goodbreak\begin{center}\begin{tabular}{>{\columncolor[gray]{0.8}}r>{\columncolor[gray]{0.9}}p{4in}}\hline} {\hline \end{tabular}\end{center}\goodbreak}

\newenvironment{apiref} {%
  \goodbreak %
  \begin{list}{}{%
      \setlength{\rightmargin}{0.5in}%
      \setlength{\leftmargin}{1.25in}%
      \setlength{\labelwidth}{1.0in}%
      \setlength{\itemindent}{0in}%
      \setlength{\labelsep}{0.25in}%
      \setlength{\listparindent}{0in}%
      \setlength{\parsep}{0in}}}%
	       {\end{list}}

\newcommand{\apifunction}[1]{\item [\textbf{Function}] \code{#1}}
\newcommand{\apisynopsis}[1]{\item [\textbf{Synopsis}] #1}
\newcommand{\apireturns}[1]{\item [\textbf{Returns}] #1}
\newcommand{\apinextparm}[2]{\item [\code{#1}]---#2}
\newcommand{\apifirstparm}[2]{\item [\textbf{Parameters}] %
  \begin{list}{}{%
      \setlength{\itemindent}{0in}%
      \setlength{\labelsep}{0in}%
      \setlength{\labelwidth}{0in}%
      \setlength{\leftmargin}{0in}%
      \setlength{\rightmargin}{0in}}%
  \apinextparm{#1}{#2}}
\newcommand{\apiendparms}{\end{list}}

\newcommand{\structname}[1]{\item [\textbf{Structure}] \code{#1}}
\newcommand{\structsynopsis}[1]{\item [\textbf{Synopsis}] #1}
\newcommand{\structnextmember}[2]{\item [\code{#1}]---#2}
\newcommand{\structfirstmember}[2]{\item [\textbf{Members}] %
  \begin{list}{}{%
      \setlength{\itemindent}{0in}%
      \setlength{\labelsep}{0in}%
      \setlength{\labelwidth}{0in}%
      \setlength{\leftmargin}{0in}%
      \setlength{\rightmargin}{0in}}%
  \apinextparm{#1}{#2}}
\newcommand{\structendmembers}{\end{list}}


% An environment for shell sessions.
\newenvironment{shell}{\goodbreak\begin{list}{}{\leftmargin 0.15in\rightmargin 0in\itemindent 0in}\item\tt\small}{\end{list}\goodbreak}

% Code listings.
\newenvironment{codesegment}{\goodbreak\begin{list}{}{\leftmargin 0.15in\rightmargin 0in\itemindent 0in}\item\small}{\end{list}}

\newtheorem{codelistingt}{Code Listing}[chapter]
% \codelisting{filename}{label}
\newenvironment{codelisting}[2]{\goodbreak\begin{codelistingt}[\filename{#1}]\label{#2}\begin{codesegment}\noindent\par}{\end{codesegment}\end{codelistingt}}

% Margin adjustment
\newenvironment{changemargin}[2]{
  \begin{list}{}{%
      \setlength{\topsep}{0pt}%
      \setlength{\leftmargin}{#1}%
      \setlength{\rightmargin}{#2}%
      \setlength{\listparindent}{\parindent}%
      \setlength{\itemindent}{\parindent}%
      \setlength{\parsep}{\parskip}%
    }%
  \item[]}{\end{list}}

% General purpose lists (see the Lentry list on p64 of TLC).
\newlength{\foob}
\newcommand{\bodylistlabel}[1]{%
  \settowidth{\foob}{\textbf{#1}}%
  \ifthenelse{\lengthtest{\foob > \labelwidth}}%
	     {\parbox[b]{\labelwidth}%
	       {\makebox[0pt][l]{\textbf{#1}}\\}}%
	     {\textbf{#1}}%
	     \hfil\relax}

\newenvironment{bodylist} %
	       {%
		 \begin{list}%
		   {}%
		   {%
		     \renewcommand{\makelabel}{\bodylistlabel}%
		     \setlength{\labelwidth}{0.85in}%
		     \setlength{\leftmargin}{0.95in}%
		     \setlength{\itemindent}{0in}%
		     \setlength{\listparindent}{0in}%
		     \setlength{\labelsep}{0.1in}%
		     \setlength{\itemsep}{0.5\baselineskip}%
		   }%
	       }%
	       {%
	       \end{list}%
	       }

% Lists of files. Do not use \item.
\newenvironment{filelist}{\list{}{\leftmargin 1.0cm}\item\tt\small}{\endlist}

% Internet stuff.
\newcommand{\hostname}[1]{\code{#1}}
\newcommand{\ip}[1]{\code{#1}}

% Change the formatting of numbering.
\renewcommand{\thefigure}{\thechapter--\arabic{figure}}
\renewcommand{\thecodelistingt}{\thechapter--\arabic{codelistingt}}
\renewcommand{\thetable}{\thechapter--\arabic{table}}

% Generate an index.
\makeindex
\makeglossary

% Bibliography controls.
\bibliographystyle{plain}

% Mwahaha!
\index{SDL\_Gasbag@\code{SDL\_Gasbag}|see{Andy Mecham}}

\emergencystretch=0.3in

% Tweakage.
\newcommand{\shortpage}{\enlargethispage{-\baselineskip}}
\newcommand{\longpage}{\enlargethispage{\baselineskip}}


\title{Programming Linux Games}
\author{John R.\ Hall\\Loki Software, Inc.}

\begin{document}

\raggedright
\raggedbottom

\nocite{*}

\include{frontmatter}

\small
\tableofcontents
\normalsize

\frontmatter

\renewcommand{\chaptermark}[1]{\markboth{FOREWORD}{FOREWORD}}
\renewcommand{\sectionmark}[1]{{}{}}

\include{foreword}

\renewcommand{\chaptermark}[1]{\markboth{PREFACE}{PREFACE}}
\renewcommand{\sectionmark}[1]{{}{}}

\include{preface}

\mainmatter

\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter}{#1}}
\renewcommand{\sectionmark}[1]{{}{}}

\include{game-anatomy}
\include{linux-development-tools}
\include{gaming-apis}
\include{mastering-sdl}
\include{linux-audio}
\setcounter{chapter}{5}
\include{game-scripting}
\include{game-networking}
\include{linux-fbcon}
\include{finishing-pw}
\include{game-install}

\backmatter

\renewcommand{\chaptermark}[1]{\markboth{GLOSSARY}{GLOSSARY}}
\renewcommand{\sectionmark}[1]{{}{}}

\include{glossary}
\bibliography{main}
\printindex

\end{document}
