0

I'm using the songs package, and I can't change the behaviour of \showindex to add a link to the song name, not the song number in the index.

As far as I could see, I'd have to redefine the \songtarget command, but I wasn't successful. How can I achieve that?

Example (that assumes that the songs package is installed):

\documentclass[letterpaper]{article}
\usepackage[bookmarks]{hyperref}
\usepackage[chorded]{songs}

\newindex{titleidx}{ind}
\titleprefixword{}
\begin{document}
\showindex{Index}{titleidx}
\begin{songs}{titleidx}
\beginsong{Songname}
\beginverse
Song \[C]with chords
\endverse
\endsong
\end{songs}

\end{document}

Then, if that is saved in mwe.tex, you have to run:

$ pdflatex mwe.tex
$ songidx ind.sxd
$ pdflatex mwe.tex
4
  • Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Jun 25, 2015 at 8:06
  • Done. Thanks for the tip =]. I believe that example represents the situation.
    – EuAndreh
    Commented Jun 25, 2015 at 13:52
  • I couldn't find the songs package. I did find songbooks (2010) and leadsheets (2015). Commented Jun 26, 2015 at 3:24
  • Songs package: http://songs.sourceforge.net/
    – EuAndreh
    Commented Jun 26, 2015 at 3:54

1 Answer 1

2

The songs package does not natively support that functionality because, in general, the right-hand-side of any index entry might refer to multiple songs. This is less common in title indexes than in other indexes, but still happens occasionally. For example, in a book with three songs all entitled "You", the index entry looks like:

You.....3, 37, 218

The package only links the items appearing on the right-hand-side, since only those are guaranteed to have unique referents.

Changing this behavior entails redefining the internal package code's \SB@ellipspread macro, which typesets ellipsis lines. (Redefining \songtarget won't help you; that just creates the invisible destination marker to which hyperlinks point, not the links that point to them.) The following code (tested on songs version 2.18) successfully links the left-hand-sides of index entries that have exactly one referent on their right-hand-sides, but leaves left-hand-sides of other entries unlinked. I can't guarantee that it will work in all possible situations, since right-hand-sides of indexes could conceivably contain anything. But it works for the sample book I tested.

\newcommand\savetarget[2]{%
  \gdef\mytarget{#1}%
  \def\songlink##1##2{\global\let\mytarget=\relax}%
}
\newbox\dummybox
{\makeatletter
 \global\let\oldellipsis=\SB@ellipspread
 \gdef\SB@ellipspread#1#2{%
   \global\let\mytarget=\relax
   {\let\songlink=\savetarget
    \setbox\dummybox\hbox{#2}}%
   \oldellipsis{\ifx\mytarget\relax#1\else\songlink{\mytarget}{#1}\fi}{#2}%
 }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .