%%
%% This is file `tocdata.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tocdata.dtx  (with options: `package')
%% This is a generated file.
%% Copyright 2016 Brian Dunn
%% 
%% 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.
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{tocdata}
    [2019/07/06 v2.03 Adds author/artist to TOC entries.]


\RequirePackage{xparse}
\RequirePackage{etoolbox}
\RequirePackage{xpatch}

\@ifpackageloaded{titletoc}{
    \PackageError{tocdata}
        {%
            Load titletoc after tocdata%
        }
        {%
            Move \protect\usepackage{titletoc} after \protect\usepackage{tocdata}.%
        }
}{}

\@ifclassloaded{memoir}
{}% memoir
{% not memoir

\@ifpackageloaded{tocloft}{
    \PackageError{tocdata}
        {%
            Load tocloft after tocdata%
        }
        {%
            Move \protect\usepackage{tocloft} after \protect\usepackage{tocdata}.%
        }
}{}

}% not memoir

\AtBeginDocument{
\@ifpackageloaded{titletoc}{
    \@ifpackageloaded{tocloft}{
        \PackageError{tocdata}
            {%
                Both titletoc and tocloft are being used.\MessageBreak
                Load only one%
            }
            {%
                The tocdata package may use the default LaTeX formatting,\MessageBreak
                or either one of titletoc or tocloft.
            }
    }{}
}{}
}

\newcommand{\TD@thistocdata}{}

