in my book project, I was inspired by fantastic table of contents display as a mindmap, posted as answer in this question:
Visual table of contents using tikz mindmap or similar
but in my case, the mind map is pretty big and I would like, at least try to, make it span over two A4 pages. For that, I happen to find solution of Mr. Scharrer in answer to this question:
How to include a picture over two pages, left part on left side, right on right (for books)?
However, simple applying mind map code into the command for two page picture led to non-coherent behaviour of the mindmap (even side wasnt fully rendered). I decided to try to generate the table of contents outside of the main document, then include it as a .pdf as stated in solution of second question.
For that, I found a solution from Mr. Oberdiek, using zref package:
but I am having trouble to generate exported table of contents in other format than default one. And TikZ mind-map format is desired.
What have I got until now:
file myreport.text:
\documentclass{book}
\usepackage{zref-abspage,zref-thepage}
\makeatletter
\newcommand*{\pagevaluelabel}[1]{%
\zref@labelbyprops{toc}{abspage}%
}
\makeatother
\AtBeginDocument{%
\addtocontents{toc}{\string\providecommand\string\pagevaluelabel[1]{}}%
\addtocontents{toc}{\string\pagevaluelabel{toc}}%
}
\usepackage{hyperref}
\setcounter{secnumdepth}{4}
\begin{document}
\frontmatter
Title page
\newpage
\chapter*{Foreword}
\tableofcontents
\mainmatter
\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}
file myreport-toc
\documentclass{book}
\usepackage [a3paper,%
landscape,%
twoside,%
inner=2.5cm,%
outer=2.5cm,%
bottom=3.2cm,%
headheight=14.5pt, % Header height
footskip=1.4cm, % Space from the bottom margin to the baseline of the footer
headsep=10pt, % Space from the top margin to the baseline of the header
%showframe, % Uncomment to show how the type block is set on the page
] {geometry}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}
\usepackage{etoc}
\usepackage{hyperref}
\usepackage{zref-xr}
\zexternaldocument[main:]{test}\relax
\makeatletter
\newcommand*{\tocinclude}[1]{%
\begingroup
\makeatletter
\def\@prj{#1}%
\let\contentsline\foreign@contentsline
\input{\@prj.toc}%
\endgroup
}
\def\foreign@contentsline#1#2#3#4{%
\ifx\\#4\\%
\csname l@#1\endcsname{#2}{#3}%
\else
\ifHy@linktocpage
\csname l@#1\endcsname{{#2}}{%
\hyper@linkfile{#3}{\@prj.pdf}{#4}%
}%
\else
\csname l@#1\endcsname{%
\hyper@linkfile{#2}{\@prj.pdf}{#4}%
}{#3}%
\fi
\fi
}%
\begin{document}
\makeatletter
\zref@refused{main:toc}
\setcounter{page}{%
\numexpr\zref@extractdefault{main:toc}{abspage}{1}\relax
}
\renewcommand*{\thepage}{%
\zref@extractdefault{main:thepage\number\value{page}}%
{page}{\arabic{page}}%
}
\tocinclude{myreport}
\clearpage
\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok
\newcommand*\treenode {} % just to check we don't overwrite something
\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 [concept color= #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 [concept color = #3]{\the#2}}%
#1\expandafter {\tmpstuff }%
}
\newcounter{partco}
\etocsetstyle{part}
{}
{}
{\toks0 \expandafter{\etocthelinkednumber}%
\toks2 \expandafter{\etocthelinkedname }%
\stepcounter{partco}%
\ifcase\value{partco}%
\or \def\tmpoption {}%
\def\tmprotate {}% first
\or \def\tmpoption {[concept]}%
\def\tmprotate {[clockwise from = 60]}% second
\else\def\tmpoption {}%
\def\tmprotate {[counterclockwise from = 90]}% third and higher
\fi
% define the part node
\edef\treenode{node \tmpoption {\the\toks0. \the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
\parttok\expandafter{\treenode}}
{}
\etocsetstyle{section}
{}
{}
{\toks0 \expandafter{\etocthelinkednumber}%
\toks2 \expandafter{\etocthelinkedname }%
% define the section node
\edef\treenode {node {\the\toks0 \space\the\toks2}}
\sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
\ifcase\value{partco}%
\or \appendchildtree\parttok\sectiontok {teal!30}% first
\or \appendchildtree\parttok\sectiontok {yellow!40}% second
\else\appendchildtree\parttok\sectiontok {green!30}% third etc...
\fi }
% This updates the global tree with the data from the
% part and all its children sections
{\ifcase\value{partco}%
\or \appendchildtree\treetok\parttok {teal!60}% first
\or \appendchildtree\treetok\parttok {yellow!80}% second
\else\appendchildtree\treetok\parttok {green!50}% third and next ...
\fi
}
\etocsettocstyle
{\treetok{\node{\textbf{My book title}} [clockwise from=60]}}
{\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group
\tableofcontents
%\showthe\treetok % debugging
\begin{tikzpicture}[grow cyclic, text width=2cm,
align=flush center,
every node/.style=concept,
concept color=orange!60,
level 1/.style={level distance=7cm,sibling angle=120},
level 2/.style={level distance=4cm,sibling angle=45}]
\the\treetok
\end{tikzpicture}
\end{document}
I am sorry for this not being an short MWE (not even short question), but I think its a pretty complex one.
I would like to ask, how to put this formatting information (commands \etocsetstyle) into toc extraction procedure in order to produce table of contents as a mind map. Ideally with hyperlinks preserved (but not necessary). Any help would be very much appreciated, even as a nudge which part of documentation read, since I wasnt able to find solution anywhere.
With hope that someone will take interest in this, regards
Tomáš Kruliš


\usepackage{hyperref}to see what I mean). – Ulrike Fischer Jul 31 '19 at 13:16