\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mkessler-fancythm}[2021/04/27 - Theorem-Environment Package]
%%%%%%%%m
%Provides fancy theorem-like-environments usedd in the write-ups of my lecture nots

\newif\ifenglish\englishtrue
\newif\ifshowstars\showstarstrue
\newif\ifshowdaggers\showdaggerstrue
\newif\ifincludestars\includestarstrue
\newif\ifincludeoral\includeoraltrue
\newif\ifmarkoral\markoraltrue

\newif\iflecturenumbers\lecturenumberstrue
\newif\ifnumbersmallenvironmentswiththeorem\numbersmallenvironmentswiththeoremfalse
\newif\ifnumbersmallenvironments\numbersmallenvironmentsfalse

\newif\ifbeamer\beamerfalse

\newcommand{\fancythmlinewidth}{2pt}
\newcommand{\fancythmskipabove}{8pt}



%Sometimes lecturers don't number environments for no particular reason. For compatibility reasons, i also don't number these environments so that the numbers are the same as in the lecture to make them better referencable, but if you want to number all (theorem, lemma, corollary, definition), then use the 'truenumber' option (true because in my opinion they really should be numbered)

%Option to number ALL environments. This numbers examples, remarks, etc as well. I usually don't do that, but if you prefer it that way, use option 'numbersmallenvironments'
%Note also that if you put this option on, it does not matter wheter option 'lecturenumbers' ore 'truenumbers' was chosen, as anyway everything will be numbered. (ALL only applys to the environments that have colored boxes)

\RequirePackage{xkeyval}

