2

I'm attempting to recreate the 'TOC as a TikZ mind map' as featured on p.47 of Jean-Francois Burnol's "The etoc package" but I cannot resolve the error that occurs on line 115:

(\centeredline{\resizebox{.85\paperwidth}{!}%)

of the following MWE:

\documentclass[12pt,oneside, tikz, ignorerest=false]{standalone}

\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}
\usepackage{etoc}
\def\input@path{{/usr/local/texlive/2022/texmf-dist/tex/latex/centeredline/}}
\usepackage{centeredline}
\newcounter{visibletoc}
\renewcommand{\etocaftertitlehook}
   {\stepcounter{visibletoc}\etoctoccontentsline{visibletoc}{\thevisibletoc}}
\etocsetlevel{visibletoc}{6}
\begin{document}
\subsection{Surprising uses of etoc}
\begingroup
% \newtoks\treetok % done in preamble
% \newtoks\parttok
\newcommand*\partnode {}  % just to check we don’t overwrite something
\newcommand*\childnode {}

\newcommand*\tmprotate {} % just to check we don’t overwrite something
\newcommand*\tmpoption {} % just to check we don’t overwrite something
\newcommand*\tmpstuff  {} % just to check we don’t overwrite something

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{%
% this is to construct "t1 child [#3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
\edef\tmpstuff {\the#1 child [#3]{\the#2}}%
#1\expandafter {\tmpstuff }%
}

\newcounter{partco}

% 1,2,3,4,5,... -> 1,2,3,1,2,3,1,2,3
\def\pseudomodthree #1{\numexpr #1 + 3 - 3*((#1+1)/3)\relax}

\etocsetstyle{part}
{\etocskipfirstprefix}
% This updates the global tree with the data  from the previous
%  part and all its children sections. Moved here because for some parts the
%  sections are not displayed due to depth tags.
{\ifnum\value{partco}=3
\appendchildtree\treetok\parttok {branch color= green!50,level distance=10cm}%
\else
\ifcase\pseudomodthree{\value{partco}}%
\or \appendchildtree\treetok\parttok {branch color= teal!60}% first
\or \appendchildtree\treetok\parttok {branch color= yellow!80}% second
\else\appendchildtree\treetok\parttok {branch color= green!50}% third and next ...
\fi\fi
}
{\stepcounter{partco}%

% customize manually some TikZ set-up (should be done inside the TikZ thing I guess)
\def\tmpoption {}%
\def\tmprotate {}% first
%\ifnum\value{partco}=5 \def\tmprotate {[counterclockwise from =-40]}\fi
%\ifnum\value{partco}=8 \def\tmprotate {[counterclockwise from =-50]}\fi
% define the part node
 \edef\partnode{node \tmpoption
{\unexpanded\expandafter{\etocthelinkednumber}.
 \unexpanded\expandafter{\etocthelinkedname}}\tmprotate }%
% this is a starting point which will be filled it by the section children
 \parttok\expandafter{\partnode}}
{\ifcase\pseudomodthree{\value{partco}}%
\or \appendchildtree\treetok\parttok {branch color= teal!60}% first
\or \appendchildtree\treetok\parttok {branch color= yellow!80}% second 
\else\appendchildtree\treetok\parttok {branch color= green!50}% third and next ...
\fi
}

\etocsetstyle{section}
{}
{}
{% define the section node
 \edef\childnode{child {node {\unexpanded\expandafter{\etocthelinkednumber}
\unexpanded\expandafter{\etocthelinkedname}}}}%
 % append it to the current \parttok
 \appendtotok\parttok\childnode
}
{}

\etocsettocstyle
{\setcounter{partco}{0}%
 \treetok{\node [root concept]{\textbf{The \etoc documentation}}}}
{\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\etocsetnexttocdepth{section}
% use of depth tags to cut out some sections.
\etocsettagdepth {preamble}   {none}
\etocsettagdepth {overview}   {part}
\etocsettagdepth {arbitrarily} {part}
\etocsettagdepth {examples}   {section}
\etocsettagdepth {surprising}  {part}
\etocsettagdepth {linestyles}  {part}
\etocsettagdepth {globalcmds}  {part}
\etocsettagdepth {custom}     {section}
\etocsettagdepth {tips}       {part}
\etocsettagdepth {etocandworld}{part}
\etocsettagdepth {code}       {section}

\tikzset{
branch color/.style={
concept color=#1!white,
every child/.append style={concept color=#1!white!30!white, font=\normalsize},
}
}%

\begin{figure}[thp!]
\tableofcontents\label{toc:mindmap}%
\centeredline{\resizebox{.85\paperwidth}{!}%
{\begin{tikzpicture}[mindmap,
grow cyclic,
text width=2cm,
align=flush center,
nodes={concept},
concept color=orange!60,
root concept/.append style={text width=4cm, font=\Large},
level 1/.append style={level distance=5cm,sibling angle=40, text width=3cm},
level 2/.append style={level distance=7cm,sibling angle=30, text width=3cm},
level 1 concept/.append style={font=\normalsize},
]
\the\treetok
\end{tikzpicture}}}
\end{figure}
\endgroup

The MWE is a combination of code taken from pgs. 46-49 of "The etoc package", along with setup code for the Preamble from user4686's 2015 answer to an issue in the SE post Visual table of contents (tikz mindmap) - Problem in output.

I also added the following code in an attempt to deal with an issue that occurrs when loading the 'centeredline' package, e.g. '\usepackage{centeredline}':

\def\input@path{{/usr/local/texlive/2022/texmf-dist/tex/latex/centeredline/}}

to eliminate a warning that occurred when compiled.

Any thoughts on what I am missing would be greatly appreciated.

1 Answer 1

2

Don't use the standalone class if you want contents and such. You don't need to define \input@path and I'm not sure what doing so is meant to do.

The code you're using assumes the use of \part, so you need to use parts to get sections etc. to show up. That is, the section code is appended to the part code for the tree. If there is no part node, the section nodes are never used. I've also added some subsections, just to show they are ignored as specified, and deleted some lines which aren't needed for your example.

mind map table of contents

\documentclass[12pt,oneside, tikz, ignorerest=false]{article}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}
\usepackage{etoc}
\usepackage{centeredline}
\begin{document}
\part{Part Level}
If we're appending to \verb|\parttok| we need a part to avoid losing it.
\section{Section level}
\subsection{Surprising uses of etoc}
\begingroup
  \newtoks\treetok % done in preamble
  \newtoks\parttok
  \newcommand*\partnode {}  % just to check we don’t overwrite something
  \newcommand*\childnode {}

  \newcommand*\tmprotate {} % just to check we don’t overwrite something
  \newcommand*\tmpoption {} % just to check we don’t overwrite something
  \newcommand*\tmpstuff  {} % just to check we don’t overwrite something

  \newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
    #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

  \newcommand*{\appendchildtree}[3]{%
    % this is to construct "t1 child [#3]{t2}" from #1=t1 and #2=t2
    % t1 and t2 are two toks variable (not macros)
    % #3 = for example teal!60
    \edef\tmpstuff {\the#1 child [#3]{\the#2}}%
    #1\expandafter {\tmpstuff }%
  }

  \newcounter{partco}

  % 1,2,3,4,5,... -> 1,2,3,1,2,3,1,2,3
  \def\pseudomodthree #1{\numexpr #1 + 3 - 3*((#1+1)/3)\relax}

  \etocsetstyle{part}
  {\etocskipfirstprefix}
  % This updates the global tree with the data  from the previous
  %  part and all its children sections. Moved here because for some parts the
  %  sections are not displayed due to depth tags.
  {\ifnum\value{partco}=3
    \appendchildtree\treetok\parttok {branch color= green!50,level distance=10cm}%
    \else
    \ifcase\pseudomodthree{\value{partco}}%
    \or \appendchildtree\treetok\parttok {branch color= teal!60}% first
    \or \appendchildtree\treetok\parttok {branch color= yellow!80}% second
    \else\appendchildtree\treetok\parttok {branch color= green!50}% third and next ...
    \fi\fi
  }
  {\stepcounter{partco}%
    
    % customize manually some TikZ set-up (should be done inside the TikZ thing I guess)
    \def\tmpoption {}%
    \def\tmprotate {}% first
    %\ifnum\value{partco}=5 \def\tmprotate {[counterclockwise from =-40]}\fi
    %\ifnum\value{partco}=8 \def\tmprotate {[counterclockwise from =-50]}\fi
    % define the part node
    \edef\partnode{node \tmpoption
      {\unexpanded\expandafter{\etocthelinkednumber}.
        \unexpanded\expandafter{\etocthelinkedname}}\tmprotate }%
    % this is a starting point which will be filled it by the section children
    \parttok\expandafter{\partnode}}
  {\ifcase\pseudomodthree{\value{partco}}%
    \or \appendchildtree\treetok\parttok {branch color= teal!60}% first
    \or \appendchildtree\treetok\parttok {branch color= yellow!80}% second 
    \else\appendchildtree\treetok\parttok {branch color= green!50}% third and next ...
    \fi
  }

  \etocsetstyle{section}
  {}
  {}
  {% define the section node
    \edef\childnode{child {node {\unexpanded\expandafter{\etocthelinkednumber}
          \unexpanded\expandafter{\etocthelinkedname}}}}%
    % append it to the current \parttok
    \appendtotok\parttok\childnode
  }
  {}

  \etocsettocstyle
  {\setcounter{partco}{0}%
    \treetok{\node [root concept]{\textbf{The etoc documentation}}}}
  {\global\appendtotok\treetok{ ;}}
  % The \global above is mandatory because etoc always typesets TOC inside a group

  \etocsetnexttocdepth{section}
  \tikzset{
    branch color/.style={
      concept color=#1!white,
      every child/.append style={concept color=#1!white!30!white, font=\normalsize},
    }
  }%

  \begin{figure}[thp!]
    \tableofcontents\label{toc:mindmap}%
    \centeredline{\resizebox{.85\paperwidth}{!}%
      {\begin{tikzpicture}[mindmap,
          grow cyclic,
          text width=2cm,
          align=flush center,
          nodes={concept},
          concept color=orange!60,
          root concept/.append style={text width=4cm, font=\Large},
          level 1/.append style={level distance=5cm,sibling angle=40, text width=3cm},
          level 2/.append style={level distance=7cm,sibling angle=30, text width=3cm},
          level 1 concept/.append style={font=\normalsize},
          ]
          \the\treetok
        \end{tikzpicture}}}
  \end{figure}
\endgroup
\subsubsection{Lower by Two}
\subsubsection{Another Lower by Two}
\subsection{A Lower Level}
\section{Another Top Level}
\end{document}
3
  • 1
    Thank you very much for your suggested code changes. It has been a while (~1.3 yrs) since I posted, but it would be fabulous to implement etoc as a 'TOC as a TikZ mind map' for my project. It will, however, take me a bit of time to do so once I've completed my switch from pdflatex to lualatex as I've been trying to do for the last few weeks. I should have done that sooner, but compelled now to do so as I've hit the main_memory = 12435455 memory limit. Thank you so much again. Apologies in advance if I don't respond successfully a bit more down the road! Thanks again!! Feb 10 at 22:06
  • Yes, sorry. I realise it is a bit late ;). Your question was near the top of some search of the site - no real idea why. I doubt this will do all you'd want to do this properly, but you can follow-up at the time if you get to it. Meanwhile, I answered because I thought it was unlikely to still be useful to you, but it might help somebody else. And because I've always been intrigued by the mind map toc in etoc's manual :).
    – cfr
    Feb 11 at 1:37
  • Actually, as soon as I've completed the pdflatex to lualatex transition (completely new for me), implementing etoc is at the top of my ToDo list. It's good to know that you are around for questions if I have them. Thank you Ssssooo much! Feb 13 at 0:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .