Using counters within \index{...}
gives solutions to the problem of using counters within the \index
command when using \usepackage{makeidx}
, as in
\index{index entry \arabic{counter}}
In this case, \arabic{counter}
is written verbatim
"index entry \arabic{counter}"
to the .idx file rather than being first expanded to something like
"index entry 1".
Solutions given include defining a new macro \Index
or use an \mbox{}
. These solutions work great when using the makeidx
package.
However, neither solution works when using the index
package rather than the makeidx
package. Here is a simple example that was adapted from the above link:
\documentclass{article}
%\usepackage{makeidx}% using this, "\arabic{section}" expands to 1, 2, 3,...
\usepackage{index}% using this, "\arabic{section}" does not expand
\makeindex
\newcommand*{\Index}[1]{\index{#1}}
\begin{document}
\section{First Section} \Index{first \arabic{section}}
\section{Second Section} \Index{second \arabic{section}}
\section{Third Section} \Index{third \arabic{section}}
\section{Fourth Section} \mbox{\index{fourth \arabic{section}}}
\section{Fifth Section} \mbox{\index{fifth \arabic{section}}}
\section{Sixth Section} \mbox{\index{sixth \arabic{section}}}
\printindex
\end{document}
When using \usepackage{makeidx}, the .idx file contains what one might want (expanded counter values):
\indexentry{first 1}{1}
\indexentry{second 2}{1}
\indexentry{third 3}{1}
\indexentry{fourth 4}{1}
\indexentry{fifth 5}{1}
\indexentry{sixth 6}{1}
However, when using \usepackage{index}
, the .idx
file contains what one may not want (verbatim strings/unexpanded counter values):
\indexentry {first \arabic {section}}{1}
\indexentry {second \arabic {section}}{1}
\indexentry {third \arabic {section}}{1}
\indexentry {fourth \arabic {section}}{1}
\indexentry {fifth \arabic {section}}{1}
\indexentry {sixth \arabic {section}}{1}
I want to use the index
package for multi-index support. Does anyone have a solution that can be used with the index
package?
Many many thanks in advance,
Dan
imakeidx
package in order to get multiple indices together with expansionimakeidx
package works great. I tested it both with the above code and with a "real" project. I did have some issues with it involving apparently failing to successfully automatically call makeindex.exe and crashing when \index{...} included \ifthenelse. But these are separate issues and if they are significant enough, I will post them separately. Actually, I'm not too crazy about automatically calling an external .exe anyways, but would rather call it from a makefile.makeindex
is run automatically byimakeidx
, providedshell-escape
is enabled