% !TeX root = tcolorbox.tex
% include file (style) of tcolorbox.tex (manual of the LaTeX package tcolorbox)
\renewcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.7em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{4.2em}{3.2em}}

% prevent hypdoc from loading (sets hyperindex=false)
\@namedef{ver@hypdoc.sty}{9999/12/31}
\@namedef{opt@hypdoc.sty}{hypdoc}

\RequirePackage[T1]{fontenc}
%\RequirePackage[utf8]{inputenc}
\RequirePackage[english]{babel}
\RequirePackage{lmodern,parskip,array,ifthen,calc}
\RequirePackage{amsmath,amssymb}
\RequirePackage[svgnames,table]{xcolor}

\RequirePackage{tikz}
\usetikzlibrary{shadings,shadows}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{patterns}
\usetikzlibrary{spy}
\usetikzlibrary{arrows.meta}

\RequirePackage[nospace]{varioref}

\RequirePackage{bookmark,varwidth,incgraph}
\RequirePackage{array,tabularx}
\RequirePackage{amsmath}
\RequirePackage{lipsum}
\RequirePackage{empheq}
\RequirePackage[extendedchars,encoding,filenameencoding=utf-8]{grffile}

\providecommand{\tcbpkgprefix}{}
\RequirePackage{\tcbpkgprefix tcolorbox}

\tcbuselibrary{most,documentation}

\tcbifexternal{}{%
  \tcbuselibrary{minted}%
  \tcbset{listing engine=listings,initialize@reset={listing engine=listings}}%
}

\RequirePackage{accsupp}
\RequirePackage{hyperref}

\RequirePackage[a4paper,left=2.5cm,right=2.5cm,top=1.5cm,bottom=1.5cm,
    marginparsep=3mm,marginparwidth=18mm,
    headheight=0mm,headsep=0cm,
    footskip=1.5cm,includeheadfoot%,showframe
    ]{geometry}
\RequirePackage{fancyhdr}
\fancyhf{}
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}
\tolerance=2000%
\setlength{\emergencystretch}{20pt}%

\RequirePackage{cleveref}


\tcbset{skin=enhanced,
  doc head={colback=yellow!10!white,interior style=fill},
  doc head key={colback=magenta!5!white,interior style=fill},
  doc head path={colback=blue!50!gray!7!white,interior style=fill},
  color key=DarkViolet,
  color value=Teal,
  color color=Teal,
  color counter=Orange!85!black,
  color length=Orange!85!black,
  index colorize,
  index annotate,
}
\urlstyle{sf}

\tcbmakedocSubKey{docTcbKey}{tcb}
\tcbmakedocSubKeys{docTcbKeys}{tcb}
\tcbmakedocSubKey{langTcbKey}{tcb/doclang}
\tcbmakedocSubKey{newTcbKey}{tcb/new}
\tcbmakedocSubKey{boxTcbKey}{tcb/boxtitle}
\tcbmakedocSubKey{extTcbKey}{tcb/external}
\tcbmakedocSubKey{vigTcbKey}{tcb/vig}
\tcbmakedocSubKey{posterTcbKey}{tcb/poster}
\tcbmakedocSubKey{posterlocTcbKey}{tcb/posterloc}
\tcbmakedocSubKey{postersetTcbKey}{tcb/posterset}
\tcbmakedocSubKey{docTikzKey}{tikz}

\def\tikzname{Ti\emph{k}Z}


