# Combine tocloft and minitoc to create custom lists in document sections

I created custom lists with tocloft and succesfully typeset them as a replacement for a toc (It is about music sheets with songs being grouped in groups of songs). I now would like to have a list of songs at the beginning of each song set, like minitoc provides for toc. Is there a package to serve that purpose or do I have to write this from the ground up. As my TeX knowledge is very limited it would need a lot of larning about basic TeX.

A minimal example sketches my problem The class:

    \NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{songsheets}
[2015/10/01 v0.9h Class for song documentation]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions

\RequirePackage{tocloft}

%table of songs stuff
\renewcommand{\cftdot}{$\cdot$}
\newlistof[songset]{song}{tos}{Songs}
\newlistentry{songset}{tos}{0}
\providecommand*{\toclevel@songset}{0}%
\providecommand*{\toclevel@song}{1}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   sectioning            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%

%definitions for a songset
\def\songsetname{Set}
\if@twoside
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\markboth
\def\songsetmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\let\@oddfoot\@empty
\let\@mkboth\markboth
\def\songsetmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}}}
\fi
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\@gobbletwo
\let\songsetmark\@gobble
\let\sectionmark\@gobble
}
\newcommand*\songsetmark[1]{}
\renewcommand \thesongset {\@Roman\c@songset}
\newcommand\songset{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@%
\@afterindentfalse%
\secdef\@songset%
\@ssongset%
}
\def\@songset[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{songset}%
\typeout{Defsongset \thesongset.}%
{\protect\numberline{\thesongset} #2}%
\else
\fi
\songsetmark{#1}%
\if@twocolumn
\else
\fi}
%   \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}
\def\@ssongset#1{\if@twocolumn
\typeout{Ssongset #1}%
\else
\fi}
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}

%definitions for a song
\def\songname{Title}
\if@twoside
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\markboth
\def\songmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\let\@oddfoot\@empty
\let\@mkboth\markboth
\def\songmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}}}
\fi
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\@gobbletwo
\let\songmark\@gobble
\let\sectionmark\@gobble
}
\newcommand*\songmark[1]{}
\newcommand\song{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@song\@ssong}
\def\@song[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{song}%
\typeout{\songname\space\thesong.}%
{\protect\numberline{\thesong} #2}%
\else
\fi
\songmark{#2}%
\if@twocolumn
\else
\fi}
%   \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
{\Large\bfseries \songname\space\thesong:}
%       \par\nobreak
%       \vskip 20\p@
\fi
\fi
\interlinepenalty\@M
{\Large \bfseries #2}\hfill
}%

\vskip 10\p@
}
\def\@ssong#1{\if@twocolumn
\else
\fi}
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries  #1\par\nobreak
\vskip 40\p@
}}


The document:

\documentclass{songlist}

\begin{document}
\listofsong
\songset{}
I would like to have a table here, showing title1 and title2 as hyperlinks
\song[]{title1}content1
\song[]{title2}content2
\songset{}
I would like to have a table here, showing title3 and title4 as hyperlinks
\song[]{title3}content3
\song[]{title4}content4
\end{document}


To create tables of content at each chapter head, I should use minitoc. But I find no way to combine tocloft and minitoc in a way that the list of songs (named Songs) is given at each songset head just giving the songs in that songset. Does this make the question clear? If not, please don't hesitate to ask for details as I do not know which details you need.

• The answer is a clear yes and no: You did not provide anything to start with – user31729 Oct 9 '15 at 16:16
• Please post a complete Minimum Working Example (MWE). This is a complete but minimal document starting with \documentclass and ending with \end{document} which contains just enough for us to reproduce relevant features of your situation in order to help you. Not only does this make it easier to help (nobody likes setting puzzles up - only solving them). It automatically clarifies your question to at least a considerable extent. Right now, I'd have to do a lot to even try to figure out code which might be worth working on, and then I might not be able to help so... no incentive, really. – cfr Oct 19 '15 at 23:20
• Instructions here – cfr Oct 19 '15 at 23:21
• The working example is now there (original post). But it doesn't do waht I try to achieve. I just added text comments at the location where I want to achive something. – Ulrich Hauser-Ehninger Oct 21 '15 at 15:45
• I reopened because a MWE has been added. – Stefan Kottwitz Nov 5 '15 at 10:08

Here is an approach. I added package etoc to the class file.

Class file songsheets.cls:

