6

I want to have an index entry typeset as $a_\text{T}$, so I issue the command \index{at@$a_\text{T}$}. Each use of this index command creates a separate line in the index. How can I get \makeindex to recognize they all reference the same topic?

My index entries look like this:

enter image description here

GregH
  • 3,499
  • 2
    Can you show an example? – egreg May 10 '14 at 15:14
  • I've updated the post to include a screenshot; each double entry comes from the same index commands \index{at@$a_\text{T}$} and \index{an@$a_\text{N}$}. – GregH May 10 '14 at 15:19
  • 1
    I think what @egreg meant was can you provide a minimal working example (MWE)? – Nicola Talbot May 10 '14 at 15:23
  • 2
    For solvers: +\usepackage{amsmath} – Malipivo May 10 '14 at 15:29
  • 2
    @GregH We need some code that shows the problem: I trust you when you say you get duplicate entries, but I can't know how you input them. – egreg May 10 '14 at 15:34
  • @GregH I'm not able to replicate your situation too. Á, I think that your problem is that you have different number of spaces in the equations. Try \index{an@$a_\text{N} $} \index{at@$a_\text{T} $} \newpage \index{an@$a_\text{N}$} \index{at@$a_\text{T}$} – Malipivo May 10 '14 at 15:43
  • Do you have one index call inside the argument to a macro, and one not? (but really you should provide an example document, then we'd see) – David Carlisle May 10 '14 at 15:45
  • unrelated but you probably want \mathrm{T} not \text – David Carlisle May 10 '14 at 15:45
  • Just to know: did you delete the temp files and run makeindex again? – Sigur May 10 '14 at 15:54
  • 2
    Having answered I remembered having answered before, this is probably a duplicate of http://tex.stackexchange.com/a/105713/1090 assuming it is the same issue. – David Carlisle May 10 '14 at 15:59
  • 1
    Sorry about the useless pic of the index - an MWE would have been useful. David's answer helped; one index command was inside a complicated command involving TikZ nodes. Putting the \index{... after the command solved the problem. Thanks. – GregH May 10 '14 at 16:31

1 Answers1

8

Hard to say as you provided no example but I'd guess you have done this:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage{makeidx}
\makeindex
\begin{document}

zz\index{at@$a_\mathrm{T}$}

zz\mbox{zz\index{at@$a_\mathrm{T}$}}

\printindex

\end{document}

One argument is read verbatim and the other not, resulting in an idx file like

\indexentry{at@$a_\mathrm{T}$}{1}
\indexentry{at@$a_\mathrm  {T}$}{1}

with different entries. The easiest solution is to wrap both in the same command. If you put \mbox (or anything) around the first \index then the index entries are merged.

David Carlisle
  • 757,742
  • I noticed when you add \mbox then the next word doesn't get hyphenated. Maybe this is only happening in my setup but be sure to check it out. – Martin Mueller Feb 03 '17 at 09:34
  • a "word" has to be preceded by white space to be considered a word to be tried for hyphenation, so \mbox{} abcdef" would not try hyphenatingabcdefyou can use\mbox{} \hspace{0pt)abcdef" for example @MartinMueller – David Carlisle Feb 03 '17 at 09:43
  • my problem was that i have the index behind the word: "Romeo\indexentry{Shakespeare!Romeo and Juliet}, a play" when used with mbox. When I would add \hspace{0pt} and have a comma afterwards it would move that comma to the next line. – Martin Mueller Feb 03 '17 at 11:11
  • @MartinMueller you have never provided any test file so it is hard to guess what you are doing, but a box after a word does not stop hyphenation, just one before, also you can always use \nolinebreak to prevent a break at the 0pt space, but why are you using \mbox at all? – David Carlisle Feb 03 '17 at 11:51
  • sorry, you're right, I didn't do it properly. I played around with your solution because i have a command \emph{ } within my entry and the whole whitespace-duplicate entries started. but I have it fixed now with splitindex, protected and an additional parenthesis around the \newcommand{\foo}[1]{{\sindex[foo]{#1}} so I just wanted to leave a small comment. – Martin Mueller Feb 03 '17 at 11:58