%% The LaTeX package tcolorbox - version 2.61 (2014/01/10)
%% tcbdocumentation.code.tex: Code for LaTeX documentations
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2013 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\tcb@set@library@version{2.61}

\tcbuselibrary{listings}

\RequirePackage{doc}[2010/02/04]
\RequirePackage{pifont}[2005/04/12]
\RequirePackage{marvosym}[2011/07/20]
\RequirePackage{hyperref}[2012/02/06]
\RequirePackage{makeidx}[2000/03/29]
\RequirePackage{refcount}[2011/10/16]

\definecolor{Option}{rgb}{0.118,0.546,0.222}
\definecolor{Definition}{rgb}{0.784,0.06,0.176}
\definecolor{ExampleFrame}{rgb}{0.628,0.705,0.942}
\definecolor{ExampleBack}{rgb}{0.963,0.971,0.994}
\definecolor{Hyperlink}{rgb}{0.281,0.275,0.485}

\def\colDef#1{\textcolor{\kvtcb@coldef}{#1}}
\def\colOpt#1{\textcolor{\kvtcb@colopt}{#1}}

\lstdefinestyle{tcbdocumentation}{language={[LaTeX]TeX},
    aboveskip={0\p@ \@plus 6\p@},
    belowskip={0\p@ \@plus 6\p@},
    columns=fullflexible,
    keepspaces=true,
    breaklines=true,
    prebreak={\Righttorque},
    postbreak={\space\Lefttorque},
    breakatwhitespace=true,
    basicstyle=\ttfamily\footnotesize,
    extendedchars=true,
    moredelim={[is][\itshape\rmfamily]{�}{�}},
    nolol,inputencoding=\kvtcb@listingencoding}

% The following macros are taken from ltxdoc
\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
\def\marg#1{%
  {\ttfamily\char`\{}{\rmfamily\meta{#1}}{\ttfamily\char`\}}}
