
\documentclass[a4paper,12pt<]{article}

\usepackage{comment}
\delimitershortfall=-2pt
\delimiterfactor=900

\usepackage{sansmath, amstext, mathtools, physics}

\usepackage{ifthen}
\usepackage{wrapfig}

% Frakturschrift
\usepackage{yfonts}

\usepackage{attachfile2}


\usepackage{enumitem}
\setlist[itemize]  {itemsep=0.0em, topsep=0.0em}
\setlist[enumerate]{itemsep=0.0em, topsep=0.0em}

% Deutsche Sprache, Silbentrennung und Schriftzeichen
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{hyperref}
\hypersetup{hidelinks}

% Verbesserter Wortabstand
\usepackage{microtype}
\usepackage{hyphenat}

\usepackage{multicol}
\usepackage{needspace}
\usepackage{physics}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{dsfont}
\usepackage{amssymb}
%\usepackage{mleftright}
% displaystyle in '\( ... \)' inline
\let\oldlparen\(
\let\oldrparen\)
\renewcommand{\(}{\oldlparen\displaystyle}
\renewcommand{\)}{\oldrparen}


\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage{tikz}
\usepackage{pgfmath}
\usepgfplotslibrary{colormaps} % For better shading

\pgfplotsset{compat=newest}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{3d}

% Pakete für Layout und Schriftart
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{helvet}  % Helvetica-Schriftart
\renewcommand{\familydefault}{\sfdefault}  % Setze serifenlose Schriftart global

% Layout
\usepackage[margin=1cm, tmargin=2cm, bmargin=0.5cm]{geometry}  % Linker und rechter Rand = 1cm
\setlength{\parindent}{0pt}  % Kein Einschub am Anfang eines Paragraphen
\setlength{\parskip}{1em}    % Abstand zwischen Paragraphen = 1em


% Aufgabe-Environment
\usepackage{titlesec}


% Define a counter for the 'aufgabe' environment, reset with each section
\newcounter{aufgabencounter}[section]
\renewcommand{\theaufgabencounter}{\thesection.\arabic{aufgabencounter}}

% Headerfancy
\usepackage{fancyhdr} % For custom headers
\usepackage{needspace} % To prevent page breaks in the middle of tasks
\usepackage{titlesec}  % For controlling section title format
% Variable to store current task title
\newcommand{\currenttasktitle}{}
% Setup the header with fancyhdr
\pagestyle{fancy}
%%%\fancyhf{}
\fancyhead[L]{\scriptsize\leftmark\\\currenttasktitle}
\fancyhead[R]{\Large\thepage}        
%\fancyhf{} % Alle Kopf- und Fußzeilen leeren
\fancyfoot[C]{} % Fußzeile in der Mitte leeren


% Define the 'aufgabe' environment
\newenvironment{aufgabe}[1]{%
%%%%<- pagebreak wenn Restseite < x %
 \ifdim\pagetotal>\dimexpr0.75\textheight\relax
     \clearpage
   \fi
%%%%->
  \refstepcounter{aufgabencounter}
  \renewcommand{\currenttasktitle}{A-\theaufgabencounter\ (#1)}
  \addcontentsline{toc}{subsection}{A-\theaufgabencounter: #1} 
%  \needspace{10\baselineskip}
  \begin{mdframed}
  \underline{\textbf{Aufgabe \theaufgabencounter\ (#1)}} 
%%%%<-
\ignorespaces
%%%%->
}{\end{mdframed}%
%%%%<-
\ignorespacesafterend
%%%%->
}



% Umdefinitionen
\renewcommand{\vec}{\underline}


% Frames
\usepackage[framemethod=Tikz]{mdframed}
\mdfsetup{
    linecolor=black,
    linewidth=1.5pt,
    roundcorner=6pt,
    backgroundcolor=white,
%    tikzsetting={rounded corners},  % TikZ Einstellung für abgerundete Ecken
}



\begin{comment}
\mdfsetup{
    linecolor=black,
    linewidth=1.5pt,
    roundcorner=15pt,
    innertopmargin=10pt,
    innerbottommargin=10pt,
    leftmargin=0pt,
    rightmargin=0pt,
    backgroundcolor=white
}
\end{comment}


\newcommand{\ul}[1]{\underline{#1}}


% Quantenmechanik
\usepackage{quantikz}
\usepackage{braket}
%\newcommand{\ketbra}[2]{\Ket{#1}\!\!\Bra{#2}}



\newcommand{\tikzmark}[2]{
   \tikz[overlay,remember picture, baseline=(#1.base)]{
    \node (#1) {#2};
  }
}

\usepackage{listings}

\allowdisplaybreaks



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tocloft}
\renewcommand{\cftsecdotsep}{1}
\renewcommand{\cftsubsecdotsep}{1}


\begin{comment}
\newlistof%
  {attachedfiles}%
  {atf}%
  {Liste der Programmcodes}

\newcommand{\textattachfilewithentry}[3]{
  \textattachfile{#1}{#2}
  \addcontentsline
    {atf} {attachedfile}
    {\\ \protect\numberline{[Kap.~\thesection] #3 \dots\dots  \thepage} }
}

\end{comment}



\newlistof%
  {attachedfiles}%
  {atf}%
  {Liste der Programmcodes}


\newcommand{\textattachfilewithentry}[3]{ %
  \textattachfile{#1}{#2}%
  \addcontentsline %
    {atf} {attachedfile} %
    {\\ \protect\textattachfile{#1}{\textcolor{black}{\fbox{CODE}}}
[Kap.~\thesection] #3 \dots\dots } %
%
% \addtocontents
%    {mylist}
%    {
%      \protect\contentsline{mylist}{}
%      {#3 \protect\attachfilelink{#2}{(Download)}}
%      {}
%    }
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



