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.

In document class book, and package caption, creating index with makeidx. Index entries for the main text and for footnotes collate properly; but those for captions create their own entries.

Example: for the tag \index{New York!Custom House!\textit{Cartouche}}, text and footnotes collate properly; but used in a caption, a new entry is created at the third level, and is also out-of-alphabetic-sequence. Note: the top level, and first sub are correct; only the second sub is duplicated.

How to get the caption index entries under the same entry?

share|improve this question
1  
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Benedikt Bauer Dec 27 '12 at 23:14

2 Answers 2

The problem is in the fact that a "normal text" appearance of

\index{New York!Custom House!\textit{Cartouche}}

writes in the .idx file a line such as

\indexentry{New York!Custom House!\textit{Cartouche}}{1}

while the same in the argument of \caption will have

\indexentry{New York!Custom House!\textit  {Cartouche}}{3}

(the numbers will be different for your document). This is due to how LaTeX processes caption texts. You see that the two lines are different and they are actually very different to MakeIndex.

There's also a problem in how you write the index annotations: formatting instructions are bound to confuse the collating process by MakeIndex. So use

\index{New York!Custom House!Cartouche@\textit{Cartouche}}

in normal text and, for the caption, write something like

\begin{figure}
...
\caption{A caption telling about \textit{Cartouche}%
  \index{New York!Custom House!Cartouche@\string\textit{Cartouche}}}
\end{figure}
share|improve this answer
    
Good - this works - thanks - lingering problem: this throws the sort ordering off for the third-level. The entries treated as above have their own sort-order. I'm experimenting, but it looks like it is descending alphabetical. –  calmbob Dec 28 '12 at 1:46
    
@calmbob Can you make an example? MakeIndex bases the sorting on what comes before the @ –  egreg Dec 28 '12 at 10:40
    
I think I found the flaw in my thinking - I rigorously harmonized use of \textit across all the entries, and all works magically - correctly, that is –  calmbob Dec 28 '12 at 14:04
2  
@egreg -- two points: (1) makeindex bases the combining (if not the sorting) on the entire string within the argument of \index{...}, and (2) \protect will not work here -- it will leave a single space after \textit (unprotected command gets two spaces as seen in your example) -- so it is absolutely necessary to use \string. very un-latex-y, but that's the way it is. –  barbara beeton Dec 28 '12 at 16:35

As an alternative mechanism

An alternative to egreg's solution I was going to post

\newcommand\hmm[1]{#1}

Then you can use

 8\hmm{\index{....}}

You could redefine \index to always do this, this just always prevents the verbatim nature of \index from activating, so you have to be a bit more careful about what you put in the argument, but it does then work consistently in all contexts.

share|improve this answer

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.