\def\oarg#1{%
  \colOpt{{\ttfamily[}{\rmfamily\meta{#1}}{\ttfamily]}}}

% language specific texts
\tcbset{
  doclang/.cd,
  color/.store in=\kvtcb@text@color,
  colors/.store in=\kvtcb@text@colors,
  environment content/.store in=\kvtcb@text@envcontent,
  environment/.store in=\kvtcb@text@env,
  environments/.store in=\kvtcb@text@envs,
  key/.store in=\kvtcb@text@key,
  index/.store in=\kvtcb@text@index,
  pageshort/.store in=\kvtcb@text@pageshort,
}

% documentation options
\tcbset{
  documentation listing options/.store in=\kvtcb@doclistingoptions,%
  documentation listing style/.style={documentation listing options={style=#1}},%
  documentation minted style/.store in=\kvtcb@docmintstyle,
  documentation minted options/.store in=\kvtcb@docmintoptions,
  color option/.store in=\kvtcb@colopt,
  color definition/.store in=\kvtcb@coldef,
  color hyperlink/.store in=\kvtcb@colhyper,
  color frame/.store in=\kvtcb@colhyper,
  color hyperlink/.store in=\kvtcb@colhyper,
  before example/.store in=\kvtcb@beforeexample,
  after example/.store in=\kvtcb@afterexample,
  index actual/.store in=\idx@actual,
  index quote/.store in=\idx@quote,
  index level/.store in=\idx@level,
  index format/.store in=\idx@format,
}

% styles
\tcbset{
  docexample/.style={colframe=ExampleFrame,colback=ExampleBack,fontlower=\footnotesize},
  documentation minted style=,
  documentation minted options={tabsize=2,fontsize=\small},
  index default settings/.style={index actual={@},index quote={"},index level={!}},
  index german settings/.style={index actual={=},index quote={!},index level={>}},
  english language/.code={\tcbset{doclang/.cd,
    color=color,
    colors=Colors,
    environment content=environment content,
    environment=environment,
    environments=Environments,
    key=key,
    index=Index,
    pageshort={P.}}},
}

\AtBeginDocument{%
  \csname tcb@doc@index@\idx@format\endcsname%
  \hypersetup{
  citecolor=\kvtcb@colhyper,
  linkcolor=\kvtcb@colhyper,
  urlcolor=\kvtcb@colhyper,
  filecolor=\kvtcb@colhyper,
  menucolor=\kvtcb@colhyper
}}


\def\dispExample{\tcbset{docexample}\tcbwritetemp}

\def\enddispExample{%
  \endtcbwritetemp%
  \kvtcb@beforeexample\begin{tcolorbox}%
  \tcb@doc@usetemplisting%
  \tcblower%
  \tcbusetemp%
  \end{tcolorbox}\kvtcb@afterexample%
}

\newenvironment{dispExample*}[1]{%
  \tcbset{docexample,#1}\tcbwritetemp%
  }{\enddispExample}

\def\dispListing{\tcb@layer@pushup\tcbset{docexample}\tcbwritetemp}

\def\enddispListing{%
  \endtcbwritetemp%
  \kvtcb@beforeexample\begin{tcolorbox}%
  \tcb@doc@usetemplisting%
  \end{tcolorbox}\kvtcb@afterexample%
}

\newenvironment{dispListing*}[1]{%
  \tcb@layer@pushup\tcbset{docexample,#1}\tcbwritetemp%
  }{\enddispListing}


% index auxiliary macros
\def\index@Col#1{\index{#1\idx@actual\texttt{#1} \kvtcb@text@color}\index{\kvtcb@text@colors\idx@level#1\idx@actual\texttt{#1}}}
\def\index@Com#1{\index{#1\idx@actual\cs{#1}}}
\def\index@Env#1{\index{#1\idx@actual\texttt{#1} \kvtcb@text@env}\index{\kvtcb@text@envs\idx@level#1\idx@actual\texttt{#1}}}
\def\index@Key#1{\index{#1\idx@actual\texttt{#1} \kvtcb@text@key}}%
\def\index@KeyPath#1#2{\index@Key{#2}\index{#1\idx@actual\texttt{/#1/}\idx@level#2\idx@actual\texttt{#2}}}%

\def\disp@com#1{\colDef{\ttfamily\bfseries#1}}

\def\brackets#1{{\ttfamily\char`\{}#1{\ttfamily\char`\}}}

\newenvironment{manual@entry}{\list{}{\leftmargin=2em\itemindent-\leftmargin\def\makelabel##1{\hss##1}}}{\endlist}

\def\manual@top#1{\itemsep=0pt\parskip=0pt\item\strut{#1}\par\topsep=0pt}

% main documentation environments
\newenvironment{docCommand}[3][]{\begin{manual@entry}%
  \tcbset{#1}\hypertarget{com:#2}{\manual@top{\disp@com{\cs{#2}}\index@Com{#2}\protected@edef\@currentlabel{\noexpand\cs{#2}}\label{com:#2}{\ttfamily #3}}}}%
  {\end{manual@entry}}

\newenvironment{docEnvironment}[3][]{\begin{manual@entry}%
  \tcbset{#1}\hypertarget{env:#2}{\manual@top{\cs{begin}\brackets{\disp@com{#2}}\index@Env{#2}\protected@edef\@currentlabel{#2}\label{env:#2}{\ttfamily #3}}}%
  \manual@top{~~\meta{\kvtcb@text@envcontent}}%
  \manual@top{\cs{end}\brackets{\disp@com{#2}}}}%
  {\end{manual@entry}}

\newenvironment{docKey}[4][\@empty]{\begin{manual@entry}%
  \ifx#1\@empty%
  \hypertarget{key:#2}{\manual@top{\disp@com{#2}\index@Key{#2}\protected@edef\@currentlabel{#2}\label{key:#2}{\ttfamily #3}\hfill(#4)}}
  \else\hypertarget{key:/#1/#2}{\manual@top{\disp@com{/#1/#2}\index@KeyPath{#1}{#2}\protected@edef\@currentlabel{/#1/#2}\label{key:/#1/#2}#3\hfill(#4)}}\fi}%
  {\end{manual@entry}}

\def\tcbmakedocSubKey#1#2{%
  \newenvironment{#1}[4][\@empty]{%
    \ifx##1\@empty\def\tcb@key@path{#2}\else\def\tcb@key@path{#2/##1}\fi%
    \begin{docKey}[\tcb@key@path]{##2}{##3}{##4}}%
      {\end{docKey}}%
}

\def\docColor#1{\disp@com{#1}\index@Col{#1}}%
\def\docAuxCommand#1{\disp@com{\cs{#1}}\index@Com{#1}}%

\setrefcountdefault{-1}
\def\ref@doc#1{\hyperlink{#1}{\texttt{\ref*{#1}}%
  \ifnum\getpagerefnumber{#1}=\thepage\else%
  \textsuperscript{\ding{213}\,\kvtcb@text@pageshort\,\pageref*{#1}}\fi}}

\def\ref@doc@star#1{\hyperlink{#1}{\texttt{\ref*{#1}}}}

\def\refCom@#1{\ref@doc{com:#1}}
\def\refCom@star#1{\ref@doc@star{com:#1}}
\def\refCom{\@ifstar\refCom@star\refCom@}

\def\refEnv@#1{\ref@doc{env:#1}}
\def\refEnv@star#1{\ref@doc@star{env:#1}}
\def\refEnv{\@ifstar\refEnv@star\refEnv@}

\def\refKey@#1{\ref@doc{key:#1}}
\def\refKey@star#1{\ref@doc@star{key:#1}}
\def\refKey{\@ifstar\refKey@star\refKey@}

\newenvironment{absquote}
               {\list{}{\leftmargin2cm\rightmargin\leftmargin}%
                \item\relax\footnotesize}
               {\endlist}

%--- index macros taken from pgfmanual-en-macros
\def\tcb@doc@index@pgf@{%
  \c@IndexColumns=2%
  \def\theindex{\@restonecoltrue
    \columnseprule \z@  \columnsep 29\p@
    \twocolumn[\index@prologue]%
    \parindent -30pt%
    \columnsep 15pt%
    \parskip 0pt plus 1pt%
    \leftskip 30pt%
    \rightskip 0pt plus 2cm%
    \small%
    \def\@idxitem{\par}%
    \let\item\@idxitem\ignorespaces}
  \def\endtheindex{\onecolumn}%
  \def\noindexing{\let\index=\@gobble}%
}


\def\tcb@doc@index@pgfsection{%
  \def\index@prologue{\section*{\kvtcb@text@index}\addcontentsline{toc}{section}{\kvtcb@text@index}%
    \par\noindent%
  }%
  \tcb@doc@index@pgf@%
}

\def\tcb@doc@index@pgfchapter{%
  \def\index@prologue{\ifdefined\phantomsection\phantomsection\fi\@makeschapterhead{\kvtcb@text@index}\addcontentsline{toc}{chapter}{\kvtcb@text@index}}%
  \tcb@doc@index@pgf@%
}


\let\tcb@doc@index@pgf=\tcb@doc@index@pgfsection%


\def\tcb@doc@index@doc{%
  \let\index@Com=\SpecialMainIndex%%
  \let\index@Env=\SpecialMainEnvIndex%
  \tcbset{index german settings}%
  \EnableCrossrefs%
  \PageIndex%
}

\def\tcb@doc@index@off{}%

\tcbset{%
  reset@documentation/.style={%
    index format=pgf,
    english language,
    documentation listing style=tcbdocumentation,
    index default settings,
    color option=Option,
    color definition=Definition,
    color hyperlink=Hyperlink,
    before example=\par\smallskip,
    after example=,},
  initialize@reset=reset@documentation,
}


