\hfuzz=15pt
\emergencystretch=1em
\usepackage{fvextra}
\usepackage{csquotes}
\usepackage[english]{babel}
\usepackage{hyperref}
\hypersetup{bookmarksnumbered}
\usepackage{xspace}
\usepackage{multicol}

% Fonts
\usepackage{fontspec}
%% Main font
\setmainfont{IBMPlexSerif}[
  Path=assets/fonts/IBM-Plex-Serif/,
  Extension=.otf,
  UprightFont=*-Text,
  BoldFont=*-Bold,
  ItalicFont=*-TextItalic,
  BoldItalicFont=*-BoldItalic,
]
%% Title font
\newfontfamily{\ibmplexsanscondensed}{IBMPlexSansCondensed}[
  Path=assets/fonts/IBM-Plex-Sans-Condensed/,
  Extension=.otf,
  UprightFont=*-Text,
  BoldFont=*-Bold,
  ItalicFont=*-TextItalic,
  BoldItalicFont=*-BoldItalic,
]
\newfontfamily{\satisfyfont}{Satisfy}[
  Path=assets/fonts/Satisfy/,
  Extension=.ttf,
  UprightFont=*-Regular,
]
%% Monospace font
\setmonofont{IBMPlexMono}[
  Ligatures=TeX,
  Path=assets/fonts/IBM-Plex-Mono/,
  Extension=.otf,
  UprightFont=*-Text,
  BoldFont=*-Bold,
  ItalicFont=*-TextItalic,
  BoldItalicFont=*-BoldItalic,
]
%% Mathmatical font
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{unicode-math}

% Algorithms
\usepackage[ruled,vlined,algochapter]{algorithm2e}

% References
\usepackage[
  style=apa,
	backend=biber,
]{biblatex}
\DeclareLanguageMapping{australian}{english-apa}
\usepackage[noabbrev]{cleveref}

% Tables
\usepackage{booktabs}

% Glossary / Acronyms
\usepackage[acronym,toc]{glossaries}
\glsdisablehyper % Comment for debugging
\usepackage[stylemods=bookindex]{glossaries-extra}
\usepackage{titlecaps}
\setabbreviationstyle[acronym]{long-short}
\defglsentryfmt[main]{\ifglsused{\glslabel}{\glsgenentryfmt}{\textit{\glsgenentryfmt}}}
\makeglossaries{}

% Graphics
\usepackage{graphicx}
\usepackage{subcaption}

