Footnote numbers instead of page numbers in index

The standard index produced by makeindex displays page numbers for each indexed term. Is there a way to display the footnote number (instead of the page number) whenever the indexed term appears in a footnote? The footnote numbers run sequentially throughout the document, so this would localize the reference much better than just qualifying the page number with an "n", say. It's okay to use different indexing macros in footnotes and main text.

• Nice question. But...If you have footnotes rather than endnotes, why is it any harder to locate a reference in a footnote than in all the paragraphs on that page? Jul 14 '16 at 19:11
• Has to do with the document. Some pages may have little main text, but lots of footnote text. A term may also appear in multiple footnotes on the same page, and it would be nice not to have to scan them all. Jul 14 '16 at 20:24

My approach switches \@footnoteindex to true at the begin of a \footnote and sets it to false after \@wrindex.

This is of course a logical error at the moment, since it does not allow another \index usage within \footnote that should use the footnote number as well.

\documentclass{article}

\usepackage{makeidx}

\usepackage{blindtext}

\makeatletter
\let\latex@@footnote\footnote
\newif\if@footnoteindex

\renewcommand{\footnote}[1]{%
\global\@footnoteindextrue
\latex@@footnote{#1}%
}

\def\@wrindex#1{%
\if@footnoteindex
\global\let\the@fooindexstuff\thefootnote
\else
\global\let\the@fooindexstuff\thepage
\fi
\protected@write\@indexfile{}%
{\string\indexentry{#1}{\the@fooindexstuff}}%
\global\@footnoteindexfalse%
\endgroup
\@esphack
}
\usepackage{hyperref}

\makeatother

\makeindex

\begin{document}

\section{A section}
The concept of animals as pets is quite important\index{Animal}
\blindtext[10]\footnote{Stuff\index{Dog}}

\clearpage
Duck\index{Duck}

\blindtext[10]\footnote{Another stuff\index{Cat}}
\clearpage
Elephant\index{Elephant}

\printindex

\end{document}

• I'll try to update...
– user31729
Jul 14 '16 at 19:14
• Resetting footnote numbers might confuse hyperref...
– user31729
Jul 14 '16 at 19:22

Even if you want the footnote numbers in the index instead of page numbers, you still will have to format them differently to distinguish both in the index. In this example, I have made the footnote numbers bold.

The problem is to get the footnote number in the .idx file when it is written. If we should send a \thefootnote, it would give the value of that counter when the index is typeset.

What I have done here is to create a \footnoteindex for using inside footnotes. This command uses \thefootnote which is expanded because it is send as an argument to \index. The page number inserted by \index will be discarded by the additional command \indexbf since the second argument (the page number) is not used.

Since the footnote numbers are not in the place of the page numbers, makeidx can not do the usual nice things with them.

This is the code:

\documentclass{article}

\usepackage{makeidx}\makeindex
\usepackage{lipsum}

\newcommand{\indexbf}[2]{\textbf{#1}}
\newcommand{\footnotexindex}[2]{\index{#1|indexbf{#2}}}
\newcommand{\footnoteindex}[1]{\footnotexindex{#1}{\thefootnote}}

\begin{document}

\setcounter{page}{11}
\setcounter{footnote}{3}

\lipsum[1]\index{first}\footnote{\lipsum[2]\footnoteindex{first foot}\footnoteindex{same foots}}
\lipsum[3]\index{second}\footnote{\lipsum[4]\footnoteindex{second foot}}
\lipsum[5]\index{text and foot}\footnote{\lipsum[6]\footnoteindex{text and foot}\footnoteindex{same foots}}

\printindex

\end{document}