I have a document with hundreds of \index entries. I'm trying to generate the index for some part of the document.

The best I could come up with is to disable the \index command temporarily. I did it like this:


I use it like this to generate the index of, say, chapter 2 only:


Is there a better or cleaner way? (My experience with this sort of macros is rather limited. I'm not even sure what \let does exactly.)

  • 1
    There would be other syntax choices but that looks OK to me. \let defines the new command to have the same definition as the old one so it's like going \newcommand\origindex{... whatever the definition of \index is ....} Commented Jul 4, 2012 at 19:44
  • related (?) how-can-i-have-2-or-more-distinct-indexes-in-latex
    – cmhughes
    Commented Jul 4, 2012 at 19:45

1 Answer 1


You do not have to do all these changes all over the place, there is in fact a very simple out of the box solution.

As you are using \include you can use \includeonly to process only some of your included files (and I guess that fits with what you are looking for anyway :-). In that case the .idx will only contain index entries from the files that you included, e.g., in your example use


and you get only the entries from the file chapter2.tex. Or if you want chapter2 and 3 use


The \include mechanism will save information for cross-references and the TOC but it will not preserve data that goes directly to files other than the .aux files. Thus this offers you precisely what you need and the page references will be correct too as long as you use the include mechanism correctly, i.e., all chapters have been compiled or recompiled when earlier chapters got changed.

There are also packages that offer an interactive usage for \includeonly, for example, the package askinclude.

You must log in to answer this question.

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