Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
I think you need to provide some information about how the verses are organized in each chapter. Does each verse come in an environment of its own (with some counter, say "versenum"?), or does the verse number have to be inferred from some other information? Separately, is my understanding correct that you want to reference the chapter's caption ("First", "Second", ...) rather than its number (which seems to be suppressed anyway)? If so, do the captions generally short (e.g., just one or two pages)? –  Mico Oct 11 '11 at 18:45
    
I did not put anything around verse numbering, I did not use versenum. As of now they are just numbers entered by me. I do want the Chapter name like first second etc. Yes I do want to capture the Chapter's caption rather than number, that confusion came because I used first second etc. I dont know if it helps but each verse will have only one indexed word –  Aku Oct 11 '11 at 19:13
    
Thanks. I've gone ahead and changed a few words in your question to make clearer that you're looking to insert the chapter's caption rather than its number in the index entries. –  Mico Oct 11 '11 at 21:03
    
@Mico - Your example produces just the indexed word and page number but it does not give the chapter name. Is there a way to add chapter name as well? –  Aku Jan 27 '12 at 19:38
    
If memory serves me right, I didn't create the example; all I did, in the process of editing your posting, was to rephrase some of your sentences to make clearer what your objective is (after the comments you and I exchanged). Have you given @Schweinebacke's answer a try? –  Mico Jan 27 '12 at 19:45

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
I copied the above example and tried, in the output there is no index, all I got is chapter heading and the verses. There was no index at the end of the document as shown in your example. –  Aku Nov 7 '11 at 18:09
    
@Aku: Have you run splitindex? I've tested the example and it works! –  Schweinebacke Nov 7 '11 at 18:13
    
pardon my ignorance but how would I run splitindex? –  Aku Nov 7 '11 at 18:14
    
@Aku: Simply replace makeindex by splitindex at the MakeIndex settings of your editor or run it from a terminal (e.g. cmd.exe at Windows). I've added some more information about this at my answer. –  Schweinebacke Nov 7 '11 at 18:29
    
@-Schweinebacke, sorry for the late reply. I was tied in many thing and could not come to this example. I tried your example and it worked great. However after every chapter it is inserting a blank page. Is there anyways to get rid of extra blank page after each chapter. here is the output file docs.google.com/… –  Aku Jan 28 '12 at 16:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.