0

I have a LaTeX document featuring these two index entries:

\index{Farbmodell!$\text{LCh}_{ab}$|main}
\index{Farbmodell!$\text{LCh}_{ab}$}

While being "identical" in my view, there are two distinct entries created in the .ind file:

  \item Farbmodell
    \subitem $\text  {LCh}_{ab}$\hspace{1em}\dotfill\hspace{1em}61
    \subitem $\text{LCh}_{ab}$\hspace{1em}\dotfill\hspace{1em}\main{39}

|main just indicates the main index entry, using \newcommand{\main}[1]{\textbf{#1}}. I don't understand where these extra spaces come from.

LaTeX packages being used are:

\documentclass[a4paper,twoside]{report}
\usepackage{german}
\usepackage[latin1]{inputenc}
\usepackage{a4}
\usepackage{makeidx}
\usepackage{showidx}
\usepackage{amsmath}
\usepackage{url}
\usepackage{graphicx}
\usepackage{ifthen}
%
\makeindex
\begin{document}

On output, the relevant index part looks like this: Part of the index output

The first index was entered directly within a section that is part of a chapter, while the second index was entered inside a caption within a table within a section within the appendix. That caption (inside table after tabular) looked like this:

\caption[Pr... im $\text{LCh}_{ab}$ Farbmodell]%
{\label{\Lt{PRMG}}Pr... im $\text{LCh}_{ab}$ Farbmodell%
\index{Farbmodell!$\text{LCh}_{ab}$}
nach \cite[Table~10, S.~15]{ICC.1:2010}}
U. Windl
  • 519
  • 2
    It's necessary to know where and how you define the index entries. I guess the one for page 61 is called in the argument to another macro. By the way, the a4 package is obsolete and deprecated and likewise german: for the first use geometry with suitable parameters, for the latter \usepackage[german]{babel} (or ngerman if you use “neue Rechtschreibung”). – egreg May 06 '19 at 21:36
  • Trying to make a small complete example showed that the index is built correctly there, resulting in \item Farbmodell \subitem $\text{LCh}_{ab}$\hspace{1em}\dotfill\hspace{1em}1, \main{1}. So still: Where do the extra spaces come from? – U. Windl May 06 '19 at 22:37
  • 2
    Move \index outside \caption. – egreg May 06 '19 at 22:45
  • 1
    No these comments are not just "personal taste" as you see in your next question they were warning you that your document will have incorrect hyphenation for example. – David Carlisle May 06 '19 at 22:55
  • My personal style is to add \index immediately after the ndex term. So instead of moving the \index past the caption, I copied it past the caption: Now I have one \index added correctly, and the other wrongly (as stated in the question). So where do these extra spaces come from? – U. Windl May 06 '19 at 22:56
  • @David Carlisle: Convincing arguments beat personal style ;-) I changed the input encoding (without actually understanding the implications). – U. Windl May 06 '19 at 22:58
  • the input encoding doesn't matter (so long as you specify the encoding you are using, it is surprising that is latin1 but if it is, it is) but using the ancient german package, and the a4 package is not likely to lead to a good outcome. – David Carlisle May 06 '19 at 23:00
  • 1
    \index reads its argument verbatim which means that it behaves differently if used in the argument of any other command. Normally the extra spaces don't matter but if you have the same entry you need to always be in a command argument or always not. – David Carlisle May 06 '19 at 23:02
  • So does this mean that \text {LCh} and \text{LCh} are the same thing in TeX, but not for the makeindex program? If so that would sound like a bug in the makeindex program to me. I consider to postprocess the .ind output to "fix" these problems. I'd prefer that over moving the \index elsewhere. – U. Windl May 06 '19 at 23:13

1 Answers1

0

I decided to fix the problem using sed (I had a Makefile anyway).

The Makefile is somewhat complex as it does some other clever things, but here is the core of the solution:

#...
echo "\# fixing $(MAIN).idx"; \
sed -E -e 's/(\\[^ ]+) +\{/\1{/' $(MAIN).idx > $(MAIN).idx~ && \
mv $(MAIN).idx~ $(MAIN).idx; \
echo "\# running makeindex on $(MAIN).idx"; \
$(Do.Makeindex) $(MAIN); \
#...

(Actually I feel LaTeX or makeindex should do that)

U. Windl
  • 519