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 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:

\let\origindex\index
\newcommand\indexoff{\renewcommand\index[2][]{}}
\newcommand\indexon{\let\index\origindex}

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

\indexoff
\include{chapter1}
\indexon
\include{chapter2}
\indexoff
\include{chapter3}

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.)

share|improve this question
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 ....} –  David Carlisle Jul 4 '12 at 19:44
    
related (?) how-can-i-have-2-or-more-distinct-indexes-in-latex –  cmhughes Jul 4 '12 at 19:45
add comment

1 Answer

up vote 5 down vote accepted

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

\includeonly{chapter2}

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

\includeonly{chapter2,chapter3}

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.

share|improve this answer
add comment

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.