%% LaTeX preamble.

\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=2cm]{geometry}
\usepackage{setspace}
\usepackage{emerald}
\usepackage{type1cm}
\usepackage{lettrine}
\usepackage{titlesec}

%% Set up page.
\pagestyle{empty}
\pagenumbering{roman}
\thispagestyle{fancy}

\renewcommand\thepage{\roman{page}}
\newcommand\pagefoot{\thepage}

%% Set various lengths.
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}

%% Set section numbering depth.
\setcounter{secnumdepth}{0}

%% Add page break before each section.
\newcommand{\sectionbreak}{\clearpage}

%% Revert to original table of contents.
\makeatletter
\renewcommand{\tableofcontents}{\py@OldTableofcontents}
\makeatother

%% Avoid too-deepy-nested problems.
\usepackage{enumitem}
\setlistdepth{99}

%% Covering page.
\def\coverpage{
    \begin{titlepage}
    \centering
    \textbf{\Huge ${title}}\par
    \vspace{0.5cm}
    \textbf{\LARGE ${author}}\par
    \vspace{2cm}
    \includegraphics[width=\textwidth]{${image}}\par
    \vspace{2cm}
    \textit{\large ${edition}}\par
    \vspace{0.5cm}
    \textbf{\large ${extra}}\par
    \vfill
    \end{titlepage}
    \newpage
}

%% License page
\def\licensepage{
    \pagestyle{plain}
    ${title}

    Authors: ${author}\par
    Editor: ${editor}\par

    Cover: \textit{${imagetitle}} ${imageinfo}

    ${licensetext}
    \newpage
}

%% History page.
\def\historypage{
    \pagestyle{plain}

    \huge \textbf{Release history} \normalsize
    \vspace{3em}

    \begin{tabular}{|l|l|l|}
    \hline
    First Edition	& April 2002	& \\
    \hline
    Second Edition	& August 2002	& Minor revisions \\
    \hline
    Third Edition	& August 2004	& Alignment with Inform 6.30 \\
			&		& Further minor revisions \\
    \hline
    \end{tabular}
    \newpage
}

%% Contents page.
\def\contentspage{
    \pagestyle{plain}
    \tableofcontents
}

%% Main text.
\def\maintext{
    \pagestyle{headings}
    \pagenumbering{arabic}
    \renewcommand\thepage{\arabic{page}}
    \setcounter{page}{1}
}

%% Start the main chapter text.
\def\startchapters{
    \setcounter{secnumdepth}{1}
}

%% Start the appendices
\def\startappendices{
    \setcounter{secnumdepth}{0}
}

%% Disable standard title (but keep PDF info).
\renewcommand{\maketitle}{
  \ifsphinxpdfoutput
    \begingroup
    % These \defs are required to deal with multi-line authors; it
    % changes \\ to ', ' (comma-space), making it pass muster for
    % generating document info in the PDF file.
    \def\\{, }
    \def\and{and }
    \pdfinfo{
      /Title (${title})
      /Author (${author})
    }
    \endgroup
  \fi
}

%% Fix up index and references.
\makeatletter

\renewcommand{\theindex}{
  \newpage
  \phantomsection
  \py@OldTheindex
  \addcontentsline{toc}{section}{Index}
}

\renewcommand{\thebibliography}[1]{
  \newpage
  \phantomsection
  \py@OldThebibliography{1}
  \addcontentsline{toc}{section}{References}
}

\makeatother

%% For picture alphabet drop caps
\newcommand{\dropcap}[1]{\lettrine[lines=3]{\ECFAPicture{\fontsize{50}{60}\selectfont #1}\normalfont}{}}