%%These are two options to adjust the skipabove and the width of the left margin of theorem-like environments. Default values are 2pt and 8pt, but feel free to change them as you like.
\DeclareOptionX{linewidth}{\renewcommand\fancythmlinewidth{#1}}
\DeclareOptionX{fancythmskipabove}{\renewcommand{\fancythmskipabove}{#1}}

\define@choicekey*{mkesslerfancythm}{numbersmallenvironments}[\val\nr]{no,section,theorem}{%
    \ifcase\nr\relax
        \numbersmallenvironmentsfalse
    \or
        \numbersmallenvironmentstrue
        %numbering small environments within sections is forbidden whilst using lecturenumbes
        \iflecturenumbers
            \numbersmallenvironmentswiththeoremtrue
        \else
            \numbersmallenvironmentswiththeoremfalse
        \fi
    \or
        \numbersmallenvironmentstrue
        \numbersmallenvironmentswiththeoremtrue
    \fi
}

\define@choicekey*{mkesslerfancythm}{lecturenumbers}[\val\nr]{true,false}{%
    \ifcase\nr\relax
        \lecturenumberstrue
    \else
        \lecturenumbersfalse
    \fi
}

\define@choicekey*{mkesslerfancythm}{showdaggers}[\val\nr]{true,false}{%
    \ifcase\nr\relax
        \showdaggerstrue
    \else
        \showdaggersfalse
    \fi
}

\define@choicekey*{mkesslerfancythm}{ownenvironments}[\val\nr]{on, natural, off}{%
    \ifcase\nr\relax
        \includestarstrue
        \showstarstrue
    \or
        \includestarstrue
        \showstarsfalse
    \or
        \includestarsfalse
        \showstarsfalse
    \fi
}

\define@choicekey*{mkesslerfancythm}{oralremarks}[\val\nr]{on,natural,off}{%
    \ifcase\nr\relax
        \includeoraltrue
        \markoraltrue
    \or
        \includeoraltrue
        \markoralfalse
    \or
        \includeoralfalse
    \fi
}

\DeclareOptionX{english}{\englishtrue}
\DeclareOptionX{german}{\englishfalse}
\DeclareOptionX{beamer}{\beamertrue}

\DeclareOptionX{showdaggers}{\setkeys{mkesslerfancythm}{showdaggers=#1}}
\DeclareOptionX{ownenvironments}{\setkeys{mkesslerfancythm}{ownenvironments=#1}}
\DeclareOptionX{oralremarks}{\setkeys{mkesslerfancythm}{oralremarks=#1}}

\DeclareOptionX{lecturenumbers}{\setkeys{mkesslerfancythm}{lecturenumbers=#1}}
\DeclareOptionX{numbersmallenvironments}{\setkeys{mkesslerfancythm}{numbersmallenvironments=#1}}

\DeclareOptionX*{\PackageWarning{mkesslerfancythm}{Unknown X \CurrentOption}}% For unknown options
\ProcessOptionsX*\relax

\RequirePackage{comment}
\begin{comment}
\DeclareOption{numbersmallenvironments}{\numbersmallenvironmentstrue\lecturenumbersfalse}
\end{comment}

%Required Packages
\RequirePackage{amsmath}
\RequirePackage{amsthm}
\RequirePackage{mdframed}
\RequirePackage{thmtools}
\RequirePackage{hyperref}
\RequirePackage[skins]{tcolorbox}
\RequirePackage{xcolor}
\definecolor{gold}{RGB}{218,165,32}


\mdfsetup{skipabove=\topskip,skipbelow=\topskip}

%%mdframed styles
\mdfdefinestyle{mdredmarginandfill}{%
    skipabove =\fancythmskipabove,
    linecolor=red,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    backgroundcolor=red!8,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdorangemarginandfill}{%
    skipabove =\fancythmskipabove,
    linecolor=orange,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    backgroundcolor=orange!10,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdbluemarginandfill}{%
    skipabove =\fancythmskipabove,
    linecolor=blue,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    backgroundcolor=blue!7,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdgreenmargin}{%
    skipabove =\fancythmskipabove,
    linecolor=green!70!black,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdgoldmargin}{%
    skipabove =\fancythmskipabove,
    linecolor=gold,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}


\mdfdefinestyle{mdyellowmargin}{%
    skipabove =\fancythmskipabove,
    linecolor=yellow!80!orange,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdgraymargin}{%
    skipabove =\fancythmskipabove,
    linecolor=gray,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdvioletmarginandfill}{%
    skipabove =\fancythmskipabove,
    linecolor=violet,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    backgroundcolor=violet!7,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdvioletmargin}{%
    skipabove =\fancythmskipabove,
    linecolor=violet,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdredmarginbluefill}{%
    skipabove =\fancythmskipabove,
    linecolor=red,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    backgroundcolor=blue!7,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdredmargin}{%
    skipabove =\fancythmskipabove,
    linecolor=red,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdorangemarginbluefill}{%
    skipabove =\fancythmskipabove,
    linecolor=orange,
    linewidth = \fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    backgroundcolor=blue!7,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdblackmarginandfill}{%
	skipabove=\fancythmskipabove,
	linecolor=black,
	linewidth=\fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
	backgroundcolor=violet!20!gray!20,
    rightline=false,
    topline=false,
    bottomline=false
}

\mdfdefinestyle{mdblackmargin}{%
	skipabove=\fancythmskipabove,
	linecolor=black,
	linewidth=\fancythmlinewidth,
    leftmargin = 0cm,
    rightmargin=0cm,
    rightline=false,
    topline=false,
    bottomline=false
}

\declaretheoremstyle[
	mdframed={style=mdredmarginandfill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmredmarginandfill}

\declaretheoremstyle[
	mdframed={style=mdorangemarginbluefill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmorangemarginbluefill}

\declaretheoremstyle[
	mdframed={style=mdorangemarginandfill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmorangemarginandfill}

\declaretheoremstyle[
	mdframed={style=mdbluemarginandfill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmbluemarginandfill}


\declaretheoremstyle[
	mdframed={style=mdgreenmargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmgreenmargin}

\declaretheoremstyle[
	mdframed={style=mdgoldmargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmgoldmargin}

\declaretheoremstyle[
	mdframed={style=mdyellowmargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmyellowmargin}

\declaretheoremstyle[
	mdframed={style=mdgraymargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmgraymargin}

\declaretheoremstyle[
	mdframed={style=mdvioletmarginandfill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmvioletmarginandfill}

\declaretheoremstyle[
	mdframed={style=mdredmargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmredmargin}

\declaretheoremstyle[
	mdframed={style=mdvioletmargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmvioletmargin}

\declaretheoremstyle[
	mdframed={style=mdredmarginbluefill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmredmarginbluefill}

\declaretheoremstyle[
	mdframed={style=mdblackmarginandfill},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmblackmarginandfill}

\declaretheoremstyle[
	mdframed={style=mdblackmargin},
	postheadspace={0.3em},
    notefont=\mdseries
]{thmblackmargin}

%%Environments that are numbered by default have 3 versions:
% - the standard one, for numbering
% - one asterisk, to exclude them from numbering (because they were not numbered in the lecture) -> they will be numbered if 'truenmubers' option is set
% - two asterisks, for marking them as self-added, so they will not be numbered, but will receive a visual asterisk. -> They will be numbered if 'truenumbers' option is set

%Theorem

\RequirePackage{mfirstuc}
\RequirePackage{xifthen}


%%\makenumberedtheorem[german Name]{style}{Name}
\RequirePackage{xparse}


\declaretheorem[numberwithin=section]{dummy}
\declaretheorem[numberwithin=dummy]{smalldummy}

%\newcounter{dummy}
%\counterwithin{dummy}{section}
%\newcounter{smalldummy}
%\counterwithin{smalldummy}{dummy}  % Make belowtheorem reset each time theorem resets

\NewDocumentCommand{\declarebigtheorem}{O{} O{} m m O{}}{
    %First, store the name of the theorem in \theoremname
    \ifenglish
        \ifthenelse{\isempty{#2}}{\def\theoremname{#4}}{\def\theoremname{#2}}
    \else
        \ifthenelse{\isempty{#1}}{\def\theoremname{#4}}{\def\theoremname{#1}}
    \fi

    %Define the mane version of the theorem
    \ifthenelse{\isempty{#5}}{\declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}, sibling = dummy]{#4}}{}

    %Define the versions theorem*, theorem**, dtheorem

    \iflecturenumbers
        \ifnumbersmallenvironments
            \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}, sibling=smalldummy]{#4*}
            \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}\ifshowstars *\else\fi, sibling=smalldummy]{#4**}
            \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}\ifshowdaggers $^{\dagger}$\else\fi, sibling=smalldummy]{d#4}
        \else
            \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}, numbered=no]{#4*}
            \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}\ifshowstars *\else\fi, numbered = no]{#4**}
            \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}\ifshowdaggers $^{\dagger}$\else\fi, numbered = no]{d#4}
        \fi
    \else
        \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}, sibling=dummy]{#4*}
        \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}\ifshowstars *\else\fi, sibling=dummy]{#4**}
        \declaretheorem[style = #3, name = \makefirstuc{\expandafter\theoremname}\ifshowdaggers $^{\dagger}$\else\fi, sibling=dummy]{d#4}
    \fi
    \ifincludestars\else\renewenvironment{#4**}{\comment}{\endcomment}\fi
}

\NewDocumentCommand{\declaresmalltheorem}{O{} O{} m m}{
    %Get the name of the theorem and store it in \theoremname
    \ifenglish
        \ifthenelse{\isempty{#2}}{\def\theoremname{#4}}{\def\theoremname{#2}}
    \else
        \ifthenelse{\isempty{#1}}{\def\theoremname{#4}}{\def\theoremname{#1}}
    \fi
    \ifnumbersmallenvironments
        \ifnumbersmallenvironmentswiththeorem
            \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}, sibling = smalldummy]{#4}
            \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}\ifshowstars *\else\fi, sibling=smalldummy]{#4*}
            \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}\ifshowdaggers $^{\dagger}$\else\fi, sibling=smalldummy]{d#4}
        \else
            \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}, sibling=dummy]{#4}
            \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}\ifshowstars *\else\fi, sibling=dummy]{#4*}
            \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}\ifshowdaggers $^{\dagger}$\else\fi, sibling=dummy]{d#4}
        \fi
    \else
        \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}, numbered = no]{#4}
        \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}\ifshowstars *\else\fi, numbered = no]{#4*}
        \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}\ifshowdaggers $^{\dagger}$\else\fi, numbered = no]{d#4}
    \fi
    \declaretheorem[style=#3,name=\makefirstuc{\expandafter\theoremname}, sibling=dummy]{n#4}
    \ifincludestars\else\renewenvironment{#4*}{\comment}{\endcomment}\fi
}



%Theorem
\declaretheorem[style=thmredmarginandfill,name=\ifenglish Theorem\else Satz\fi, sibling=dummy, refname = {Satz,Sätze}, Refname = {Satz,Sätze}]{theorem}
\AtBeginDocument{\def\theoremautorefname{\ifenglish Theorem \else Satz\fi}} %Make referencing of theorems work properly (in german) with \autoref
\declarebigtheorem[Satz][Theorem]{thmredmarginandfill}{theorem}[nomain]
%Other
\declarebigtheorem{thmredmarginandfill}{proposition}
\declarebigtheorem[Korollar]{thmredmarginandfill}{corollary}
\declarebigtheorem{thmorangemarginandfill}{lemma}
\declarebigtheorem[Lemma und Definition][Lemma and Definition]{thmorangemarginbluefill}{lemmadef}
\declarebigtheorem{thmbluemarginandfill}{definition}
\declarebigtheorem[Satz und Definition][Theorem and Definition]{thmredmarginbluefill}{theoremdef}
\declarebigtheorem[Proposition und Definition][Proposition and Definition]{thmredmarginbluefill}{propositiondef}
\declarebigtheorem{thmvioletmarginandfill}{notation}
\declarebigtheorem[zuSatz][Addition to Theorem]{thmredmarginandfill}{additiontheorem}

%%%Environments that are not numbered by default (notation, question, example, remark etc) have two forms:
% - normal form: won't be numbered unless 'numbersmallenvironments' is set
% - having an asterisk: will be displayed with an asterisk, will be numbered if 'numbersmallenvironments' is set
%Notation

\declaresmalltheorem[Notationsmissbrauch][Abuse of Notation]{thmvioletmargin}{abuse}
\declaresmalltheorem[Beispiel]{thmgreenmargin}{example}
\declaresmalltheorem[Bemerkung]{thmyellowmargin}{remark}
\declaresmalltheorem[Lob]{thmgoldmargin}{praise}
\declaresmalltheorem[Trivial Nonsense][Trivial Nonsense]{thmyellowmargin}{trivial}
\declaresmalltheorem[Frage]{thmblackmarginandfill}{question}
\declaresmalltheorem[Organisatorisches][Organisational stuff]{thmblackmargin}{orga}
\declaresmalltheorem[Fakt]{thmredmargin}{fact}
\newcounter{blatt}
%\RequirePackage{savesym}
%\savesymbol{aside}
%\declaresmalltheorem[Nebenbemerkung]{thmgraymargin}{aside}
%\restoresymbol{Color}{aside}

%%Aufgaben environment to include exercises at the end of the documnt
%%%This is really a UGLY hack, since autoref actlly does not work properly, so we overwrite the autoref-name of itmes (!)
\declaretheorem[style = thmgreenmargin, numberwithin = blatt, name =Aufgabe]{aufgabe}
\newcommand\blatt{\refstepcounter{blatt}\subsection*{\theblatt. Übungsblatt}\addcontentsline{toc}{subsection}{\theblatt. Übungsblatt}}
\AtEndEnvironment{aufgabe}{\label{aufgabe-\theaufgabe}}
\AtBeginDocument{\def\itemautorefname{Aufgabe}}


%Oral remarks receive their own environment
\declaresmalltheorem[\ifmarkoral Mündliche Anmerkung\else Bemerkung\fi][\ifmarkoral Oral remark\else remark\fi]{thmyellowmargin}{oral}

\ifincludeoral\else
    \renewenvironment{oral}{\comment}{\endcomment}
    \renewenvironment{oral*}{\comment}{\endcomment}
    \renewenvironment{doral}{\comment}{\endcomment}
\fi


%Proof (with asterisk)
\newenvironment{proof*}[1][\ifenglish Proof\else Beweis\fi]{\begin{proof}[#1\emph{*}]}{\end{proof}}

\newtcolorbox{recap}{before skip = 0.5cm, after skip = 0.5cm, enhanced, sharp corners = all, colback = white, colframe = gray, toprule=0pt, bottomrule=0pt, leftrule=0pt,rightrule=0pt, overlay = {
        \draw[gray, line width = 2pt] (frame.north west) -- ++(0.5cm, 0pt);
        \draw[gray, line width=2pt] (frame.south east) -- ++(-0.5cm, 0pt);
        \draw[gray, line width=2pt] (frame.north west) -- ++ (0pt, -0.5cm);
        \draw[gray, line width=2pt] (frame.south east) -- ++(0pt, 0.5cm);
}}

\def\restatableplaceholder{
    \begin{recap}
        Platzhalter, um einen anderen Satz zu wiederholen, der momentan nicht kompiliert wurde
    \end{recap}
}

\theoremstyle{plain}
\ifbeamer\else\newtheorem{variant}{\ifenglish Variant\else Variante\fi}
\newtheorem{assumption}{\ifenglish Assumption\else Annahme\fi}
\fi

%%Give claim an own counter and let it reset at each proof
%See also at:
%https://tex.stackexchange.com/questions/283502/reset-counter-at-beginning-of-proof
\ifbeamer\else
\newtheorem{claim}{\ifenglish Claim\else Behauptung\fi}
\AtBeginEnvironment{proof}{\setcounter{claim}{0}}
\newtheorem*{claim*}{\ifenglish Claim\else Behauptung\fi}
\fi

\theoremstyle{definition}
\ifbeamer\else\newtheorem*{note}{\ifenglish Note\else Anmerkung\fi}\fi
\newtheorem*{warning}{\color{red}\ifenglish Warning \else Warnung\fi}
\ifbeamer\else\newtheorem*{goal}{\ifenglish Goal \else Ziel\fi}\fi
\newtheorem*{strategy}{\ifenglish Proof Strategy \else Beweisstrategie\fi}
\newtheorem*{goal*}{\ifenglish Goal* \else Ziel*\fi}
\newtheorem*{problem}{Problem}
\ifbeamer\else\newtheorem*{info}{Information}\fi
\newenvironment{moral}{%
	\begin{mdframed}[linecolor=green!70!black]%
	\bfseries\color{green!50!black}}%
	{\end{mdframed}}
\newenvironment{antimoral}{%
	\begin{mdframed}[linecolor=red!70!black]%
	\bfseries\color{red!50!black}}%
	{\end{mdframed}}

\ifbeamer\else\newtheorem*{answer}{\ifenglish Answer\else Antwort\fi}\fi
\newtheorem{observe}[theorem]{\ifenglish Observe\else Beobachte\fi}
\ifbeamer\else\newtheorem*{property}{\ifenglish Property\else Eigenschaft\fi}\fi
\ifbeamer\else\newtheorem*{intuition}{Intuition}\fi
\ifbeamer\else\newtheorem*{recall}{\ifenglish Recall\else Erinnerung\fi}\fi
\newtheorem*{idea}{\ifenglish Idea\else Idee\fi}
\ifbeamer\else\newtheorem{exercise}{\ifenglish Exercise\else Aufgabe\fi}[section]\fi
\newtheorem{reminder}{\ifenglish Reminder\else Erinnerung\fi}

%Numbering of environments with a fractional environment number, see
% https://tex.stackexchange.com/questions/598076/how-to-have-a-fractional-environment-number/598080?noredirect=1#comment1499689_598080
%However, for a reason i don't understand the posted answer does not work for me, but i had to replace theorem with definition in the definition of the gag environment (so apparently, i have to do this for each environment separately). It seems that the definitions of this document do use \thedefinition and not \thetheorem, although by default this is not the case.
\newcounter{gag}
\makeatletter
\newenvironment{gag}[1]{%
  \let\savedthedefinition\thedefinition
  \thm@headfont{\bfseries\boldmath}%
  \stepcounter{gag}%
  \renewcommand{\thedefinition}{\savedthedefinition#1}%
  \renewcommand{\theHdefinition}{gag\thegag}%
  \addtocounter{definition}{-1}\ignorespaces
}{\ignorespacesafterend}
\makeatother




%%subproof environment - essentially copied proof environment from amsthm and modified its name + symbol
\makeatletter
\DeclareRobustCommand{\blackqed}{%
  \ifmmode \mathqed
  \else
    \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
    \quad\hbox{$\blacksquare$}%
  \fi
}
\newenvironment{subproof}[1][\ifenglish Subproof\else Unterbeweis\fi]{\par
  \pushQED{\blackqed}%
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \item[\hskip\labelsep
        \itshape
    #1\@addpunct{.}]\ignorespaces
}{%
  \popQED\endtrivlist\@endpefalse
}
\makeatother

%%Solution (for exercises)
\newenvironment{solution}[1][]{\begin{proof}[\ifenglish{}Solution\else{}Lösung\fi{}#1]}{\end{proof}}
\newenvironment{additionproof}[1][]{\begin{proof}[\ifenglish{}Additional proof\else{}zuBeweis\fi{}#1]}{\end{proof}}


%Taken from
% https://github.com/gillescastel/university-setup/blob/master/preamble.tex
% Make boxes breakable
\tcbuselibrary{breakable}

