This assumes that your toc file only contains lines in the form
Code: Select all
\contentsline {section}{\numberline {1}Last of the Songs}{1}
(That is, you don't have any \chapters or \addcontentsline etc)
The following is a minimal example:
Code: Select all
\documentclass{article}
\makeatletter
\newcommand{\makesongs}{%
\makeindex
\bgroup
\def\indexsection\numberline##1##2\endindexsection{%
\protected@write\@indexfile{}{\string\indexentry{##2}{##1}}}%
\def\contentsline##1##2##3{\indexsection##2\endindexsection}%
\@input@{\jobname.toc}%
\egroup
}
\newcommand{\listofsongs}{\@input@{\jobname.ind}}
\makeatother
\makesongs
\begin{document}
\tableofcontents
\listofsongs
\section{Last of the Songs}
\section{Song of the Lasts}
\newpage
\section{Example Song}
\end{document}
If this file is called, say, mydoc.tex then \makesongs reads through mydoc.toc and extracts the sectioning information and adds the corresponding line to mydoc.ind. You can then use makeindex to sort this file into alphabetical order, but you need to use a customised makeindex style file to set it in the same style as the table of contents.
To do this create a file called, say, songs.ist that contains the following:
Code: Select all
preamble "\\section*{List of Songs}"
postamble ""
group_skip ""
item_0 "\n\\contentsline\{section\}\{"
delim_0 "\}\{"
delim_t "\}"
headings_flag 0
In order to get the complete document, you need to run latex twice followed by makeindex and then latex again:
Code: Select all
latex mydoc
latex mydoc
makeindex -s songs.ist mydoc.idx
latex mydoc
If the toc file contains lines that don't start with \contentsline{section} then \makesongs would need to be modified so that it checked the start of each line which is a little more complicated.
Hope that helps
Regards
Nicola Talbot