LaTeX songs use tableofcontents
You can use the following redefinition of \beginsong
:
\makeatletter
\renewcommand\beginsong[1]{%
\ifSB@insong\SB@errboo\SB@closeall\fi%
\ifSB@intersong\SB@errbor\SB@closeall\fi%
\SB@insongtrue%
\def\SB@closeall{\endsong}%
\SB@parsetitles{#1}%
\global\setbox\SB@songwrites\box\voidb@x%
\SB@clearbskeys%
\@ifnextchar[\SB@bskvfmt\SB@@beginsong%
\hypersetup{bookmarksdepth=0}%
\phantomsection%
\addcontentsline{toc}{subsection}{\numberline{\thesongnum}#1}%
\hypersetup{bookmarksdepth=2}%
}
\makeatother
to include the songs as subsections in the ToC, with proper bookmarks and hyperlinks from each entry to the corresponding song.
The complete code, using the files provided by the package authors in its downloads section
:
\documentclass[letterpaper]{article}
\usepackage{etoolbox}
\usepackage[bookmarks]{hyperref}
\usepackage[lyric]{songs}
% \includeonlysongs{2}
\makeatletter
\renewcommand\beginsong[1]{%
\ifSB@insong\SB@errboo\SB@closeall\fi%
\ifSB@intersong\SB@errbor\SB@closeall\fi%
\SB@insongtrue%
\def\SB@closeall{\endsong}%
\SB@parsetitles{#1}%
\global\setbox\SB@songwrites\box\voidb@x%
\SB@clearbskeys%
\@ifnextchar[\SB@bskvfmt\SB@@beginsong%
\hypersetup{bookmarksdepth=0}%
\phantomsection%
\addcontentsline{toc}{subsection}{\numberline{\thesongnum}#1}%
\hypersetup{bookmarksdepth=2}%
}
\makeatother
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\topmargin}{0in}
\setlength{\topskip}{0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textheight}{9.1in}
\settowidth{\versenumwidth}{1.\ }
\pagestyle{empty}
\newindex{titleidx}{lbtitle}
\newauthorindex{authidx}{lbauth}
\newscripindex{scripidx}{lbscrip}
\begin{document}
\tableofcontents
\clearpage
\songsection{Worship Songs}
\begin{songs}{titleidx,authidx,scripidx}
\input{songs.sbd}
\end{songs}
\showindex{Index of Authors and Composers}{authidx}
\showindex{Index of Scripture}{scripidx}
\end{document}
An image of the resulting ToC:
The accepted answer to this question unfortunately breaks the song package's parser for \beginsong
. Here's a different approach that uses the songs package's built-in support for new keyvals:
\newcommand\toctitle{}
\newcommand\toclink{}
{\makeatletter\gdef\toclink{\@ifundefined{href}{}{{song\theSB@songsnum-\thesongnum
.\ifnum\value{section}=0 1\else2\fi}}}}
\newcommand\addtotoc[1]{\addtocontents{toc}{\protect\contentsline
{\ifnum\value{section}>0sub\fi section}{\numberline\thesongnum#1}{\thepage}\toclink}}
\newsongkey{toc}
{\def\toctitle{\resettitles\addtotoc\songtitle}}
{\def\toctitle{\addtotoc{#1}}}
\renewcommand\extendprelude{\showrefs\showauthors\toctitle}
This yields the same output as the accepted answer but it
- doesn't break the parser,
- works with or without hyperref loaded,
- works in both chaptered books and sectioned article documents,
- provides a new
\beginsong
keyvaltoc={title}
that lets you customize the title that appears for each song in the table of contents, and - is more likely to remain compatible with future versions of the songs package, since it doesn't redefine any of the package's internal macros.