\ProvidesPackage{unnamedgoodbook}
% use pdflatex

% Packages
\RequirePackage{babel}
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[all]{xy}
\RequirePackage{mathtools}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{amsthm}
\RequirePackage{alltt}
\RequirePackage{fullpage}
\RequirePackage{ulem}
\RequirePackage{fancyhdr}
\RequirePackage{lastpage}
\RequirePackage{hyperref}
\RequirePackage{graphicx}
\RequirePackage{float}
\RequirePackage{wrapfig}
\RequirePackage{subfig}
\RequirePackage{csquotes}
\RequirePackage{lmodern}
\RequirePackage{inconsolata}
\RequirePackage{minted}
\RequirePackage{tikz}
\RequirePackage{pdfpages}
\RequirePackage[style=authoryear]{biblatex}

\let\omaketitle\maketitle
\renewcommand{\maketitle}{
\let\localtitle\@title
\let\localauthor\@author
\let\localdate\@date
\omaketitle
\let\@title\localtitle
\let\@author\localauthor
\let\@date\localdate
}

% Colors
\definecolor{Black}{gray}{0}
\definecolor{White}{gray}{1}
\definecolor{front}{RGB}{198,255,25}
\definecolor{back}{RGB}{255,25,57}

% Hyperref details
\newcommand{\email}[1]{\href{mailto:#1}{\nolinkurl{#1}}}
\newcommand{\dohypersetup}{
  \hypersetup{
    pdftitle={\@title},
    pdfauthor={\@author},
    pdfsubject={Book},
    colorlinks=true,
    linkcolor=Black,   % color of internal links
    citecolor=Black,   % color of links to bibliography
    urlcolor=Black     % color of external links
  }
}


% Basic style
\setlength{\parindent}{4mm}
\setlength{\parskip}{0.5mm}
\setlength{\marginparsep}{0mm}
\setlength{\marginparwidth}{0mm}
\setlength{\textwidth}{125mm}
\setlength{\footskip}{12mm}
\setlength{\topmargin}{0mm}
\setlength{\textheight}{178mm}
\setlength{\headsep}{2mm}
\setlength{\headheight}{2mm}

\newcommand{\bgstyle}{
\setlength{\hoffset}{-.8mm}
\setlength{\voffset}{0mm}
}
\newcommand{\normstyle}{
\setlength{\hoffset}{-13mm}
\setlength{\voffset}{-19mm}
}
\normstyle

% Fancy headers and footers
\fancyhf{}
\pagestyle{fancy}
\newcommand{\doheaderfootersetup}{
  \chead{}
  \lhead{}
  \rhead{}
  \cfoot{}
  \lfoot[\small\textbf{\emph{\thepage\hspace{1cm}\@author}}]{}
  \rfoot[]{\small\textbf{\emph{\@title\hspace{1cm}\thepage}}}
}

\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\newcommand{\setupdocument}{
  \dohypersetup
  \doheaderfootersetup
}

\newcommand{\adjustdocument}{
  \fancypagestyle{plain}{} % fancyhdr on all pages
  \normalem % ulem
  \small
}

\newcommand{\newchapter}[1]{
\newpage
\null
\section*{\colorbox{black}{\textcolor{white}{#1}\hspace{7cm}}}
}

\let\ochapter\chapter
\renewcommand{\chapter}[1]{\newchapter{#1}}

\newcommand{\emptypage}{
  \newpage
  \thispagestyle{empty}
  \mbox{}
}

\newcommand{\Fullsection}[1]{
  #1\vspace{1.8mm}
}

% Define text for copying conditions
\newcommand{\insertcopying}{

  \begin{wrapfigure}{r}{48mm}
    \includegraphics[width=28mm]{img/by-sa.pdf}
  \end{wrapfigure}

  \noindent \textbf{\@title}\hspace{3mm}\\[1mm]
  \footnotesize
  \noindent Copyright \copyright\ \@date\ \@author\\[1mm]

  \begin{minipage}[1cm]{10cm}
    This book is available under the terms of the Creative Commons
    Attribution-Share Alike 3.0 (or any later version) Unported license. To
    view a copy of this license, visit the link below or send a letter to
    Creative Commons, 444 Castro Street, Suite 900, Mountain View, California,
    94041, USA.

    The book is typeset with the fonts Utopia and Inconsolata. Both fonts are
    free.
  \end{minipage}

\begin{description}
\item[Creative Commons Attribution-Share Alike 3.0 Unported] \hfill \\
  \url{http://creativecommons.org/licenses/by-sa/3.0/}
\item[Inconsolata] \hfill \\
  \url{http://www.levien.com/type/myfonts/inconsolata.html}
\item[Utopia] \hfill \\
  \url{http://tug.org/fonts/utopia/LICENSE-utopia.txt}
\item[Online version] \hfill \\
  \url{http://metanohi.name/writings/ugs/}
\end{description}
}

% Modified titlepage
\renewcommand{\maketitle} {
\pagestyle{empty}
\begin{titlepage}
\pagecolor{front}{
\begin{center}
\includegraphics[keepaspectratio, width=\textwidth, height=.99\textheight]
{img/title.pdf}
\end{center}}
\newpage
\pagecolor{white}
\insertcopying
\end{titlepage}
\setcounter{page}{1}
\pagestyle{fancy}
}

\newcommand{\makebacktitle}[1] {
\newpage
\pagestyle{empty}
\pagecolor{back}{
\begin{center}
\includegraphics[keepaspectratio, width=\textwidth, height=.99\textheight]
{img/backtitle.pdf}
\end{center}}
}