Debian Codegraph @

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

raw
1 %% LaTeX2e file `etocsnippet-16.tex'
2 %% generated by the `filecontentsdef' environment
3 %% from source `etoc' on 2026/05/05.
4 %%
5 % \newtoks\treetok % put this (uncommented) preferably in the preamble
6 % \newtoks\tmptok % (idem)
7 \begingroup
8 \newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
9 #1\expandafter\expandafter\expandafter
10 {\expandafter\the\expandafter #1#2}}
11
12 \newcommand*\PrepareSectionNode{%
13 \tmptok {\centering\bfseries}%
14 \appendtotok\tmptok\etocthelinkedname
15 \edef\foresttreenode{ [{\noexpand\parbox{2cm}{\the\tmptok}}}%
16 }
17
18 \newcommand*{\PrepareSubsectionNode}{%
19 \tmptok {\raggedright}%
20 \appendtotok\tmptok\etocthelinkedname
21 \edef\foresttreenode{ [{\noexpand\parbox{6cm}{\the\tmptok}}}%
22 }
23
24 \etocsetlinestyle{section}
25 {\etocskipfirstprefix}
26 {\appendtotok\treetok{ ]}}
27 {\PrepareSectionNode \appendtotok\treetok\foresttreenode}
28 {\appendtotok\treetok{ ]}}
29
30 \etocsetlinestyle{subsection}
31 {\etocskipfirstprefix}
32 {\appendtotok\treetok{ ]}}
33 {\PrepareSubsectionNode \appendtotok\treetok\foresttreenode}
34 {\appendtotok\treetok{ ]}}
35
36 \etocsettocstyle
37 {\treetok{[{\hyperref[part:styling]{The \etoc styling commands}}}}
38 {\global\appendtotok\treetok{ ]}}
39
40 % forest does not like @\the\treetok if \treetok is empty. On first latex
41 % run, this will be the case because the TOC style defined above will not
42 % have been executed, as the label {toc:overview} does not refer to a valid
43 % TOC yet. So we must give a safe default value to \treetok
44 \treetok{[{run latex again}]}
45
46 \begin{figure}[htbp!]
47 \centering
48 \etocsetnexttocdepth{subsection}
49 \tableofcontents \label{toc:forest}\ref{toc:part:styling}
50 \hypersetup{hidelinks}%
51 \bracketset{action character=@}
52 % manual adjustments to fit the printed page
53 % \kern-1cm
54 \noindent\kern-3cm
55 \begin{forest}
56 for tree={anchor=center,child anchor=west,
57 grow'=east,draw,thick,
58 edge={draw,thick,dashed,color=teal}},
59 where={level()==1}{circle,thick,fill=blue!5,
60 before computing xy={l=6cm}}{},
61 where={level()==2}{fill=red!5,
62 before computing xy={l=6cm}}{},
63 rectangle, thick, fill=cyan!5, inner sep=6pt,
64 @\the\treetok
65 \end{forest}
66 \end{figure}
67 \endgroup