% ================
% = Layout Setup =
% ================
% see http://ftp.snt.utwente.nl/pub/software/tex/macros/latex/contrib/memoir/memman.pdf

\setstocksize{221mm}{138mm} 		% Page Setup: 3 en 6mm afloop, zoals Word template
\settrimmedsize{215mm}{135mm}{*} 	% Page Size: A5 (\pageav)
\settrims{0mm}{0mm} 				% Zit in de stock size
\settypeblocksize{180mm}{100mm}{*}
%\setpagecc{\paperheight}{\paperwidth}{*} % centers page on stock (trimmings in middle) - NIET nodig, geen A5 op A4 meer

\setlrmargins{*}{17mm}{*} % Horizontal margin. spine, edge, ratio. Spine gets most, auto-calculated.
\setulmargins{*}{20mm}{*}  % Vertical   margin. upper, lower, ratio. 

\setheadfoot{\baselineskip}{2\baselineskip} % headheight and footskip
\setheaderspaces{0.5in}{*}{*} % headdrop, headsep, and ratio

\checkandfixthelayout


% ===========================
% = Paragraph/Content Setup =
% ===========================
% paragraph indentation
\usepackage{parskip}
\setlength{\parindent}{15pt}

% for itemization, other symbol - labelitemii, iii, iv, ... kan ook
\renewcommand{\labelitemi}{$\circ$}

% starbreak: only add if at beginning of new page. MD: just '* * *'
\newcommand{\starbreak}{%
    \fancybreak{* * *}%
}
\DeclareRobustCommand{\cs}[1]{\texttt{\char`\\#1}}
\newlength{\tpheight}\setlength{\tpheight}{0.9\textheight}
\newlength{\txtheight}\setlength{\txtheight}{0.9\tpheight}
\newlength{\tpwidth}\setlength{\tpwidth}{0.9\textwidth}
\newlength{\txtwidth}\setlength{\txtwidth}{0.9\tpwidth}
\newlength{\drop}


% =============================
% = Footer/header/index Setup =
% =============================
\makepagestyle{desem}
\createmark{chapter}{left}{nonumber}{}{}	% remove 'chapter x:' from \leftmark
% args: hstylei, hlefti, hcenteri, hrighti
\makeevenfoot{desem}{\textsf{\textcolor{lightgray}{\footnotesize \textbf{\thepage} \: | \: RED ZUURDESEM}}}{}{} 
\makeoddfoot{desem}{}{}{\textsf{\textcolor{lightgray}{\footnotesize \leftmark \: | \: \textbf{\thepage}}}}
\copypagestyle{plain}{desem}
\copypagestyle{part}{empty}
\AtBeginDocument{\addtocontents{toc}{\protect\thispagestyle{empty}}} 

% footnotes: one per page (needs re-compilation, could crash first time) and symbols
\usepackage{perpage}
\MakePerPage{footnote}
\renewcommand*{\thefootnote}{\fnsymbol{footnote}}


% ===================
% = Font/Text Setup =
% ===================
\usepackage{tcolorbox}
\usepackage{etoolbox}
\usepackage{fontspec}
\usepackage{mathpazo}
\setmainfont
     [ BoldFont       = texgyrepagella-bold.otf ,
       ItalicFont     = texgyrepagella-italic.otf ,
       BoldItalicFont = texgyrepagella-bolditalic.otf ]
     {texgyrepagella-regular.otf}
% for Japanese chars
\usepackage{xeCJK}
\setCJKmainfont[BoldFont=STHeiti,ItalicFont=STKaiti]{STSong}


% ================
% = Images Setup =
% ================
% for png/pdf inclusion (pdfpages: full-page)
\usepackage{graphicx}
\graphicspath{{img/}}

\usepackage{wrapfig}    % inline l/r
\usepackage{subcaption} % subfigure
\usepackage{calc}		% for adjustimg cmd calculations
\usepackage{changepage} % full-page 
\newcommand{\adjustimg}{% Horizontal adjustment of image
  \checkoddpage%
  \ifoddpage\hspace*{\dimexpr\evensidemargin-\oddsidemargin}\else\hspace*{-\dimexpr\evensidemargin-\oddsidemargin}\fi%
}
\newcommand{\centerimg}[2][width=\textwidth]{% Center an image
  \makebox[\textwidth]{\adjustimg\includegraphics[#1]{#2}}%
}
% \usepackage{pdfpages} % for fullpage png/pdf includes

% figure caption styles - http://www.peteryu.ca/tutorials/publishing/latex_captions
\usepackage[skip=4pt,font=small]{caption}
\captionsetup[figure]{labelformat=empty, labelsep=colon, labelfont=bf, textfont={it}}
\captionsetup[table]{labelformat=empty, labelsep=colon, labelfont=bf, textfont={it}}
\renewcommand{\thefigure}{\thechapter.\Alph{figure}} % set caption label style to 1.A
\renewcommand{\thetable}{\thechapter.\Alph{figure}} % set caption label style to 1.A

% remove figure & table numbers from list of figures
\makeatletter
\renewcommand{\cftfigurepresnum}{\begin{lrbox}{\@tempboxa}}
\renewcommand{\cftfigureaftersnum}{\end{lrbox}}
\renewcommand{\cfttablepresnum}{\begin{lrbox}{\@tempboxa}}
\renewcommand{\cfttableaftersnum}{\end{lrbox}}
\makeatother
\setlength{\cftfigurenumwidth}{0pt}
\setlength{\cfttablenumwidth}{0pt}


% ==================
% = Chapter Styles =
% ==================
% hoofdstuk header style ( - 1 -, naam HF)
% to add subtitle to \maketitle
\makeatletter
\providecommand{\subtitle}[1]{
  \apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother

\chapterstyle{dash}\renewcommand*{\chaptitlefont}{\normalfont\itshape\LARGE}
\setlength{\beforechapskip}{2\onelineskip}
\setsecheadstyle{\normalfont\Large\raggedright}
