\ProvidesPackage{setup}

% ! Provides all preamble

\usepackage[margin=0.15in]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage[]{csquotes}

\usepackage{amsthm}
\usepackage{amsmath,amssymb}
\usepackage{mathrsfs}
\usepackage{xfrac}

% \usepackage{libertine}
\usepackage{newpxtext}
\usepackage{newpxmath}

\usepackage{tabularx}
\usepackage{multicol}
\usepackage[shortlabels]{enumitem}
\usepackage{listings}
\usepackage{tocloft}

\usepackage{setspace}
\usepackage{cancel}
\usepackage{graphicx}

\usepackage{thmtools}
\usepackage{thm-restate}
\usepackage[framemethod=TikZ]{mdframed}

\usepackage[ragged,multiple,flushmargin]{footmisc}

\usepackage{xcolor-solarized}
\usepackage[colorlinks, allcolors=solarized-cyan, linkcolor=darkgray]{hyperref}
\usepackage{cleveref}
\usepackage{nameref}

\usepackage{xpatch}
\usepackage{catchfile}
\usepackage{marvosym}
\usepackage{pgffor}

\usepackage{physics}

\usepackage{tikz}
% \usepackage{quiver}
% \usetikzlibrary{babel}
% \usetikzlibrary{braids}


% TODO: updates below
% ! title
% \newcommand{\thetitle}{\noindent
% \begin{center}
%     \begin{tabularx}{\textwidth} { 
%         >{\raggedright\arraybackslash}X 
%         >{\raggedleft\arraybackslash}X}
%     \LARGE \pageauthor \\
%     \LARGE \textbf{\pagetitle} & \LARGE \textbf{\pagesubtitle}\\
%     \end{tabularx}\\
%     \rule[2ex]{0.8\textwidth}{1pt}
% \end{center}}
\newcommand{\thetitle}{
  \noindent
% \begin{center}
  \vspace*{5em}\\
  {\Huge\textbf{\pagesubtitle} - \pagetitle}\\
  {\small{\pagedescription}}
  \vspace*{2em}\\
  % \vspace*{2em}
 {\small Based on lectures from \pagesemester by \pageprofessor}\\
 {\small Notes by \pageauthor}
 \vspace*{5em}
% \end{center}
}


% TODO
\titleformat{\section}
{\color{darkgray}\centering\normalfont\Large\bfseries}
{\color{darkgray}\thesection}{1em}{}

% Proof environment
\renewcommand*{\qedsymbol}{\(\blacksquare\)}
\renewcommand*{\proofname}{\underline{Proof}}

% % Fix issues with references
\newcommand{\getenv}[2][]{%
  \CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{\endlinechar=-1}%
  \if\relax\detokenize{#1}\relax\temp\else\let#1\temp\fi}


  \makeatletter
  \define@key{thmdef}{mdthm}[{}]{%
  \thmt@trytwice{\def\thmt@theoremdefiner{\mdtheorem[#1]}}{}}
  \makeatother
  
% Theorem environments
\declaretheorem[
  % thmbox=S,
  name=Remark,
  refname={Remark, remark},
  numberwithin=section
]{remark}


\mdfdefinestyle{example}{
  roundcorner=8pt,
  linewidth=2pt,
  linecolor=gray!30,
  leftmargin=15,rightmargin=15,
  backgroundcolor=solarized-cyan!20,
  skipabove=5pt, skipbelow=5pt,
  innertopmargin=2pt, innerbottommargin=5pt,
  innerleftmargin=8pt, innerrightmargin=8pt
  % nobreak=true
}

\mdfdefinestyle{general-thm}{
  roundcorner=8pt,
  linecolor=white,
  leftmargin=5,rightmargin=5,
  backgroundcolor=gray!10,
  skipabove=10pt, skipbelow=10pt,
  innertopmargin=2pt, innerbottommargin=5pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  nobreak=true
}

\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-red}{$\hookrightarrow$ \underline{Theorem}}, numberwithin=section]{theorem}
\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-orange}{$\hookrightarrow$ \underline{Corollary}}, numberwithin=section]{corollary}
\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-magenta}{$\hookrightarrow$ \underline{Proposition}}, numberwithin=section]{proposition}
\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-orange}{$\hookrightarrow$ \underline{Lemma}}, numberwithin=section]{lemma}
\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-orange}{$\hookrightarrow$ \underline{Axiom}}, numberwithin=section]{axiom}
\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-blue}{$\hookrightarrow$ \underline{Definition}}, numberwithin=section]{definition}
\declaretheorem[mdthm={style=general-thm}, title=\textcolor{solarized-blue}{$\hookrightarrow$ \underline{Question}}, numberwithin=section]{question}
% \declaretheorem[mdthm={style=general-thm}, numberwithin=section]{theorem}

\mdtheorem[style=example]{example}{$\circledast$ \underline{Example}}[section]

% \mdtheorem[style=general-thm]{theorem}{\textcolor{solarized-red}{$\hookrightarrow$ \underline{Theorem}}}[section]
% \mdtheorem[style=general-thm]{proposition}{\textcolor{solarized-magenta}{$\hookrightarrow$ \underline{Proposition}}}[section]
% \mdtheorem[style=general-thm]{corollary}{\textcolor{solarized-orange}{$\hookrightarrow$ \underline{Corollary}}}[section]
% \mdtheorem[style=general-thm]{lemma}{\textcolor{solarized-orange}{$\hookrightarrow$ \underline{Lemma}}}[section]
% \mdtheorem[style=general-thm]{axiom}{\textcolor{solarized-orange}{$\hookrightarrow$ \underline{Axiom}}}[section]
% \mdtheorem[style=general-thm]{definition}{\textcolor{solarized-blue}{$\hookrightarrow$ \underline{Definition}}}[section]
% \mdtheorem[style=general-thm]{question}{\textcolor{solarized-blue}{$\hookrightarrow$ \underline{Question}}}[section]

% fixes broken references
% \newcommand{\thmautorefname}{Theorem}
% \makeatletter
% \xpatchcmd{\theorem}{\refstepcounter}{\NR@gettitle{#1}\refstepcounter}{}{}
% \makeatother

% \newcommand{\propautorefname}{Proposition}
% \makeatletter
% \xpatchcmd{\proposition}{\refstepcounter}{\NR@gettitle{#1}\refstepcounter}{}{}
% \makeatother

% \newcommand{\axiomautorefname}{Axiom}
% \makeatletter
% \xpatchcmd{\axiom}{\refstepcounter}{\NR@gettitle{#1}\refstepcounter}{}{}
% \makeatother

% \newcommand{\corrautorefname}{Corollary}
% \makeatletter
% \xpatchcmd{\corollary}{\refstepcounter}{\NR@gettitle{#1}\refstepcounter}{}{}
% \makeatother

% \newcommand{\lemmaautorefname}{Lemma}
% \makeatletter
% \xpatchcmd{\lemma}{\refstepcounter}{\NR@gettitle{#1}\refstepcounter}{}{}
% \makeatother


% makes "quoted" text actually look correct
\MakeOuterQuote{"}

% page footer
\newpagestyle{mypage}{%
% \footrule
\setfoot{\scriptsize\textcolor{gray}{§\ref{\thesubsection}}}{\scriptsize\textcolor{gray}{\textit{{\scshape\sectiontitle}: \textbf{\subsectiontitle}}}}{\textcolor{gray}{\scriptsize p. \thepage}}
}


\titleformat{\section}
{\Large\bfseries\scshape}
{\thesection}{1em}{}

\renewcommand{\contentsname}{\bfseries\scshape\Large Contents}