%% LaTeX2e file `etocsnippet-17.tex'
%% generated by the `filecontentshere' environment
%% from source `etoc' on 2023/10/29.
%%
% \newtoks\treetok % put this (uncommented) preferably in the preamble
% \newtoks\subsectiontok
% \newtoks\subsubsectiontok
% Attention: this code has been prepared only for subsections
% and subsubsections.

\newcommand*{\treenode}{}% only to make sure our \edef's do not overwrite
                         % an existing command

% expands 2nd argument (macro) and appends it to 1st argument (toks)
\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter
    {\expandafter\the\expandafter #1#2}}

% appends 2nd argument contents (toks) as child of first argument (toks)
\newcommand*{\appendchildtree}[2]{% token list t1 becomes: t1 child {t2}
   \edef\tmp{\the#1 child {\the#2}}%
   #1\expandafter{\tmp}%
}
% prepare the (hyperlinked) number in the "node (number)" shape
\newcommand*{\preparetreenode}{%
  \tmptok\expandafter{\etocthelinkednumber}% expanded once (needed)
  \edef\treenode{node {\the\tmptok}}%
}

\etocsetstyle{subsection}
  {\etocskipfirstprefix}
  {\appendchildtree\treetok\subsectiontok}
  {\preparetreenode
   \subsectiontok\expandafter{\treenode}}
  {\appendchildtree\treetok\subsectiontok}

\etocsetstyle{subsubsection}
  {\etocskipfirstprefix}
  {\appendchildtree\subsectiontok\subsubsectiontok}
  {\preparetreenode
   \subsubsectiontok\expandafter{\treenode}}
  {\appendchildtree\subsectiontok\subsubsectiontok}

\etocsettocstyle
  {\treetok{\node {\hyperref[sec:linestyles]{Line styles}}}}
  {\global\appendtotok\treetok{ ;}}

\centeredline{% from package centeredline (limits scope of \hypersetup)
   \etocsetnexttocdepth{subsubsection}
   \etocinline\tableofcontents \label{toc:molecule} \ref{toc:tocstyle}
   \hypersetup{hidelinks}%
   \begin{tikzpicture}
              [grow cyclic,
               level 1/.style={level distance=4cm,sibling angle=72},
               level 2/.style={level distance=2cm,sibling angle=60},
               every node/.style={ball color=red,circle,text=SkyBlue},
               edge from parent path={[dashed,very thick,color=cyan]
                           (\tikzparentnode) --(\tikzchildnode)}]
   \the\treetok
   \end{tikzpicture}%
}