\newrobustcmd{\tcbIndexPrintSkinCA}[1]{\tcb@Index@Print@CA{#1}{\kvtcb@col@key}{Skin}}
\newrobustcmd{\tcbIndexPrintSkinC}[1]{\tcb@Index@Print@C{#1}{\kvtcb@col@key}}
\def\refSkin{\tcb@ref@doc{skin}}

\newrobustcmd{\tcbIndexPrintFadCA}[1]{\tcb@Index@Print@CA{#1}{\kvtcb@col@value}{fading}}
\newrobustcmd{\tcbIndexPrintFadC}[1]{\tcb@Index@Print@C{#1}{\kvtcb@col@value}}


\ExplSyntaxOn

\NewDocumentEnvironment{docSkin}{ O{} m }
  {
    \__tcobox_doc_entry_begin:nnn
      {
        doc~keypath=tcb,
        doc~name={skin},
        doc~label={skin=#2},
        doc~parameter={=\docValue*[nophantom]{#2}},
        doc~description={skin},
        #1,
        doc~no~index,
        doc~head~key =
        {
          colback=magenta!5!white,interior~style=fill,
          phantom=
            {
              \protected@edef\@currentlabel{#2}
              \label{skin:#2}
              \index{#2\idx@actual\tcbIndexPrintSkinCA{#2}}
              \index{Skins\idx@level#2\idx@actual\tcbIndexPrintSkinC{#2}}
            },
        }
      }
      {}{key}
  }
  {
    \__tcobox_doc_entry_end:n { key }
  }


\NewDocumentCommand \docFading { s +O{} m }
  {
    \group_begin:
    \tcbset{doc~name={#3},#2}
    \textcolor{\kvtcb@col@value}{\__tcobox_print_docname:}
    \IfBooleanF{#1}
      {
        \kvtcb@index@command{\kvtcb@doc@sortindex\idx@actual\tcbIndexPrintFadCA{\kvtcb@doc@index}}
        \kvtcb@index@command{Fadings\idx@level\kvtcb@doc@sortindex\idx@actual\tcbIndexPrintFadC{\kvtcb@doc@index}}
      }
    \group_end:
  }

\ExplSyntaxOff



\newtcolorbox{marker}[1][]{enhanced,
  before skip balanced=2mm,after skip balanced=3mm,
  boxrule=0.4pt,left=5mm,right=2mm,top=1mm,bottom=1mm,
  colback=yellow!50,
  colframe=yellow!20!black,
  sharp corners,rounded corners=southeast,arc is angular,arc=3mm,
  underlay={%
    \path[fill=tcbcolback!80!black] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2);
    \path[draw=tcbcolframe,shorten <=-0.05mm,shorten >=-0.05mm] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2);
    \path[fill=yellow!50!black,draw=none] (interior.south west) rectangle node[white]{\Huge\bfseries !} ([xshift=4mm]interior.north west);
    },
  drop fuzzy shadow,#1}


\renewcommand*{\tcbdocnew}[1]{\textcolor{green!50!black}{\sffamily\bfseries N} #1}
\renewcommand*{\tcbdocupdated}[1]{\textcolor{blue!75!black}{\sffamily\bfseries U} #1}

\newcounter{texexp}
\newcounter{texercise}
\newcounter{mytheorem}[section]

\newcounter{myexample}

\newcounter{example}
\newlength{\examlen}
\newsavebox\mysavebox

\lstdefinestyle{mydocumentation}{style=tcbdocumentation,
  classoffset=0,
  texcsstyle=*\color{blue},
  % LaTeX and other packages
  moretexcs={arrayrulecolor,draw,includegraphics,ifthenelse,isodd,lipsum,path,pgfkeysalso},
  classoffset=1,
  % tcolorbox macros
  moretexcs={% core
    endtcolorbox,endtcbverbatimwrite,newtcolorbox,newtcbox,newtcboxfit,tcbusetemp,tcbtitle,tcbtitletext,
    tcblower,tcbox,tcboxfit,tcbset,tcbuselibrary,tcolorbox,tcbverbatimwrite,tcbsetforeverylayer,tcbsubtitle,
    tcolorboxenvironment,tcblistof,tcbstartrecording,tcbrecord,tcbstoprecording,tcbinputrecords,
    tcbpatcharcangular,tcbpatcharcround,tcbifoddpage,thetcolorboxnumber,thetcolorboxpage,
    tcbheightfromgroup,tcbheightspace,tcbtextwidth,tcbtextheight,
    % listings
    endtcblisting,newtcblisting,newtcbinputlisting,
    tcblisting,tcbinputlisting,tcbuselistingtext,tcbuselistinglisting,tcbusetemplisting,
    tcbfitdim,tcbfitsteps,
    % raster
    thetcbrasternum,tcbitem,
    % breakable
    tcbbreak,
    % theorems
    tcbmaketheorem,tcboxmath,tcbhighmath,thetcbcounter,newtcbtheorem,
    NewTcbTheorem,RenewTcbTheorem,ProvideTcbTheorem,DeclareTcbTheorem,
    % documentation
    brackets,
    colDef,colOpt,cs,
    docAuxCommand,docColor,docAuxEnvironment,docAuxKey,
    docCounter,docLength,
    meta,marg,
    oarg,
    refCom,refEnv,refKey,
    sarg,
    tcbmakedocSubKey,tcbdocmarginnote,tcbdocnew,tcbdocupdated,
    % skins
    tcbincludegraphics,tcbincludepdf,pdfpages,imagepage,imagepath,imagename,
    tcbline,tcboxedtitleheight,tcboxedtitlewidth,
    tcbsettowidthofnode,tcbsetmacrotowidthofnode,tcbsettoheightofnode,tcbsetmacrotoheightofnode,
    tcbhypernode,
    % vignette
    tcbvignette,
    % xparse
    DeclareTColorBox,NewTColorBox,RenewTColorBox,ProvideTColorBox,
    DeclareTotalTColorBox,NewTotalTColorBox,RenewTotalTColorBox,ProvideTotalTColorBox,
    DeclareTCBox,NewTCBox,RenewTCBox,ProvideTCBox,
    DeclareTotalTCBox,NewTotalTCBox,RenewTotalTCBox,ProvideTotalTCBox,
    DeclareTCBListing,NewTCBListing,RenewTCBListing,ProvideTCBListing,
    DeclareTCBInputListing,NewTCBInputListing,RenewTCBInputListing,ProvideTCBInputListing,
    DeclareTCBoxFit,NewTCBoxFit,RenewTCBoxFit,ProvideTCBoxFit,
    DeclareTotalTCBoxFit,NewTotalTCBoxFit,RenewTotalTCBoxFit,ProvideTotalTCBoxFit,
    tcbsidebyside,tcboxverb,
    % externalization
    tcbEXTERNALIZE,tcbifexternal,newtcbexternalizeenvironment,
    renewtcbexternalizeenvironment,extcolorbox,extikzpicture,
    newtcbexternalizetcolorbox,renewtcbexternalizetcolorbox,
    tcbiffileprocess,
    % box array
    newboxarray,boxarraygetsize,boxarrayreset,boxarrayclear,
    boxarraygetbox,boxarraygetwidth,boxarraygetheight,boxarraygetdepth,
    boxarraygettotalheight,useboxarray,usetcboxarray,
    consumeboxarray,consumetcboxarray,ifboxarrayempty,
    % poster
    posterbox,tcbposterwidth,tcbposterheight,tcbpostercolspacing,
    tcbposterrowspacing,tcbpostercolumns,tcbposterrows,tcbpostercolwidth,
    tcbposterrowheight,tcbposterset,
    % extras
    skinExampleSet,
    },
  texcsstyle=*\color{Definition}\bfseries,
  classoffset=0% restore default
  }

\definecolor{Green_Dark}{rgb}{0.078431,0.407843,0.176471}
\definecolor{Blue_Dark}{rgb}{0.090196,0.211765,0.364706}
\definecolor{Blue_Bright}{rgb}{0.858824,0.898039,0.945098}

\tcbset{
  documentation listing style=mydocumentation,%
  sbs/.style={sidebyside,before lower app={\tcbset{sidebyside=false}}},%
  innerbox/.style={reset,documentation listing style=mydocumentation,
    doc keypath/.store in=\kvtcb@doc@keypath,
    docexample/.style={docexample original},%
    },
  beforeafter example/.style={
    before skip balanced=4pt plus 2pt minus 1pt,
    after skip balanced=5pt plus 2pt minus 1pt
  },
  base example/.style={bicolor jigsaw,
    beforeafter example,arc is angular,fonttitle=\bfseries,
    fontlower=\footnotesize,
    colframe=Blue_Dark,
    colback=Blue_Bright,
    colbacklower=white,
    drop fuzzy shadow,
    },
  docexample/.style={base example,%
    every box on layer 2/.style={every box},
    before upper={\tcbset{innerbox}},before lower={\tcbset{innerbox}}
    },
  docexample original/.style={colframe=ExampleFrame,colback=ExampleBack,fontlower=\footnotesize,
    before skip=\medskipamount,after skip=\medskipamount,frame style={}},
}

\newtcbexternalizetcolorbox{exdispExample}{dispExample}{environment with percent=false,minipage,compiler=lualatex}{beforeafter example}

\newtcbexternalizetcolorbox{exdispExample*}{dispExample*}{environment with percent=false,minipage,compiler=lualatex}{beforeafter example}

\newcommand{\inputpreamblelisting}[1]{%
  \tcbinputlisting{title=Definition in the preamble:,
    base example,coltitle=black,fonttitle=\itshape,titlerule=0pt,
    colbacktitle=Navy!15!ExampleBack,
    top=0mm,
    %before=\par\smallskip,%
    before skip balanced=4pt plus 2pt minus 1pt,
    after skip balanced=5pt plus 2pt minus 1pt,
    listing style=mydocumentation,
    listing only,listing file={\jobname_preamble_#1.tex}}%
}

\newtcolorbox{deprecated}{blank,breakable,watermark text=deprecated}

\newtcbox{\mylib}{enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=0mm,bottom=0mm,
  right=0mm,left=4mm,arc=1pt,boxsep=2pt,before upper={\vphantom{dlg}},
  colframe=green!50!black,coltext=green!25!black,colback=green!10!white,
  overlay={\begin{tcbclipinterior}\fill[green!75!blue!50!white] (frame.south west)
    rectangle node[text=white,font=\sffamily\bfseries\tiny,rotate=90] {LIB} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}

\robustify{\mylib}

\pdfstringdefDisableCommands{%
  \def\mylib#1{`#1'}%
}

\newrobustcmd*{\tcbexclamation}{!}

\newtcbox{\section@box}{tile,before=\clearpage\noindent,after=,
  fontupper=\normalfont\Large\bfseries,capture=minipage,colback=blue!80,coltext=white,
  boxsep=0mm,top=4mm,bottom=4mm,left=\oddsidemargin+1in,right=\oddsidemargin+1in,
  spread sidewards,fuzzy halo=1mm with blue!50!gray}

\renewcommand\section{\@startsection{section}{1}{\z@}{\z@}{5mm}{\section@box}}

\newtcblisting{fulldocumentlisting}[1]{%
  enhanced jigsaw,lower separated=false,breakable,
  leftlower=0mm,rightlower=0mm,bottom=0mm,middle=1mm,
  listing style=mydocumentation,base example,
  listing and comment,
  pdf comment,freeze pdf,
  comment style={raster columns=2,raster equal skip=1mm},
  compilable listing,
  run pdflatex,#1
}

\ExplSyntaxOn

\cs_new:Npn \__tcobox_aux_mkdir:n #1
  {
    \file_if_exist:nF { "#1"/dir.marker }
      {
        \sys_shell_now:x {mkdir~"#1"}
        \iow_open:Nn \g_tmpa_iow {"#1"/dir.marker}
        \iow_close:N \g_tmpa_iow
      }
  }

\NewDocumentCommand{ \tcbAUXmkdir }{ m }
  {
    \__tcobox_aux_mkdir:n {#1}
  }

\ExplSyntaxOff

