%! TeX program = lualatex
\documentclass[UKenglish,12pt,BCOR=10mm]{scrartcl}

\usepackage[defaultfeatures={%
    Ligatures={TeX,Common,Discretionary}
  },nomath]{libertinus}
\usepackage{xcolor}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{selnolig}
\usepackage{amsmath,amsthm}
\usepackage{mathtools}
\usepackage[colon=literal]{unicode-math}
\usepackage{enumitem}
\usepackage{tcolorbox}
\usepackage[style=ext-numeric]{biblatex}
\usepackage[intoc]{nomencl}
\usepackage{makeidx}
\usepackage{idxlayout}
\usepackage{hyperref}
\usepackage{bookmark}
\usepackage{hypdestopt}
\usepackage[capitalise]{cleveref}
%\usepackage{refcheck}

% ---------- fontspec
\setfontfamily\fausansoffice{FAUSansOffice}
\setmathfont[Scale=MatchLowercase]{New Computer Modern Math}
% restore traditional bb and cal glyphs
\let\mathbb\relax\DeclareMathAlphabet\mathbb{U}{msb}{m}{n}
\let\mathcal\relax\DeclareMathAlphabet\mathcal{OMS}{cmsy}{m}{n}

% ---------- xcolor
\definecolor{faunat}{RGB}{29,134,73}
\definecolor{linkcolor}{RGB}{134,29,38} % split complementary method

% ---------- koma-script
\KOMAoptions{%
  numbers=noenddot,
  index=totoc
}
\addtokomafont{sectioning}{\fausansoffice\color{faunat}}
% keep layout when removing BCOR=10mm
%\areaset{426.8pt}{635.5pt}

% ---------- selnolig
\nolig{tz}{t|z}
%\debugon

% ---------- amsmath
\numberwithin{equation}{section}
\DeclareMathOperator{\supp}{supp}
\DeclareMathOperator{\dom}{dom}
% extend amsmath's proof environment
\NewDocumentEnvironment{myproof}{Ob}{\IfNoValueTF{#1}{\begin{proof}}{\begin{proof}[\proofname\ of \Cref{#1}]}}{\end{proof}}

% ---------- mathtools
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\DeclarePairedDelimiter\parens{\lparen}{\rparen}
\DeclarePairedDelimiter\bracks{\lbrack}{\rbrack}
\DeclarePairedDelimiter\braces{\lbrace}{\rbrace}
\DeclarePairedDelimiter\angles{\langle}{\rangle}
\DeclarePairedDelimiter\bra{\lvert}{\rangle}
\DeclarePairedDelimiter\ket{\langle}{\rvert}
\DeclarePairedDelimiterX\innerp[2]{\langle}{\rangle}{#1,#2}

% ---------- tcolorbox
\tcbuselibrary{skins,theorems} % add breakable library?
\tcbset{%
  beforeafter skip balanced=0.4\baselineskip,
  mythmstyle/.style={%
    enhanced,
    sharp corners=all,
    interior hidden,
    borderline west={3pt}{0pt}{#1},
    colframe=#1!25,
    coltitle=black,
    fonttitle=\bfseries,
    toptitle=0.6ex,
    left=3pt+0.6ex,
    bottom=0.6ex,
    top=0.6ex,
    theorem style=break,
    separator sign={\ \mdseries---},
    description delimiters none,
    terminator sign none,
  }
}
\newcounter{mythmcounter}
\counterwithin{mythmcounter}{section}
\newcommand{\mynewthm}[2]{%
  \newtcbtheorem[%
    use counter*=mythmcounter,
    Crefname={\MakeTitlecase{#1}}{\MakeTitlecase{#1s}}
    ]{#1}{\MakeTitlecase{#1}}{mythmstyle=#2}{#1}
}
\mynewthm{definition}{gray}
\mynewthm{example}{gray}
\mynewthm{remark}{gray}
\mynewthm{theorem}{faunat}
\mynewthm{lemma}{faunat}
\mynewthm{proposition}{faunat}
\mynewthm{corollary}{faunat}

% ---------- biblatex
\addbibresource[glob]{bib/*.bib}
\ExecuteBibliographyOptions{%
  refsegment=section,
  sorting=none,
  defernumbers,
  giveninits,
  backref,
}
\defbibheading{subbibliography}{%
  \bookmarksetupnext{level=subsection,italic}
  \pdfbookmark{\refname}{refbm:\arabic{refsegment}}
  \subsection*{\refname\ for \Cref*{refsegment:\therefsection\therefsegment}}
}
\DefineBibliographyStrings{english}{%
  backrefpage={ref.\ on p.},
  backrefpages={ref.\ on pp.}
}
\DeclareFieldFormat[article]{volume}{\textbf{#1}}
\DeclareFieldFormat[article]{title}{\textit{#1}}
\renewcommand{\mkbibnamefamily}[1]{\textsc{#1}}
\renewcommand{\mkbibnamegiven}[1]{\textsc{#1}}
\renewcommand{\mkbibnameprefix}[1]{\textsc{#1}}
\renewcommand{\mkbibnamesuffix}[1]{\textsc{#1}}
% https://tex.stackexchange.com/questions/574292
\renewcommand*{\subtitlepunct}{\addcolon\space}
\DeclarePunctuationPairs{colon}{*}

% ---------- nomencl
\makenomenclature
\def\pagedeclaration#1{, \hyperlink{page.#1}{page\nobreakspace#1}}

% ---------- makeidx
\makeindex

% ---------- hyperref
\hypersetup{%
  colorlinks,
  allcolors=linkcolor,
  linktoc=all,
  bookmarksnumbered,
  bookmarksopen,
  bookmarksopenlevel=2,
  hypertexnames=false,
  pdftitle={Title},
  pdfauthor={Justin Gassner},
  pdfsubject={Subject},
  pdfkeywords={Keyword1, Keyword2},
}

% ---------- more pdf stuff
\pdfvariable minorversion 6
\pdfvariable suppressoptionalinfo \numexpr
        0
    +   1   % PTEX.FullBanner
    +   2   % PTEX.FileName
    +   4   % PTEX.PageNumber
    +   8   % PTEX.InfoDict
    +  16   % Creator
    +  32   % CreationDate
    +  64   % ModDate
    + 128   % Producer
    + 256   % Trapped
    + 512   % ID
\relax

% ---------- misc
\renewcommand\phi\varphi
\renewcommand\epsilon\varepsilon
% number systems
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\CC}{\mathbb{C}}
% emphasis for defined terms
\newcommand{\defn}[1]{\textbf{\textit{#1}}}
% Hilbert spaces
\newcommand{\hilb}[1]{\mathcal{#1}}
% Fourier transformation
\newcommand{\ft}[1]{\hat{#1}}
\newcommand{\FT}[1]{\mathcal{F}\parens*{#1}}
\newcommand{\iFT}[1]{\mathcal{F}^{-1}\parens*{#1}}
% normal ordering (aka Wick ordering)
\newcommand{\normord}[1]{{\vcentcolon\mathrel{#1}\vcentcolon}}