\newcommand{\settocdata}[1]{\renewcommand{\TD@thistocdata}{#1}}

\newcommand{\tocdata}[2]{%
    \@bsphack\addtocontents{#1}{\protect\settocdata{#2}}\@esphack%
}
\newcommand{\tocdatafont}[1]{{\normalfont\textit{\small#1}}}
\def\tocdataformat{\tocdatafont}
\newcommand{\TD@usetocdata}{%
    \ifdefvoid{\TD@thistocdata}{}{%
        \tocdataformat{\TD@thistocdata}%
        \global\def\TD@thistocdata{}%
    }%
}

\let\TD@checktocdatafont\tocdatafont

\AtBeginDocument{
\ifdefequal\TD@checktocdatafont\tocdatafont{}{
    \PackageWarningNoLine{tocdata}{%
        You have redefined \protect\tocdatafont,\MessageBreak
        which has been deprecated.  Please redefine\MessageBreak
        \protect\tocdataformat\space instead}
}
}

\newcommand*{\TD@patchstandardlatex}{
\xpatchcmd{\@dottedtocline}
    {\hfill\nobreak}
    {\hfill\TD@usetocdata\nobreak}
    {}%
    {%
        \PackageWarningNoLine{tocdata}{%
            Could not patch LaTeX core \protect\@dottedtocline.\MessageBreak
            Authors may not appear in TOC, LOF}
    }%

\@ifclassloaded{memoir}{}{%
\@ifpackageloaded{tocbasic}{}{%
\xpatchcmd{\l@part}
    {\hfil}
    {\hfil\TD@usetocdata}
    {}%
    {%
        \PackageWarningNoLine{tocdata}{%
            Could not patch LaTeX core \protect\l@part.\MessageBreak
            Authors may not appear in TOC parts}
    }%
}}

\@ifclassloaded{memoir}{}{%
\@ifpackageloaded{tocbasic}{}{%
\@ifundefined{chapter}{}{%
\xpatchcmd{\l@chapter}
    {\hfil\nobreak}
    {\hfil\TD@usetocdata\nobreak}
    {}%
    {%
        \PackageWarningNoLine{tocdata}{%
            Could not patch LaTeX core \protect\l@chapter.\MessageBreak
            Authors may not appear in TOC chapters}
    }%
}}}

\@ifclassloaded{article}{
\xpatchcmd{\l@section}
    {\hfil\nobreak}
    {\hfil\TD@usetocdata\nobreak}
    {}%
    {%
        \PackageWarningNoLine{tocdata}{%
            Could not patch LaTeX core \protect\l@section.\MessageBreak
            Authors may not appear in TOC sections}
    }%
}{}
}% TD@patchstandardlatex
\@ifpackageloaded{lwarp}{%
    \ifbool{warpingprint}{\TD@patchstandardlatex}{}%
}{%
    \TD@patchstandardlatex%
}

\AtBeginDocument{
\@ifpackageloaded{titletoc}{

\newcommand*{\TD@titletoc@patch}[1]{%
    \expandafter\xpatchcmd\csname ttl@savel@#1\endcsname
        {\nobreak\hfil\nobreak}
        {\nobreak\hfil\TD@usetocdata\nobreak}
        {}
        {}
    \expandafter\xpatchcmd\csname l@#1\endcsname
        {\contentspage}
        {\TD@usetocdata\contentspage}
        {}
        {}
}

\TD@titletoc@patch{part}
\@ifundefined{chapter}{}{\TD@titletoc@patch{chapter}}
\TD@titletoc@patch{section}
\TD@titletoc@patch{subsection}
\TD@titletoc@patch{subsubsection}
\TD@titletoc@patch{paragraph}
\TD@titletoc@patch{subparagraph}
\TD@titletoc@patch{figure}
\TD@titletoc@patch{table}
}% end of titletoc loaded
{% titletoc is not loaded
}% end of \@ifpackageloaded{titletoc}
}% end of \AtBeginDocument

\AtBeginDocument{
\@ifclassloaded{memoir}
{
\appto{\cftpartleader}{\TD@usetocdata}
\appto{\cftchapterleader}{\TD@usetocdata}
\appto{\cftsectionleader}{\TD@usetocdata}
\appto{\cftsubsectionleader}{\TD@usetocdata}
\appto{\cftsubsubsectionleader}{\TD@usetocdata}
\appto{\cftparagraphleader}{\TD@usetocdata}
\appto{\cftsubparagraphleader}{\TD@usetocdata}
\appto{\cftfigureleader}{\TD@usetocdata}
\appto{\cfttableleader}{\TD@usetocdata}
\appto{\cftsubfigureleader}{\TD@usetocdata}
\appto{\cftsubtableleader}{\TD@usetocdata}
}% memoir
{% not memoir
\@ifpackageloaded{tocloft}
{
\appto{\cftpartleader}{\TD@usetocdata}
\if@cfthaschapter
    \appto{\cftchapleader}{\TD@usetocdata}
\fi
\appto{\cftsecleader}{\TD@usetocdata}
\appto{\cftsubsecleader}{\TD@usetocdata}
\appto{\cftsubsubsecleader}{\TD@usetocdata}
\appto{\cftparaleader}{\TD@usetocdata}
\appto{\cftsubparaleader}{\TD@usetocdata}
\appto{\cftfigleader}{\TD@usetocdata}
\appto{\cfttableader}{\TD@usetocdata}
\appto{\cftsubfigleader}{\TD@usetocdata}
\appto{\cftsubtableader}{\TD@usetocdata}

}% end of tocloft patches
{}% tocloft not loaded
}% not memoir
}% \AtBeginDocument
\AtBeginDocument{

\@ifpackageloaded{tocbasic}{
\renewcommand*{\scr@dte@tocline}[3]{%
  \ifnum \@nameuse{#1tocdepth}>\c@tocdepth
  \else
    \tocbasic@DependOnPenaltyAndTOCLevel{#1}%
    \addvspace{\@nameuse{scr@tso@#1@beforeskip}}\relax
    {%
      \leftskip \@nameuse{scr@tso@#1@indent}\relax
      \rightskip \@tocrmarg
      \parfillskip -\rightskip
      \@nameuse{Ifscr@tso@#1@raggedpage}{%
        \addtolength{\parfillskip}{\z@ \@plus 1fil}%
      }{}%
      \parindent \@nameuse{scr@tso@#1@indent}\relax
      \@afterindenttrue
      \interlinepenalty\@M
      \expandafter\ifx\csname ragged#1entry\endcsname\raggedright
        \addtolength\rightskip\@flushglue
      \else
        \def\reserved@a{\raggedright}%
        \expandafter\ifx\csname ragged#1entry\endcsname\reserved@a
          \addtolength\rightskip\@flushglue
        \else
          \renewcommand\reserved@a{\raggedright}%
          \expandafter\ifx\csname ragged#1entry\endcsname\reserved@a
            \addtolength\rightskip\@flushglue
          \fi
        \fi
      \fi
      \leavevmode
      \@tempdima \@nameuse{scr@tso@#1@numwidth}\relax
      \@nameuse{Ifscr@tso@#1@dynnumwidth}{%
        \scr@ifundefinedorrelax{scr@dte@#1@lastmaxnumwidth}{}{%
          \ifdim \@nameuse{scr@dte@#1@lastmaxnumwidth}>\@tempdima
            \@tempdima\@nameuse{scr@dte@#1@lastmaxnumwidth}\relax
          \fi
        }%
      }{}%
      \advance\leftskip \@tempdima
      \null\nobreak\hskip -\leftskip
      {%
        \usetocbasicnumberline
        \let\scr@dte@numberline@box\numberline@box
        \def\numberline@box##1{%
          \sbox\scr@dte@tocline@numbox{\@nameuse{scr@tso@#1@numberformat}{##1}}%
          \global\scr@dte@tocline@numberwidth
          \dimexpr\wd\scr@dte@tocline@numbox+\@nameuse{scr@tso@#1@numsep}\relax
          \relax
          \ifdim \scr@dte@tocline@numberwidth
                >\@nameuse{scr@dte@#1@maxnumwidth}\relax
            \global\@nameuse{scr@dte@#1@maxnumwidth}\scr@dte@tocline@numberwidth
          \fi
          \@nameuse{Ifscr@tso@#1@dynnumwidth}{}{%
            \ifdim \scr@dte@tocline@numberwidth
                  >\dimexpr \@nameuse{scr@tso@#1@numwidth}%
                           +\@nameuse{scr@tso@#1@numsep}\relax\relax
              \PackageWarning{tocbasic%
              }{%
                number width of #1 toc entries should be
                increased!\MessageBreak
                Currently used number width =
                \the\wd\scr@dte@tocline@numbox,\MessageBreak
                Wanted number separation
                \space\space\space =
                \the\dimexpr\@nameuse{scr@tso@#1@numsep}\relax,\MessageBreak
                Reserved number width \space\space\space\space\space\space =
                \the\dimexpr\@nameuse{scr@tso@#1@numwidth}\relax%
              }%
            \fi
          }%
          \scr@dte@numberline@box{\@nameuse{scr@tso@#1@numberformat}{##1}}%
          \@nameuse{Ifscr@tso@#1@breakafternumber}{%
            {\parfillskip\@flushglue\par}\nobreak\hskip-\leftskip
          }{}%
        }%
        \@nameuse{scr@tso@#1@entryformat}{%
          #2%
          \nobreak
          {%
            \normalfont\normalsize\@nameuse{scr@tso@#1@linefill}%
            \TD@usetocdata%     lwarp
            \nobreak
            \@nameuse{scr@tso@#1@pagenumberbox}{%
              \@nameuse{scr@tso@#1@pagenumberformat}{#3}%
            }%
          }%
          \@par
        }%
      }%
    }%
    \tocbasic@SetPenaltyByTOCLevel{#1}%
  \fi
}

}{}
}
\AtBeginDocument{
\@ifpackageloaded{tocstyle}{
\xpatchcmd\tocstyle@dottedtocline
    {%
      \ifx\tocstyle@feature@leaders\relax
        \leaders\hbox{$\m@th
          \mkern \@dotsep mu\hbox{\tocstyle@feature@dothook .}%
          \mkern \@dotsep mu$}\hfill
      \else
        \tocstyle@feature@leaders
      \fi%
    }
    {%
      \ifx\tocstyle@feature@leaders\relax
        \leaders\hbox{$\m@th
          \mkern \@dotsep mu\hbox{\tocstyle@feature@dothook .}%
          \mkern \@dotsep mu$}\hfill
      \else
        \tocstyle@feature@leaders
      \fi%
      \TD@usetocdata%
    }
    {}%
    {%
        \PackageWarningNoLine{tocdata}{%
            Could not patch tocstyle \protect\tocstyle@dottedtocline.\MessageBreak
            Authors may not appear in TOC, LOF}
    }%
}{}
}
\newcommand{\TDoptionalnameprint}[1]
{%
    \ifblank{#1}%
    {}%
    {#1~}%
}
\newcommand{\tocdatapartprint}[4]
{%
    \par\noindent%
    {%
        \normalfont\normalsize%
        \textit{%
            \hspace*{4em}--- %
            \TDoptionalnameprint{#1}\TDoptionalnameprint{#2}#3#4%
        }%
    }%
}
\@ifundefined{chapter}
{}% if no chapters
{% only of chapters exists in this documentclass:
    \let\tocdatachapterprint\tocdatapartprint
}% end of chapters-only
\let\tocdatasectionprint\tocdatapartprint
\let\tocdatasubsectionprint\tocdatapartprint
\newcommand{\TDartistauthorprint}[5]{%
    \begin{minipage}{\linewidth}%
    \csuse{TD@#1align}%
    \footnotesize\normalfont%
    \textsc{{\TDoptionalnameprint{#2}\TDoptionalnameprint{#3}#4#5}}%
    \end{minipage}%
    \par%
    \addvspace{2ex}%
}
\newcommand{\tocdataartistprint}{%
    \par\smallskip%
    \TDartistauthorprint{artist}%
}
\newcommand{\tocdataauthorprint}{%
    \par\smallskip%
    \TDartistauthorprint{author}%
}
\newcommand{\TDartistauthortextprint}[2]{%
    \addvspace{2ex}%
    \begin{minipage}{\linewidth}%
    \csuse{TD@#1textalign}%
    \footnotesize\normalfont%
    \setlength{\parskip}{1.5ex}%
    \setlength{\parindent}{0em}%
    #2%
    \end{minipage}%
    \par%
    \addvspace{2ex}%
}
\newcommand{\tocdataartisttextprint}{\TDartistauthortextprint{artist}}
\newcommand{\tocdataauthortextprint}{\TDartistauthortextprint{author}}
\@ifclassloaded{article}
{
    \newcommand*{\TD@starredsectionauthorprint}[5]{%
        \unskip\medskip\csuse{tocdata#1print}{#2}{#3}{#4}{#5}\par%
        \bigskip%
    }
}
{
    \newcommand*{\TD@starredsectionauthorprint}[5]{%
        \ifstrequal{#1}{part}%
        {%
            \PackageWarning{tocdata}{%
                The author's name will not be printed for\MessageBreak
                the starred \protect\part%
            }
        }%
        {%
            \unskip\medskip\csuse{tocdata#1print}{#2}{#3}{#4}{#5}\par%
            \bigskip%
        }%
    }
}
\NewDocumentCommand{\TD@sectionauthor}{m s o m O{} m m O{}}{%
    \IfBooleanTF{#2}%
    {% star:
        \csuse{#1}*{#4}%
        \TD@starredsectionauthorprint{#1}{#5}{#6}{#7}{#8}%
    }%
    {% no star:
        \tocdata{toc}{#6 #7}%
        \IfValueTF{#3}%
            {\csuse{#1}[#3]{#4\nopagebreak\csuse{tocdata#1print}{#5}{#6}{#7}{#8}}}%
            {\csuse{#1}[#4]{#4\nopagebreak\csuse{tocdata#1print}{#5}{#6}{#7}{#8}}}%
    }% no star
    \ifblank{#6}%
        {\index{#7}}%
        {\index{#7, #6}}%
}
\newcommand*{\partauthor}{\TD@sectionauthor{part}}
\@ifundefined{chapter}
{}% if no chapters
{% only of chapters exists in this documentclass:
    \newcommand*{\chapterauthor}{\TD@sectionauthor{chapter}}
}
\newcommand*{\sectionauthor}{\TD@sectionauthor{section}}
\newcommand*{\subsectionauthor}{\TD@sectionauthor{subsection}}
\newcommand{\TD@artistalign}{\centering}
\newcommand{\tdartistjustify}{%
    \renewcommand{\TD@artistalign}{}%
}
\newcommand{\tdartistcenter}{%
    \renewcommand{\TD@artistalign}{\centering}%
}
\newcommand{\tdartistleft}{%
    \renewcommand{\TD@artistalign}{\raggedright}%
}
\newcommand{\tdartistright}{%
    \renewcommand{\TD@artistalign}{\raggedleft}%
}
\newcommand{\TD@authoralign}{\raggedleft}
\newcommand{\tdauthorjustify}{%
    \renewcommand{\TD@authoralign}{}%
}
\newcommand{\tdauthorcenter}{%
    \renewcommand{\TD@authoralign}{\centering}%
}
\newcommand{\tdauthorleft}{%
    \renewcommand{\TD@authoralign}{\raggedright}%
}
\newcommand{\tdauthorright}{%
    \renewcommand{\TD@authoralign}{\raggedleft}%
}
\newcommand{\TD@artisttextalign}{\centering}
\newcommand{\tdartisttextjustify}{%
    \renewcommand{\TD@artisttextalign}{}%
}
\newcommand{\tdartisttextcenter}{%
    \renewcommand{\TD@artisttextalign}{\centering}%
}
\newcommand{\tdartisttextleft}{%
    \renewcommand{\TD@artisttextalign}{\raggedright}%
}
\newcommand{\tdartisttextright}{%
    \renewcommand{\TD@artisttextalign}{\raggedleft}%
}
\newcommand{\TD@authortextalign}{\centering}
\newcommand{\tdauthortextjustify}{%
    \renewcommand{\TD@authortextalign}{}%
}
\newcommand{\tdauthortextcenter}{%
    \renewcommand{\TD@authortextalign}{\centering}%
}
\newcommand{\tdauthortextleft}{%
    \renewcommand{\TD@authortextalign}{\raggedright}%
}
\newcommand{\tdauthortextright}{%
    \renewcommand{\TD@authortextalign}{\raggedleft}%
}
\NewDocumentCommand{\TD@captionartistauthor}{m s o m +O{} O{} m m O{}}{%
    \csuse{tocdata#1print}{#6}{#7}{#8}{#9}%
    \ifblank{#5}%
        {}%
        {\par\csuse{tocdata#1textprint}{#5}}%
    \unskip%
    \IfBooleanTF{#2}%
        {% starred
            \IfValueTF{#3}{\caption*[#3]{#4}}{\caption*{#4}}%
        }% starred
        {% not starred
            \tocdata{\csuse{ext@\@captype}}{#7 #8}%
            \IfValueTF{#3}{\caption[#3]{#4}}{\caption{#4}}%
        }% not starred
    \ifblank{#7}%
        {\index{#8}}%
        {\index{#8, #7}}%
}
\newcommand*{\captionartist}{\TD@captionartistauthor{artist}}
\newcommand*{\captionauthor}{\TD@captionartistauthor{author}}
\endinput
%%
%% End of file `tocdata.sty'.
