The problem is that \index
expands its contents when it appears as the argument to another command, while it doesn't if it appears at the top level, so with \is{$\langle\rangle$}
you get, in the .idx
file,
\indexentry{0@{$\delimiter "426830A \delimiter "526930B $}}{1}
and, in the .ind
file,
\item {$\delimiter 426830A \delimiter 526930B $}, 1
(notice that the double quotes get lost).
Now TeX finds \delimiter
followed by the number 426830, which is hexadecimal "6834E
and since it's in normal operations, it typesets the math code "0068
: in position "68
of font family 0 there's an h. Similarly, 526930 is hexadecimal "80A52
, but in position "80
there's no character! So you get a roman h, followed by italics A and B. Wow!
A way out is telling TeX not to interpret the characters:
\newcommand{\is}[1]{%
\index{\arabic{occurrence}@\detokenize{#1}}%
\stepcounter{occurrence}}
The argument of \index
doesn't get expanded when written to the .idx
file, so makeindex
is trying to sort \glsfirst{cd}
. Since makeindex
doesn't interpret TeX commands, it views this as a string starting with the backslash character, which is why the entry is considered a symbol. Here's a way of automatically indexing subsequent uses of the acronyms that expands the indexed term before writing it to the .idx
file:
\documentclass[11pt]{article}
\usepackage{makeidx}
\makeindex
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},%
symbol={\the\glsshorttok},%
text={\the\glsshorttok\protect\index{\the\glslongtok\space(\the\glsshorttok)}},%
plural={\the\glsshorttok\noexpand\acrpluralsuffix\protect\index{\the\glslongtok\space(\the\glsshorttok)}},%
first={\the\glslongtok\space(\the\glsshorttok)},%
firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space(\the\glsshorttok)},%
description={\the\glslongtok}%
}
\SetCustomStyle
\newacronym{cd}{CD}{compact disk}
\begin{document}
\noindent
First\index{first} use of \gls{cd}\\
subsequent\index{subsequent} use of \gls{cd}.
\printglossaries
\printindex
\end{document}
Assuming I have the makeindex
headings flag set (via headings_flag 1
in a .ist
file) I get the following index:
If you only want to index some subsequent entries rather than all of them, here's another approach that saves the index command with expanded argument in the user1
field:
\documentclass[11pt]{article}
\usepackage{makeidx}
\makeindex
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},%
symbol={\the\glsshorttok},%
text={\the\glsshorttok},%
plural={\the\glsshorttok\noexpand\acrpluralsuffix},%
first={\the\glslongtok\space(\the\glsshorttok)},%
firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space(\the\glsshorttok)},%
description={\the\glslongtok},%
user1={\protect\index{\the\glslongtok\space(\the\glsshorttok)}}%
}
\SetCustomStyle
\newacronym{cd}{CD}{compact disk}
\begin{document}
\noindent
First\index{first} use of \gls{cd}\\
subsequent\index{subsequent} use of \gls{cd}.
\newpage
Another use of \gls{cd}\glsuseri{cd}.
\printglossaries
\printindex
\end{document}
The index now looks like:
Best Answer
This is usual for an index. Indeed, this is, really, the whole point of an index: people can find stuff provided they know the relevant alphabet.
The index usually comes at the end of a document, especially a book or other longer document. It contains a list of key words and topics with a list of page numbers showing where those words and topics appear in the body of the text.
I strongly suspect that the problem is that you do not really want an index at all. I think that you probably want to produce a table of contents instead.
The table of contents usually comes near the beginning of a document and lists the main divisions of the document in the order in which they appear, usually with the page number on which each section starts. This might include chapters, sections etc.
For example:
If that's what you want, that is actually much easier than an index: