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}}
You can use glossaries
to do this. I assume you either want to sort your symbols according to definition or to usage since symbols are difficult to sort alphabetically (and your sample isn't alphabetically sorted). With glossaries
you can use the package option sort=def
to sort in order of definition or sort=use
to sort according to usage. In the example below, I've used sort=def
(change \setglossarystyle
to \glossarystyle
if you are using a version of glossaries
prior to version 4.0):
\documentclass{report}
\usepackage{amsfonts}
\usepackage[nomain,section,sort=def]{glossaries}
\usepackage{glossary-mcols}
% (Pre glossaries v4.0 requires \glossarystyle rather than
% \setglossarystyle)
\setglossarystyle{mcolindex}
\renewcommand{\glspostdescription}{\dotfill}
\newglossary[op-glg]{operators}{op-gls}{op-glo}{Operators}
\newglossary[cn-glg]{constants}{cn-gls}{cn-glo}{Constants}
\makeglossaries
% Define a command to define operators
% Syntax: \newoperator[options]{label}{operator symbol}
\newcommand*{\newoperator}[3][]{%
\newglossaryentry{#2}{type=operators,%
name={$#3$},text={#3},description={},#1}%
}
% Similarly for constants
\newcommand*{\newconstant}[3][]{%
\newglossaryentry{#2}{type=constants,%
name={$#3$},text={#3},description={},#1}%
}
% Define operators
\newoperator{Mop}{\mathcal{M}}
\newoperator{Aalpha}{A_\alpha}
\newoperator{nablaOmega}{\nabla_\Omega}
\newoperator{T}{T}
\newoperator{I2}{I_2}
\newoperator{Jz}{J_z}
\newoperator{Gz}{G_z}
% Define constants
\newconstant{pdash}{p'}
\newconstant{jnu}{j_\nu}
\newconstant{Mcn}{\mathfrak{M}}
\newconstant{Dpq}{D_{p,q}}
\begin{document}
\chapter{Sample Chapter}
Some sample usage of constants:
\[
\gls{pdash}, \gls{Mcn}, \gls{jnu}
\]
Some sample usage of operators:
\[
\gls{Mop}, \gls{Aalpha}, \gls{nablaOmega}
\]
\newpage
More sample usage:
\[
\gls{T}, \gls{I2}, \gls{Jz}, \gls{Gz},
\gls{Mcn}, \gls{Dpq}, \gls{jnu}
\]
\chapter*{Index}
\printglossaries
\end{document}
In order to build the PDF you need to do:
- Run
pdflatex
- Run
makeglossaries
- Run
pdflatex
The above example produces:
Page 1:
Page 2:
Page 3:
In your example image, you have some lines with multiple entries (for example, c, c_1, c_2, \ldots, v_n
). There are various ways to deal with these. You could designate the first in the list (e.g, c
) as the main parent entry, and the remainder as sub-entries, and then define a glossary style that puts the sub-entry names after the parent entry name, but this will complicate the location list. However, I think the easiest solution is probably to define an entry with the specified list and then use \glsdisp
or \glslink
whenever you use it.
For example:
\newconstant{c}{c, c_1, c_2, \ldots, v_n}
Then in the document:
In-line: $\glslink{c}{c}$ or $\glslink{c}{c_1}$ or $\glslink{c}{c_2}$ etc.
Best Answer
The symbol
|
is special within the\index
command as it deals with special page ranges. You need to hide this from TeX using something likeAlso note that
\index
takes only one argument which is the index entry. If you want to also print this entry in text, you need to use the following format:virtually duplicating the typeset component and index entry. Here's your MWE with a the above modifications:
Consider reading through Leslie Lamport's MakeIndex : An Index Processor For LaTeX.