% Typography
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Adobe Caslon Pro}
\setsansfont{Myriad Pro}
\setmonofont[Scale=MatchLowercase]{Menlo}
\usepackage{microtype}
\usepackage{setspace}
\usepackage{csquotes}

% Colors, links, syntax highlighting
\usepackage[dvipsnames,table]{xcolor}
\usepackage[pagebackref]{hyperref}
\hypersetup{
    pdftitle={Crypto 101},
    pdfauthor={Laurens Van Houtven (lvh)},
    colorlinks,
    linkcolor=Sepia,
    citecolor=Periwinkle
}
\usepackage{minted}
\usepackage[acronym,toc]{glossaries}
\include{Glossary}
\makeglossaries
\usepackage{makeidx}
\makeindex

% Localization
\usepackage{polyglossia}
\setdefaultlanguage{english}

% Mathematical symbols
%% \usepackage{savesym}
%% \savesymbol{iint}
%% \savesymbol{iiint}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand\xor{\oplus}

% Advanced command definitions
\usepackage{xparse}

% Figures and subfigures
\usepackage{float}
\usepackage{rotating}
\usepackage{subcaption}
\usepackage{array}
\usepackage{calc}
\usepackage{framed}
\usepackage{wrapfig}
\usepackage{longtable}
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}
\usepackage[export]{adjustbox}

% Fancy figure command
\DeclareDocumentCommand{\illustration}{
   m     % sub-path to illustration, /Illustrations/{this}.pdf, mandatory
   O{.8} % width as fraction of line width, optional
   o     % caption, optional
   o     % label, optional
  }{
  \begin{figure}[ht!]
    \centering
    \includegraphics[width=#2\linewidth]{./Illustrations/#1.pdf}
    \IfValueTF{#3}{\caption{#3}}{}
    \IfValueTF{#4}{\label{#4}}{}
  \end{figure}
}

% Special subsection commands
\definecolor{shadecolor}{HTML}{AABAD1}
\DeclareDocumentCommand{\advanced}{
   o     % extra caption, optional
  }{
  \begin{shaded}
      \begin{wrapfigure}{l}{.2\linewidth}
          \vspace{-8pt}
          \includegraphics[width=\linewidth]{./Illustrations/Propeller/Propeller.pdf}
      \end{wrapfigure}

      \noindent This is an optional, in-depth section. It almost
      certainly won't help you write better software, so feel free to
      skip it. It is only here to satisfy your inner geek's curiosity.

      \IfValueTF{#1}{#1}{}
  \end{shaded}
}

% Chapter markup
\usepackage{tikz, blindtext}
\makechapterstyle{box}{
  \renewcommand*{\printchaptername}{}
  \renewcommand*{\printchapternum}{
    \flushright
    \begin{tikzpicture}
      \draw[fill,color=black] (0,0) rectangle (2cm,2cm);
      \draw[color=white] (1cm,1cm) node { \chapnumfont\thechapter };
    \end{tikzpicture}
  }
  \renewcommand*{\printchaptertitle}[1]{\flushright\chaptitlefont##1}
}
\chapterstyle{box}

% Title page markup
\usepackage{geometry}
\usepackage{titlesec}
\makeatletter
\newlength\drop
\renewcommand{\maketitle}{
  \thispagestyle{empty}
  \begingroup
  \drop = 0.1\textheight
  \vspace*{\baselineskip}
  \vfill
  \hbox{%
    \hspace*{0.2\textwidth}%
    \rule{1pt}{\dimexpr\textheight-28pt\relax}%
    \hspace*{0.05\textwidth}%
    \parbox[b]{0.75\textwidth}{%
      \vbox{%
        \vspace{\drop}
               {\Huge\bfseries\raggedright\@title\par}\vskip2.37\baselineskip
               {\Large\bfseries\@author\par}
               \vspace{0.5\textheight}
      }% end of vbox
    }% end of parbox
  }% end of hbox
  \vfill
  \null
  \endgroup

  \thispagestyle{plain}
  \par
  \noindent
  Copyright 2013-2014, Laurens Van Houtven

  \noindent
  This book is made possible by your donations. If you enjoyed it,
  please consider making a donation, so it can be made even better and
  reach even more people.

  \noindent
  This work is available under the Creative Commons
  Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license.
  You can find the full text of the license
  at \url{https://creativecommons.org/licenses/by-nc/4.0/}.

  \begin{center}
    \includegraphics{./Illustrations/CC/CC-BY-NC.pdf}
  \end{center}

  \noindent
  The following is a human-readable summary of (and not a substitute
  for) the license. You can:

  \begin{itemize}
  \item Share: copy and redistribute the material in any medium or format
  \item Adapt: remix, transform, and build upon the material
  \end{itemize}

  The licensor cannot revoke these freedoms as long as you follow the
  license terms:

  \begin{itemize}
  \item Attribution: you must give appropriate credit, provide a link
  to the license, and indicate if changes were made. You may do so in
  any reasonable manner, but not in any way that suggests the licensor
  endorses you or your use.
  \item NonCommercial: you may not use the material for commercial
  purposes.
  \item No additional restrictions: you may not apply legal terms or
  technological measures that legally restrict others from doing
  anything the license permits.
  \end{itemize}

  You do not have to comply with the license for elements of the
  material in the public domain or where your use is permitted by an
  applicable exception or limitation.

  No warranties are given. The license may not give you all of the
  permissions necessary for your intended use. For example, other
  rights such as publicity, privacy, or moral rights may limit how you
  use the material.

 \clearpage

 \thispagestyle{plain}
 \par
 \vspace*{.3\textheight}{
   \centering
   \emph{Pomidorkowi}
   \par
   \clearpage
 }
}
\makeatother
