My indexed terms are hyperlinks (to external files — see question listed below), so the page numbers are really not useful information. Hece I would like to be able to remove the page number (and the comma preceding the page number).
The MWEs below produce the image on the left, but I would like it to produce the image on the right:
Would be nice if one solution worked with all the packages, but package specific solutions are ok too. I am using imakeidx
so that would be most helpful to me.
References:
- This is a follow up to Index hyperlinks to open a PDF file.
- List of Indexing Packages – Pros and Cons
Code: imakeidx
\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}
\makeindex[columns=1]
\begin{document}
Test\index{foo}
\index{bar}
\printindex
\end{document}
Code: makeidx
\documentclass{article}
\usepackage{makeidx}
\usepackage{hyperref}
\makeindex
\begin{document}
Test\index{foo}
\index{bar}
\printindex
\end{document}
Best Answer
UPDATED ANSWER
I answer this question for two index processors:
makeindex
andtexindy
. Both examples use the packageimakeidx
to simplify the compilation.texindy
With
texindy
you have to compile with the optionshell-escape
.First of all I set the option
texindy
of the packageimakeidx
to specify the index processor.The
options
specify what will be passed as an argument totexindy
. The option-M mystyle.xdy
means thattexindy
use the style filemystyle.xdy
.the algorithm
Before I explain the code I want to explain the algorithm which I use.
texindy
style. So I can change it by setting them inside the style file.Every page number of the index entry can be surrounded and modified with a command. To suppress the output of the page number, I can use the LaTeX kernel command
\@gobble
which is simply defined asThese modification must be executed after the sorting algorithm of the index processor. So you can't remove the page of
\indexentry
.Now the implementation.
The index processor
texindy
(and alsomakeindex
) can't handle LaTeX commands with an@
symbol, because@
is a special character for the index processor. So I defined a command equal to\@gobble
The usage will be explained later. Next I have to manipulate the command
\index
so that every page number of the the commandindex
will be modified. Therefore you can use the expansion|
. For example to print a bold page number you use\index{foo|textbf}
. Thetextbf
is a predefined attribute of the index processor. Instead oftextbf
I use the attributegobble
. The command\index
provided byimakeidx
has an optional argument so I recommend the macro\LetLtxMacro
provided by packageletltxmacro
instead of\let
Through this redefinition every index command gets the attribute
gobble
. This attribute is defined in the style file for thetexindy
run:In the first line I define a new attribute. In the second line I say what the attribute should do. Here the command
\mygobble
is used. The third line defines the separator to be empty""
.Side note: Comments in a
texindy
style file are introduced with a;
.Altogether we get the following example:
The result is:
makeindex
In relation to
makeindex
here are the options for the packageimakeidx
The option
options
must be set to-s mystyle.ist
because in this way you pass a style file to the index processormakeindex
.makeindex
works with the same algorithm. So the lines are almost identicalUnlike
texindy
,makeindex
doesn't work with attributes. The commandmygobble
without backslash will be passed as an argument of\index
to the processor. The processor will write\mygobble{\thepage}
.The separator must be redefined inside a style file.
delim_0
etc. are the separator of the different levels.Side note: Comments in a
makeindex
style file are introduced with a the same as in LaTeX the%
.So we get the following example with
makeindex
:hyperref support
Remember to load
imakeidx
beforehyperref
.In combination with
hyperref
the approach withmakeindex
doesn't need any special handling. If you usetexindy
in combination with hyperref you have to change the style file*.xdy
in the following way:In the document body you must change the printing of the index as follows to gobble the page numbers:
Here the complete MWE: