\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{homework}[2024/31/01 my class for homework]% Danish format

% Class options
\newif\ifclassdansk\classdanskfalse
\newif\ifclassfarver\classfarvertrue

\DeclareOption{dansk}{\classdansktrue}
\DeclareOption{nocolors}{\classfarverfalse}
% Any options passed to homework.cls not "dansk" or "nocolors"
% will be passed to amsart instead.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{amsart}}
\ProcessOptions\relax

% Load amsart
\LoadClass[a4paper]{amsart}
\RequirePackage[utf8]{inputenc}

% Selecting the language
\ifclassdansk
	\PassOptionsToClass{danish}{amsart}
	\RequirePackage[danish]{babel}
\else
	\PassOptionsToClass{english}{amsart}
	\RequirePackage[english]{babel}
\fi

% ==================================================================
% ============================ PACKAGES ============================
% ==================================================================

\RequirePackage{etoolbox} % For my own macros
\RequirePackage{csquotes} % do you use this package?
\RequirePackage{marginnote}
\RequirePackage{microtype} % are you sure you want to use this package?

\RequirePackage{enumitem}
\RequirePackage[nodayofweek]{datetime} % option "level", if you want st,nd,rd,th \emph{level} with the text
\RequirePackage{graphicx}

\RequirePackage{caption}
\RequirePackage{subcaption}

% Math packages
\RequirePackage{mathtools}
\RequirePackage{amsthm}
\RequirePackage{thmtools}
\RequirePackage{amssymb} % loads amsfonts
\RequirePackage{amscd}
\RequirePackage{bm}
\RequirePackage{mathrsfs} % for the calligraphy some people use for categories
\RequirePackage{siunitx} % for (Danish) numbers
\RequirePackage{CJKutf8} % For the Yoneda embedding (\yo)

\RequirePackage{ifthen}
\ifclassfarver
	\RequirePackage{xcolor}
\fi

\RequirePackage{hyperref}
\RequirePackage{cleveref} % should be loaded last

% ==================================================================
% =========================== CUSTOMIZATION ========================
% ==================================================================

\ifclassfarver
	\definecolor{KUrod}{HTML}{901A1E}
	\definecolor{KUgron}{HTML}{4b8325}% 39641c
	\definecolor{KUblaa}{HTML}{122947}
	\hypersetup{
		colorlinks=true,
		citecolor={KUgron},
		linkcolor={KUrod},
		urlcolor={KUblaa},
		linktoc=page,
	}
\fi

% Language setup
\ifclassdansk
	\renewcommand{\datename}{\textit{Dato}:}
	\sisetup{locale = DE}% for siunitx
	\AfterEndPreamble{\renewcommand{\appendixname}{Appendiks}}
\else
	\renewcommand{\datename}{\textit{Date}:}
\fi

% styling the Table of Contents
\def\l@section{\@tocline{1}{5pt}{1pc}{}{\bfseries}}
\def\l@subsection{\@tocline{2}{0pt}{2.7pc}{5pc}{}}

% ==================================================================
% ========================== THEOREM-LIKE ==========================
% ==================================================================

\newskip\minegenskip % Denne er den afstand amsart.cls og amsthm.sty bruger til afstanden før og efter f.eks. theorem
\minegenskip=.5\baselineskip plus.2\baselineskip minus.2\baselineskip

\declaretheoremstyle[
	spaceabove=\minegenskip,
	spacebelow=\minegenskip
]{minopgave}

\ifclassdansk
	\declaretheorem[style=minopgave,name=Opgave]{opgave}
	\declaretheorem[style=minopgave,name=Opgave,numbered=no]{opgave*}
\else
	\declaretheorem[style=minopgave,name=Problem]{opgave}
	\declaretheorem[style=minopgave,name=Problem,numbered=no]{opgave*}
\fi
\declaretheorem[style=minopgave,name=Problem,sibling=opgave]{problem}
\declaretheorem[style=minopgave,name=Problem,sibling=opgave,numbered=no]{problem*}

\declaretheoremstyle[
	spaceabove=\minegenskip,
	spacebelow=\minegenskip,
	bodyfont=\itshape,
]{minsetning}

\declaretheorem[style=minsetning,name=Lemma,numbered=yes]{lemma}
\declaretheorem[style=minsetning,name=Lemma,numbered=no]{lemma*}

\declaretheoremstyle[
	spaceabove=\minegenskip,
	spacebelow=\minegenskip,
	numbered=no,
	headfont=\itshape
]{minremark}

\declaretheorem[style=minremark,name=Notation]{notation}
\ifclassdansk
	\declaretheorem[style=minremark,name=Påstand,numbered=yes]{claim}
	\declaretheorem[style=minremark,name=Påstand]{claim*}
	\declaretheorem[style=minremark,name=Bevis af påstand,qed=$\square_{\text{påstand}}$]{proofofclaim}
\else
	\declaretheorem[style=minremark,name=Claim,numbered=yes]{claim}
	\declaretheorem[style=minremark,name=Claim]{claim*}
	\declaretheorem[style=minremark,name=Proof of claim,qed=$\square_{\text{claim}}$]{proofofclaim}
\fi

% ==================================================================
% ============================ SVAR ENV ============================
% ==================================================================

% Define the numbering for lists made by the liste environment
\providecommand{\nummer}{\textbf{\alph*)}}

\newif\ifcurrenvirliste
\currenvirlistefalse
\newenvironment{liste}[1][]
{
\ifthenelse{\equal{#1}{resume}}
	{\begin{enumerate}[resume*=liste]\currenvirlistetrue}
	{\begin{enumerate}[series=liste,label=\nummer]\currenvirlistetrue}
}
{\end{enumerate}\currenvirlistefalse}

% Define svar - an environment for writing solutions to problems (opgave)
% svar can be used inside the liste environment (hence the complication) 
\ifclassdansk
	\newenvironment{svar}%
	{\begin{proof}[Løsning]}%
	{\end{proof}}
\else
	\newenvironment{svar}%
	{\begin{proof}[Solution]}%
	{\end{proof}}
\fi

\BeforeBeginEnvironment{svar}{%
	\ifcurrenvirliste
		\end{enumerate} \currenvirlistetrue
	\else
	\fi
}
\AfterEndEnvironment{svar}{%
	\ifcurrenvirliste
		\begin{enumerate}[resume*=liste] \currenvirlistetrue
	\else
	\fi
}

% ==================================================================
% ============================= MACROS =============================
% ==================================================================

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}

\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}

% a colon, "facing the opposite way" - e.g. for adjoints
\providecommand{\cocolon}{%
	\nobreak\mskip6muplus1mu\mathpunct{}\nonscript
	\mkern-\thinmuskip{:}\mskip2mu\relax}

\renewcommand{\to}{\longrightarrow}

\providecommand{\pipe}{\ \vert\ }
\providecommand{\uden}{\backslash}
\providecommand{\mono}{\hookrightarrow}
\providecommand{\xmono}[1]{\xhookrightarrow{#1}}
\providecommand{\epi}{\twoheadrightarrow}
\providecommand{\xepi}[1]{\xtwoheadrightarrow{#1}}
\providecommand{\cupprod}{\smile}
\providecommand{\capprod}{\frown}
\providecommand{\hurewicz}{\hbar}

\providecommand{\normal}{\mathrel{\unlhd}} % as in normal subgroup

\newcommand{\yo}{\text{\begin{CJK}{UTF8}{min}よ\end{CJK}}} % for the Yoneda embedding

\providecommand{\N}{\mathbb{N}}
\providecommand{\Z}{\mathbb{Z}}
\providecommand{\Q}{\mathbb{Q}}
\providecommand{\R}{\mathbb{R}}
\providecommand{\C}{\mathbb{C}}
\providecommand{\F}{\mathbb{F}}

\DeclareMathOperator{\Ran}{Ran}
\DeclareMathOperator{\Ho}{Ho}
\DeclareMathOperator{\dom}{dom}
\DeclareMathOperator{\cod}{cod}
\DeclareMathOperator{\spec}{Spec}
\DeclareMathOperator{\Hom}{Hom}
\DeclareMathOperator{\id}{id}
\DeclareMathOperator{\im}{im}
\DeclareMathOperator{\Int}{int}
\DeclareMathOperator{\obj}{Obj}
\DeclareMathOperator{\Sing}{Sing}
\DeclareMathOperator{\tot}{Tot}
\DeclareMathOperator{\GL}{GL}
\DeclareMathOperator{\Span}{span}
\def\coker{\qopname\relax{no}{coker}}
\def\colim{\qopname\relax n{colim}}
\def\hocolim{\qopname\relax n{hocolim}}
\def\holim{\qopname\relax n{holim}}

\DeclareMathOperator{\on}{\textbf{On}}

\DeclareMathOperator{\ord}{\textsc{ord }}
\DeclareMathOperator{\card}{\textsc{card }}

% categories --- You should probably change the names of these
% the commands should not be capitalized
\DeclareMathOperator{\Set}{\textbf{Set}}
\DeclareMathOperator{\sSet}{\textbf{sSet}}
\DeclareMathOperator{\Ring}{\textbf{Ring}}
\DeclareMathOperator{\Mon}{\textbf{Mon}}
\DeclareMathOperator{\Mod}{\textbf{Mod}}
\DeclareMathOperator{\Ab}{\textbf{Ab}}
\DeclareMathOperator{\Grp}{\textbf{Grp}}
\DeclareMathOperator{\Cat}{\textbf{Cat}}
\DeclareMathOperator{\Top}{\textbf{Top}}
\DeclareMathOperator{\Fun}{Fun}

% dx, dy, du etc. for analysis
\providecommand{\dx}{\,\mathrm{d}x}
\providecommand{\dy}{\,\mathrm{d}y}
\providecommand{\dz}{\,\mathrm{d}z}
\providecommand{\dt}{\,\mathrm{d}t}
\providecommand{\du}{\,\mathrm{d}u}
