%% LaTeX2e file `etocsnippet-17.tex'
%% generated by the `filecontentshere' environment
%% from source `etoc' on 2026/05/05.
%%
% To run this code you must have \usetikzlibrary{trees} in preamble
% and as color SkyBlue is neeed you need xcolor with dvipsnames or svgnames

% \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}%
}

% this one sets the node, it is the core macro where we actually
% define the contents of all the nodes.  We **must** expand
% \etocthelinkednumber once.  Commented-out is the old syntax.
\newcommand*{\preparetreenode}{%
  % \tmptok\expandafter{\etocthelinkednumber}% expanded once (needed)
  % \edef\treenode{node {\the\tmptok}}%
  %
  \edef\treenode{node {\unexpanded\expandafter{\etocthelinkednumber}}}%
}

% The main objective of these somewhat subtle constructs is to build up
% the expected by TikZ input tree in its syntax
\etocsetlinestyle{subsection}
  {\etocskipfirstprefix}
  {\appendchildtree\treetok\subsectiontok}
  {\preparetreenode
   \subsectiontok\expandafter{\treenode}}
  {\appendchildtree\treetok\subsectiontok}

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

% Finally here we have the core code to create and finish the \treetok
% we need a global in the "after" code because there will be a grouping
% created always by \tableofcontents
\etocsettocstyle
  {\treetok{\node {\hyperref[sec:linestyles]{Line styles}}}}
  {\global\appendtotok\treetok{ ;}}

\centeredline{% from package centeredline
% btw, the \centeredline creates a scope limiting group
   \etocsetnexttocdepth{subsubsection}%
   \etocinline% avoid issueing a \par
   \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}%
}