% modified by jfbu jeudi 05 novembre 2015 at 15:18:26
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{songsheets}
[2015/10/01 v0.9h Class for song documentation]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions

\RequirePackage{tocloft}
\RequirePackage{etoc}

% tocloft table of songs stuff
\renewcommand{\cftdot}{$\cdot$}

\newlistof[songset]{song}{tos}{Songs}
\newlistentry{songset}{tos}{0}
\providecommand*{\toclevel@songset}{0}
\providecommand*{\toclevel@song}{1}
% moved here
\newcommand*  \songsetmark [1]{}
\renewcommand*\thesongset  {\@Roman\c@songset}
\newcommand*  \songmark    [1]{}

% etoc table of songs stuff
\newcommand*{\tableofsongs}
{%
\begingroup
\@for\@tempa:=part,chapter,section,subsection,paragraph\do
{\etocsetlevel{\@tempa}{6}}%
\etocsetlevel{songset}{0}%
\etocsetlevel{song}{1}%
\etocsetnexttocdepth{song}%
\renewcommand*\contentsname{Songs}%
\tableofcontents
\endgroup
}%
\newcommand*{\localtableofsongs}
{%
\begingroup
\@for\@tempa:=part,chapter,section,subsection,paragraph\do
{\etocsetlevel{\@tempa}{6}}%
\etocsetlevel{songset}{0}%
\etocsetlevel{song}{1}%
\etocsetnexttocdepth{song}%
\localtableofcontents
\endgroup
}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   sectioning            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%

%definitions for a songset
\def\songsetname{Set}
\if@twoside
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\markboth
\def\songsetmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\let\@oddfoot\@empty
\let\@mkboth\markboth
\def\songsetmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}}}
\fi
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\@gobbletwo
\let\songsetmark\@gobble
\let\sectionmark\@gobble
}
% moved to top of file
% \newcommand*\songsetmark[1]{}
% \renewcommand \thesongset {\@Roman\c@songset}
\newcommand\songset{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@%
\@afterindentfalse%
\secdef\@songset%
\@ssongset%
}
\def\@songset[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{songset}%
\typeout{Defsongset \thesongset.}%
% replaced by etoc use of toc file
\else
% replaced by etoc use of toc file
\fi
\songsetmark{#1}%
\if@twocolumn
\else
\fi}
%   \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}
\def\@ssongset#1{\if@twocolumn
\typeout{Ssongset #1}%
\else
\fi}
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}

%definitions for a song
\def\songname{Title}
\if@twoside
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\markboth
\def\songmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\let\@oddfoot\@empty
\let\@mkboth\markboth
\def\songmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}}}
\fi
\let\@oddfoot\@empty\let\@evenfoot\@empty
\let\@mkboth\@gobbletwo
\let\songmark\@gobble
\let\sectionmark\@gobble
}
% \newcommand*\songmark[1]{}
\newcommand\song{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@song\@ssong}
\def\@song[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{song}%
\typeout{\songname\space\thesong.}%
% use of toc file for etoc
\else
% use of toc file for etoc
\fi
\songmark{#2}%
\if@twocolumn
\else
\fi}
%   \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
{\Large\bfseries \songname\space\thesong:}
%       \par\nobreak
%       \vskip 20\p@
\fi
\fi
\interlinepenalty\@M
{\Large \bfseries #2}\hfill
}%

\vskip 10\p@
}
\def\@ssong#1{\if@twocolumn
\else
\fi}
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries  #1\par\nobreak
\vskip 40\p@
}}


Document songlist.tex:

\documentclass{songsheets}
\begin{document}
\tableofsongs
\songset{}
I now have a table here, showing title1 and title2 as hyperlinks.
\localtableofsongs
\song[]{title1}content1
\song[]{title2}content2
\songset{}
I now have a table here, showing title3 and title4 as hyperlinks.
\localtableofsongs
\song[]{title3}content3
\song[]{title4}content4
\end{document}


Output:

Page 1:

Page 3:

Page 9:

Again page 1, to show the hyperlinks as red boxes:

• Thank you very much. I had found etoc in the meantime as well. I have toyed with it a little and am close to a solution. As I have not completely succeeded yet I haven't commented here, but I am pretty sure that etoc is a perfectly working solution here. – Ulrich Hauser-Ehninger Nov 6 '15 at 11:56
• Yes, thank you, this is a solution. I didn't expect etoc and tocloft to work nicely together. – Ulrich Hauser-Ehninger Nov 18 '15 at 14:29