%% prefer than direct use in usepackage geometry
%% A4 layout in point is % 595x842

%% default value
\setlength{\hoffset}{0pt}
\setlength{\voffset}{0pt}

%% height
%% 72 - 60 + 20 + 25 = 57
\setlength{\topmargin}{-60pt}
\setlength{\headheight}{20pt}
\setlength{\headsep}{25pt}

\setlength{\footskip}{30pt}

%% width
%% 72 + 32 + 10 = 114pt = 40mm
\setlength{\oddsidemargin}{32pt}
\setlength{\evensidemargin}{32pt}
\setlength{\marginparsep}{10pt}

%% size text
\setlength{\textheight}{728pt}
\setlength{\textwidth}{425pt}

%% style
%% preliminary, just roman pagination + empty header
\fancypagestyle{preliminary}{
    \renewcommand{\headrulewidth}{0pt}
    \fancyhead[RCL]{}

    \pagenumbering{Roman}
}
%% chapter/classic text style
\fancypagestyle{chapter}{
    %% title of the chapter, left header, no uppercase, 10 pt, italics, no bold
    \fancyhead[L]{\normalfont\itshape\fontsize{10pt}{12pt}\selectfont\nouppercase{\leftmark}}
    \fancyhead[R]{}

    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0pt}
    \pagenumbering{arabic}
}

%% define length and scaling for baseline
\newcommand{\headingBaseline}{12}
\newcommand{\headingBaselineDiv}{10}
\newlength{\chapterFontSize}
\newlength{\sectionFontSize}
\newlength{\subsectionFontSize}
\newlength{\chapterBaseline}
\newlength{\sectionBaseline}
\newlength{\subsectionBaseline}

%% change those value if you want to change the chapter/section/subsection font size
\setlength{\chapterFontSize}{14pt}
\setlength{\sectionFontSize}{12pt}
\setlength{\subsectionFontSize}{12pt}

%% automatic computation for baseline, rule of thumb is 1.2
\setlength{\chapterBaseline}{ \chapterFontSize * \headingBaseline / \headingBaselineDiv}
\setlength{\sectionBaseline}{ \sectionFontSize * \headingBaseline / \headingBaselineDiv}
\setlength{\subsectionBaseline}{ \subsectionFontSize * \headingBaseline / \headingBaselineDiv}


%% headings
%% Chapter, 14-point, bold
\titleformat{\chapter}[display]
    {\normalfont\bfseries\fontsize{\chapterFontSize}{\chapterBaseline}\selectfont}{\chaptertitlename\ \thechapter}{14pt}{}
%% capitalised initial letter,
% \titleformat{\chapter}[display]
%     {\normalfont\bfseries\fontsize{\chapterFontSize}{\chapterBaseline}\selectfont}{\chaptertitlename\ \thechapter}{14pt}{\capitalisewords}
%% left|above|below
\titlespacing{\chapter}{0pt}{10pt}{25pt}

%% Section, 12-point
\titleformat{\section}[hang]
    {\normalfont\bfseries\fontsize{\sectionFontSize}{\sectionBaseline}\selectfont}{\thesection}{5pt}{}
%% capitalised  initial letter
% \titleformat{\section}[hang]
%     {\normalfont\bfseries\fontsize{\sectionFontSize}{\sectionBaseline}\selectfont}{\thesection}{5pt}{\capitalisewords}
%% left|above|below
\titlespacing{\section}{0pt}{25pt}{15pt}

%% Subsection, 12-point, italic
\titleformat{\subsection}[hang]
    {\normalfont\bfseries\itshape\fontsize{\subsectionFontSize}{\subsectionBaseline}\selectfont}{\thesubsection}{5pt}{}
% \titleformat{\subsection}[hang]
%     {\normalfont\bfseries\itshape\fontsize{\subsectionFontSize}{\subsectionBaseline}\selectfont\MakeLowercase}{\thesubsection}{5pt}{\makefirstuc}
%% left|above|below
\titlespacing{\subsection}{0pt}{20pt}{10pt}

%% table of content
\renewcommand{\contentsname}{Table of Contents}
\setcounter{tocdepth}{2} 
\setcounter{secnumdepth}{2}

%% list of figure
\renewcommand*\listfigurename{Figure table}

%% init gloassaries
%% noidx cause otherwise we have to do a normal glossary, compile, then remove it so it is cached
%% because we only use acronym
\makenoidxglossaries

%% bibliography config
%% https://tex.stackexchange.com/a/6977
\DeclareBibliographyCategory{cited}
\AtEveryCitekey{\addtocategory{cited}{\thefield{entrykey}}}
\addbibresource{Bibliography.bib}
\addbibresource{BibMine.bib}
\addbibresource{references.bib}

%% hyperref setup
\hypersetup{
    colorlinks = true,
    linkcolor = blue, % normal internal links, like ref, can be black tbh
    citecolor = blue, % bibliographical links
    urlcolor = blue, % linked urls
    filecolor = black % url which open local files
}

%% modified reference function
%% https://tex.stackexchange.com/a/438998
\newcommand\eref[1]{equation~(\ref{#1})}
\newcommand\tref[1]{table~\ref{#1}}
\newcommand\fref[1]{figure~\ref{#1}}

%% 1.5 line spacing
\setstretch{1.5}