3

I have a book typesetted in latex with about 30 stories. The stories conform 3 books with stories overlapping, this means story1 appears in book1 and book2, for example.

How can I generate a latex document containing 3 TOCs? each one pointing to the tales corresponding to each "sub book"?

I suspect that the solution should include a way to tell for each story (chapter) to which "sub book"(s) it belongs.

2

Since no example is given, I'll try to provide an answer based on assumptions and minitoc package.

This uses \part as 'subbook' and \parttoc as macro to instruct minitoc to generate a local toc. The local toc title can be changed to by redefinition of the \ptctitle macro.

Note: The minitoc package is about 6 years old, as of writing just now and somehow unmaintained. An alternative might be the usage of etoc package.

\documentclass{book}

\usepackage{minitoc}
\usepackage{filecontents}
\usepackage{blindtext}%

\usepackage[hypertexnames=false]{hyperref}

\makeatletter
\@addtoreset{chapter}{part}
\makeatother


\let\standardptctitle\ptctitle%

\doparttoc

\renewcommand{\partname}{Book}

\begin{filecontents}{story1.tex}
\chapter{Story 1}%
\end{filecontents}

\begin{filecontents}{story2.tex}
\chapter{Story 2}%
\end{filecontents}

\begin{filecontents}{story3.tex}
\chapter{Story 3}%
\end{filecontents}



\begin{document}

\part{Some Stories}
\tableofcontents
\renewcommand{\ptctitle}{\standardptctitle~of \partname~\thepart}
\parttoc

\input{story1}
\input{story2}

\part{More Stories}
\parttoc
\input{story2}
\input{story3}

\part{Even More Stories}
\parttoc

\input{story3}
\input{story1}


\end{document}

enter image description here

Version with etoc package

The etoc package provides an easy access to \localtableofcontents and is maintained. See etoc for more information.

\documentclass{book}

\usepackage{etoc}%
\usepackage{filecontents}
\usepackage{blindtext}%

\usepackage[hypertexnames=false]{hyperref}

\makeatletter
\@addtoreset{chapter}{part}
\makeatother

\let\StandardContentsName\contentsname


\renewcommand{\partname}{Book}

\begin{filecontents}{story1.tex}
\chapter{Story 1}%
\end{filecontents}

\begin{filecontents}{story2.tex}
\chapter{Story 2}%
\end{filecontents}

\begin{filecontents}{story3.tex}
\chapter{Story 3}%
\end{filecontents}



\begin{document}
\tableofcontents% The whole document contents
\renewcommand{\contentsname}{\StandardContentsName~of \partname~\thepart}

\part{Some Stories}
\localtableofcontents

\input{story1}
\input{story2}

\part{More Stories}
\localtableofcontents
\input{story2}
\input{story3}

\part{Even More Stories}
\localtableofcontents

\input{story3}
\input{story1}


\end{document}
|improve this answer|||||
  • Thanks. The problem I see with this solution is that stories are repeated inside the whole book. I don't want that. I want them to appear only once. Can this be achieve? – Juanjo Conti Oct 21 '14 at 22:44
  • @JuanjoConti: * 3 books with stories overlapping, this means story1 appears in book1 and book2, for example.* This could be interpreted as a multiple appearance of the same story. Your question is somewhat not clear and there is no example given – user31729 Oct 22 '14 at 4:41
  • @JuanjoConti I think I interpreted your question (which wasn't that clear:-) the way you intended "overlapping" to be understood. Let me know if not:-) – David Carlisle Oct 22 '14 at 14:19
  • @DavidCarlisle: Yes, it was probably meant that way you did it, but for me it was not clear initially. – user31729 Oct 22 '14 at 14:29
  • I want the stories to be printed only once. Is that clear? :) Thanks a lot. Excuse my english. – Juanjo Conti Oct 27 '14 at 23:11
2

enter image description here

\documentclass{article}

\makeatletter
\let\old@starttoc\@starttoc
\let\old@addcontentsline\addcontentsline
\def\@toc{toc}
\def\@alltoc{tocabc}
\def\@starttoc#1{%
\def\tmp{#1}%
\ifx\tmp\@toc\let\tmp\currenttoc\fi
\old@starttoc\tmp}
\def\addcontentsline#1#2#3{%
\def\tmp{#1}%
\ifx\tmp\@toc
\ifx\currenttoc\@alltoc
\old@addcontentsline{toca}{#2}{#3}%
\old@addcontentsline{tocb}{#2}{#3}%
\old@addcontentsline{tocc}{#2}{#3}%
\else
\old@addcontentsline{\currenttoc}{#2}{#3}%
\fi
\else
\old@addcontentsline{#1}{#2}{#3}%
\fi}
\makeatother


\begin{document}

\def\currenttoc{toca}\def\contentsname{story 1 contents}\tableofcontents
\def\currenttoc{tocb}\def\contentsname{story 2 contents}\tableofcontents
\def\currenttoc{tocc}\def\contentsname{story 3 contents}\tableofcontents


\def\currenttoc{tocabc}
\section{book, the first}

\def\currenttoc{toca}
\subsection{start}
red red blue yellow red red blue yellow
red red blue yellow red red blue yellow

\def\currenttoc{tocb}
\subsection{new start}
one two three four five one two three four five 
one two three four five one two three four five 


\def\currenttoc{tocabc}
\section{book, the second}

\def\currenttoc{tocb}
\subsection{more numbers}
one two three four five one two three four five 
one two three four five one two three four five 

\def\currenttoc{tocc}
\subsection{even newer start}
rome paris london 
rome paris london 
rome paris london 

\def\currenttoc{toca}
\subsection{return to colour}
black blue green black blue green black blue green 
black blue green black blue green black blue green 

\def\currenttoc{tocabc}
\section{book, the third}


\def\currenttoc{tocb}
\subsection{numbers again}
one two three four five one two three four five 
one two three four five one two three four five 

\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.