%% LaTeX2e file `etocsnippet-16.tex'
%% generated by the `filecontentsdef' environment
%% from source `etoc' on 2026/05/05.
%%
% \newtoks\treetok % put this (uncommented) preferably in the preamble
% \newtoks\tmptok  % (idem)
\begingroup
\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter
    {\expandafter\the\expandafter #1#2}}

\newcommand*\PrepareSectionNode{%
  \tmptok {\centering\bfseries}%
  \appendtotok\tmptok\etocthelinkedname
  \edef\foresttreenode{ [{\noexpand\parbox{2cm}{\the\tmptok}}}%
}

\newcommand*{\PrepareSubsectionNode}{%
  \tmptok {\raggedright}%
  \appendtotok\tmptok\etocthelinkedname
  \edef\foresttreenode{ [{\noexpand\parbox{6cm}{\the\tmptok}}}%
}

\etocsetlinestyle{section}
  {\etocskipfirstprefix}
  {\appendtotok\treetok{ ]}}
  {\PrepareSectionNode \appendtotok\treetok\foresttreenode}
  {\appendtotok\treetok{ ]}}

\etocsetlinestyle{subsection}
  {\etocskipfirstprefix}
  {\appendtotok\treetok{ ]}}
  {\PrepareSubsectionNode \appendtotok\treetok\foresttreenode}
  {\appendtotok\treetok{ ]}}

\etocsettocstyle
    {\treetok{[{\hyperref[part:styling]{The \etoc styling commands}}}}
    {\global\appendtotok\treetok{ ]}}

% forest does not like @\the\treetok if \treetok is empty. On first latex
% run, this will be the case because the TOC style defined above will not
% have been executed, as the label {toc:overview} does not refer to a valid
% TOC yet. So we must give a safe default value to \treetok
\treetok{[{run latex again}]}

\begin{figure}[htbp!]
\centering
     \etocsetnexttocdepth{subsection}
     \tableofcontents \label{toc:forest}\ref{toc:part:styling}
     \hypersetup{hidelinks}%
     \bracketset{action character=@}
% manual adjustments to fit the printed page
% \kern-1cm
\noindent\kern-3cm
     \begin{forest}
                  for tree={anchor=center,child anchor=west,
                            grow'=east,draw,thick,
                            edge={draw,thick,dashed,color=teal}},
                  where={level()==1}{circle,thick,fill=blue!5,
                                    before computing xy={l=6cm}}{},
                  where={level()==2}{fill=red!5,
                                    before computing xy={l=6cm}}{},
                  rectangle, thick, fill=cyan!5, inner sep=6pt,
     @\the\treetok
     \end{forest}
\end{figure}
\endgroup
