[Tex/LaTex] Customizing Index – Adding chapter heading and verse number to index entries

indexingverse

I would like to provide the chapter title and the verse number for each entry in the index. This is unusual but the book I am working on requires such formatting.

In the output I want the chapter title to appear between the indexed text and the verse number. For verses I am using the verse environment but do not show here.

In the output shown below, the first line is the header, repeated on each page of the index. Then, based on the three example verses, the desired output:

Indexed text, Chapter Name, Verse Number.

Fairest… First… 1

decease… Second… 1

thine… Third… 4

I would like to suppress page numbers in the index.

\documentclass[12pt,a4paper]{book}
\usepackage{index}
\usepackage{idxlayout}
\makeindex

\begin{document}
\printindex

\chapter*{First}
  From \index*{fairest} creatures we desire increase,
  That thereby beauty's rose might never die ... |1|

\chapter*{Second}
  But as the riper should by time \index*{decease},
  His tender heir might bear his memory ... |1|

\chapter*{Third}
  But thou contracted to \index*{thine} own bright eyes,
  Feed'st thy light's flame with self-substantial fuel ... |4|
\end{document}

Best Answer

Maybe:

\documentclass[12pt,a4paper]{book}
\usepackage{splitidx}\makeindex

\newindex[Index of Verses]{vrs}
\AtWriteToIndex{vrs}{\let\thepage\theverse}%
\newcounter{verse}
\newcommand*{\vindex}[2]{%
  \setcounter{verse}{#2}%
  \sindex[vrs]{#1, \currentchapter}%
}
\newcommand*{\xchapter}[1]{%
  \chapter*{#1}\renewcommand*{\currentchapter}{#1}%
}
\newcommand*{\currentchapter}{}

\begin{document}

\xchapter{First}

From \vindex{fairest}{1} creatures we desire increase,
That thereby beauty's rose might never die ... |1|

\xchapter{Second}

But as the riper should by time \vindex{decease}{1},
His tender heir might bear his memory ... |1|

\xchapter{Third}

But thou contracted to \vindex{thine}{4} own bright eyes,
Feed'st thy light's flame with self-substantial fuel ... |4|

\printindex[vrs]

\end{document}

Note, that you have to replace call of makeindex by splitindex. So you should

  1. latex foo.tex
  2. splitindex foo
  3. latex foo.tex

to get the result with Index of Verse. With TeX Live splitindex is a link to splitindex.pl. If you are using Windows and MiKTeX you may either install Perl or use splitindex.exe.

If running splitindex is a problem for you, you may try option split loading package splitidx:

\usepackage[split,makeindex]{splitidx}

In this case you have to run makeindex with file <foo>-vers.idx:

  1. latex foo.tex
  2. makeindex foo-vers
  3. latex foo.tex

Please replace foo by the base name of your test file. See manual of splitindex for more information about running the several variants of the programm splitindex and the options and macros of package splitidx.

Instead of using a second argument at definition of \vindex, you may set the verse numbers by setting counter verse e.g. using an environment or command to set the verses.

Related Question