Debian Codegraph @

texmf-dist/doc/latex/etoc/etocsnippet-17.tex

raw
1 %% LaTeX2e file `etocsnippet-17.tex'
2 %% generated by the `filecontentshere' environment
3 %% from source `etoc' on 2026/05/05.
4 %%
5 % To run this code you must have \usetikzlibrary{trees} in preamble
6 % and as color SkyBlue is neeed you need xcolor with dvipsnames or svgnames
7
8 % \newtoks\treetok % put this (uncommented) preferably in the preamble
9 % \newtoks\subsectiontok
10 % \newtoks\subsubsectiontok
11 % Attention: this code has been prepared only for subsections
12 % and subsubsections.
13
14 \newcommand*{\treenode}{}% only to make sure our \edef's do not overwrite
15 % an existing command
16
17 % expands 2nd argument (macro) and appends it to 1st argument (toks)
18 \newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
19 #1\expandafter\expandafter\expandafter
20 {\expandafter\the\expandafter #1#2}}
21
22 % appends 2nd argument contents (toks) as child of first argument (toks)
23 \newcommand*{\appendchildtree}[2]{% token list t1 becomes: t1 child {t2}
24 \edef\tmp{\the#1 child {\the#2}}%
25 #1\expandafter{\tmp}%
26 }
27
28 % this one sets the node, it is the core macro where we actually
29 % define the contents of all the nodes. We **must** expand
30 % \etocthelinkednumber once. Commented-out is the old syntax.
31 \newcommand*{\preparetreenode}{%
32 % \tmptok\expandafter{\etocthelinkednumber}% expanded once (needed)
33 % \edef\treenode{node {\the\tmptok}}%
34 %
35 \edef\treenode{node {\unexpanded\expandafter{\etocthelinkednumber}}}%
36 }
37
38 % The main objective of these somewhat subtle constructs is to build up
39 % the expected by TikZ input tree in its syntax
40 \etocsetlinestyle{subsection}
41 {\etocskipfirstprefix}
42 {\appendchildtree\treetok\subsectiontok}
43 {\preparetreenode
44 \subsectiontok\expandafter{\treenode}}
45 {\appendchildtree\treetok\subsectiontok}
46
47 \etocsetlinestyle{subsubsection}
48 {\etocskipfirstprefix}
49 {\appendchildtree\subsectiontok\subsubsectiontok}
50 {\preparetreenode
51 \subsubsectiontok\expandafter{\treenode}}
52 {\appendchildtree\subsectiontok\subsubsectiontok}
53
54 % Finally here we have the core code to create and finish the \treetok
55 % we need a global in the "after" code because there will be a grouping
56 % created always by \tableofcontents
57 \etocsettocstyle
58 {\treetok{\node {\hyperref[sec:linestyles]{Line styles}}}}
59 {\global\appendtotok\treetok{ ;}}
60
61 \centeredline{% from package centeredline
62 % btw, the \centeredline creates a scope limiting group
63 \etocsetnexttocdepth{subsubsection}%
64 \etocinline% avoid issueing a \par
65 \tableofcontents \label{toc:molecule} \ref{toc:tocstyle}%
66 \hypersetup{hidelinks}%
67 \begin{tikzpicture}
68 [grow cyclic,
69 level 1/.style={level distance=4cm,sibling angle=72},
70 level 2/.style={level distance=2cm,sibling angle=60},
71 every node/.style={ball color=red,circle,text=SkyBlue},
72 edge from parent path={[dashed,very thick,color=cyan]
73 (\tikzparentnode) --(\tikzchildnode)}]
74 \the\treetok
75 \end{tikzpicture}%
76 }