\usepackage{geometry}
\geometry{
	inner=25mm,
	outer=20mm,
	marginparsep=3mm,
	marginparwidth=13mm,
	top=25mm,
	bottom=20mm,
	paperwidth=17cm,
	paperheight=24cm,
}
\usepackage{pdflscape}

\usepackage{fancyhdr} % Custom headers and footers
\usepackage[fit]{truncate}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\setlength{\unitlength}{18mm}
\newcommand{\blob}{{\color{gray}\rule[-.2\unitlength]{2\unitlength}{.5\unitlength}}}
\fancyhead[RE]{\truncate{.95\headwidth}{\rightmark}}
\fancyhead[LO]{\truncate{.95\headwidth}{\leftmark}}
\newcommand{\frontmatterfancy}[0]{
	\fancyhead[RO]{\thepage}
	\fancyhead[LE]{\thepage}
}
\newcommand{\mainmatterfancy}[0]{
	\fancyhead[RO]{
		\thepage%
		\begin{picture}(0,0)
			\put(1,-\value{chapter}){\blob}
		\end{picture}
	}
	\fancyhead[LE]{
		\begin{picture}(0,0)
			\put(-3,-\value{chapter}){\blob}
		\end{picture}%
		\thepage%
	}
}
\newcommand{\backmatterfancy}[0]{
	\fancyhead[RO]{
		\thepage%
		\begin{picture}(0,0)
			\put(1,-1){\blob}
		\end{picture}
	}
	\fancyhead[LE]{
		\begin{picture}(0,0)
			\put(-3,-1){\blob}
		\end{picture}%
		\thepage%
	}
}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
%\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\chaptername}\ \thechapter.\ #1}{}}
%\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage{etoolbox} % To patch the chapter command
% Have better page numbering in chapters
\patchcmd{\chapter}{plain}{headings}{}{}
\usepackage{epigraph} % Epigraph
\renewcommand\partname{Episode}                   % Rename parts to episodes (rhapsody uhu)
\addto\captionsbritish{\renewcommand{\partname}{Episode}}
\usepackage{titlesec}
\titleformat{\part}[block]
	{\Huge}
	{\partname~\thepart:}
	{20pt}
	{}

% This is required to make \nameref work (https://tex.stackexchange.com/questions/211035/problems-with-nameref-not-refering-to-the-correct-label-x-titlesec)
\makeatletter
\let\titlesec@part\part%
\renewcommand{\part}{\@ifstar\part@star\part@nostar}
\def\part@star#1{\NR@gettitle{#1}\titlesec@part*{#1}}
\def\part@nostar{\@ifnextchar[\part@nostar@opt\part@nostar@nopt} % chktex 9
\def\part@nostar@nopt#1{\NR@gettitle{#1}\titlesec@part{#1}}
\def\part@nostar@opt[#1]#2{\NR@gettitle{#1}\titlesec@part[#1]{#2}}
\makeatother

% Colored frames
\usepackage{framed}
\definecolor{lstbg}{gray}{.95}
\definecolor{shadecolor}{named}{lstbg}
\newenvironment{chapterabstract}{\begin{shaded}\begin{quotation}}{\end{quotation}\end{shaded}} %chktex 6

% Increase the depth for the table of contents
\setcounter{secnumdepth}{3}
\renewcommand{\contentsname}{Table of Contents} % change the name of the TOC
\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{empty}}} % to remove page numbering from the TOC

% Custom enumerations
\usepackage[inline,shortlabels]{enumitem}
\setlist{noitemsep}
\setlist[description]{leftmargin=\parindent}

% Custom floats
\usepackage{float}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
	fileext=loq,
	listname={List of definitions},
	name=Definition,
	placement=tbp,
	within=chapter,
	chapterlistsgaps=on,
	]{equ}

% chapterappendices
\usepackage{appendix}