% % TODO: What am I doing with this?
\newcommand*\justify{%
  \fontdimen2\font=0.4em% interword space
  \fontdimen3\font=0.2em% interword stretch
  \fontdimen4\font=0.1em% interword shrink
  \fontdimen7\font=0.1em% extra space
  \hyphenchar\font=`\-% allowing hyphenation
}

\newcommand{\Vlabel}[1]{\label[line]{#1}\hypertarget{#1}{}}
\newcommand{\lref}[1]{\FancyVerbLineautorefname~\hyperlink{#1}{\ref*{#1}}}
\newcommand{\Lref}[1]{\titlecap{\FancyVerbLineautorefname}~\hyperlink{#1}{\ref*{#1}}}
\newcommand{\lrefrange}[2]{\FancyVerbLineautorefname{}s~\hyperlink{#1}{\ref*{#1}}--\hyperlink{#2}{\ref*{#2}}}
\newcommand{\Lrefrange}[2]{Lines~\hyperlink{#1}{\ref*{#1}}--\hyperlink{#2}{\ref*{#2}}}

% Proof Tree
\usepackage[nounderscore]{syntax}
\setlength{\grammarindent}{8em}
\usepackage{ebproof}

% Comments
\newcommand{\todo}[1]{\textcolor{red}{\Big[\textbf{TODO}: #1\Big]}}

% Example environment
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheoremstyle[
  headfont=\usekomafont{disposition},
  spaceabove=1em plus 0.75em minus 0.25em,
	numberwithin=chapter,
  bodyfont=\normalfont,
	headformat=†~\NAME~\NUMBER\NOTE,
	headpunct={:},
	postheadspace=2em,
	qed={\ibmplexsanscondensed{}\textbf{‡}},
  spacebelow=1em plus 0.75em minus 0.25em,
]{exmpstyle}

\declaretheorem[
  style=exmpstyle,
  title=Example,
  refname={example,examples},
  Refname={Example,Examples}
]{example}

% Code formatting
\usepackage[
  chapter,
  cachedir=listings,
  outputdir=latex.out,
]{minted}
\usemintedstyle{borland}

\usepackage[many]{tcolorbox}
\newtcolorbox{listingbox}[1][]{
  breakable,
  enhanced,
  arc=0pt,
  boxrule=0pt,
  outer arc=0pt,
  overlay first={
      \draw[#1] (frame.north west) -- ++ (0,-5pt);
      \draw[#1] (frame.north west) -- ++ (25pt, 0pt);
    },
  overlay last={
      \draw[#1] (frame.south west) -- ++ (0, 5pt);
      \draw[#1] (frame.south west) -- ++ (25pt,0pt);
    },
  overlay  unbroken={
      \draw[#1] (frame.north west) -- ++ (0,-5pt);
      \draw[#1] (frame.north west) -- ++ (25pt, 0pt);
      \draw[#1] (frame.south west) -- ++ (0, 5pt);
      \draw[#1] (frame.south west) -- ++ (25pt,0pt);
    },
  colback=white,
  colframe=white,
}
\BeforeBeginEnvironment{minted}{\begin{listingbox}}
    \AfterEndEnvironment{minted}{\end{listingbox}}

\newcommand{\ptinline}[1]{{\texttt{\small {#1}}}}

\newcommand{\pyfile}[1]{\inputminted[autogobble=true,breaklines,breakindent=4em,numbers=left,escapeinside=@@,fontsize=\scriptsize,tabsize=2]{python}{#1}}

\newcommand{\mznfile}[1]{\inputminted[autogobble=true,breaklines,breakindent=4em,numbers=left,escapeinside=@@,fontsize=\scriptsize,tabsize=2]{minizinc}{#1}}
\newcommand{\mzninline}[1]{\mintinline[fontsize=\small,escapeinside=@@]{minizinc}{#1}}
\newenvironment{mzn}{\VerbatimEnvironment{}\begin{minted}[
  autogobble=true,
  breaklines,
  breakindent=4em,
  numbers=none,
  escapeinside=@@,
  fontsize=\scriptsize,
	tabsize=2,
]{minizinc}}{\end{minted}}


% TODO: Fix the nanozinc sytax highlighting/formatting
\newcommand{\nzninline}[1]{\mintinline[fontsize=\small,escapeinside=@@]{minizinc}{#1}}
\newenvironment{nzn}{\VerbatimEnvironment{}\begin{minted}[
  autogobble=true,
  breaklines,
  breakindent=4em,
  numbers=none,
  escapeinside=@@,
  fontsize=\scriptsize,
	tabsize=2,
]{minizinc}}{\end{minted}}

\newenvironment{plain}{\VerbatimEnvironment{}\begin{minted}[
  autogobble=true,
  breaklines,
  breakindent=4em,
  numbers=none,
  % escapeinside=@@,
  fontsize=\scriptsize,
	tabsize=2,
]{text}}{\end{minted}}

\newcommand{\amplfile}[1]{\inputminted[autogobble=true,breaklines,breakindent=4em,numbers=left,escapeinside=@@,fontsize=\scriptsize,tabsize=2]{ampl}{#1}}
\newenvironment{ampl}{\VerbatimEnvironment{}\begin{minted}[
  autogobble=true,
  breaklines,
  breakindent=4em,
  numbers=none,
  escapeinside=@@,
  fontsize=\scriptsize,
	tabsize=2,
]{ampl}}{\end{minted}}

% Some fixes to be loaded at the end
\usepackage{scrhack}
