4

We're using the index package in order to get several indexes (name index, subject index, language index), and we're basically happy with it. There's only one obstinate problem: index does not propagate footnote numbers as desired, unlike makeidx (which doesn't support multiple indexes though):

\documentclass{scrbook}

\usepackage{index}
\usepackage{hyperref}

\def\fn#1#2{%
\hyperpage{#2}n#1%
}%

\newcommand{\is}[1]{\if@noftnote%
\index{#1}%
\else%
\index{#1|fn{\thefootnote}}%
\fi%
}

\makeindex

\begin{document}

\footnote{First footnote.}
\footnote{Second footnote.\is{inside second footnote}}
\footnote{Third footnote.}

\printindex

\end{document}

This outputs inside second footnote, 1n3 instead of inside second footnote, 1n2. Hence, \thefootnote seems to be expanded at the very end, and not immediately in the footnote.

Any suggestions how to do it right with index?

Timm
  • 899

2 Answers2

4

The imakeidx package provides multiple index files as well and does expand the footnote number correctly.

\documentclass{scrbook}

\usepackage{imakeidx}
\usepackage{hyperref}

\def\fn#1#2{%
\hyperpage{#2}n#1%
}%

\newcommand{\is}[1]{%
\if@noftnote%
\index{#1}%
\else%
\index{#1|fn{\number\value{footnote}}}%
\fi%
}

\makeindex

\begin{document}

\footnote{First footnote.}
\footnote{Second footnote.\is{inside second footnote}}
\footnote{Third footnote.}

\printindex

\end{document}
1

You have to expand \thefootnote, or it will be essentially written in unusable form in the .idx file:

\documentclass{scrbook}

\usepackage{index}
\usepackage{hyperref}

\newcommand\fn[2]{\hyperpage{#2}n#1}

\makeatletter
\let\if@noftnote\iffalse % just for the example
\newcommand{\is}[1]{%
  \if@noftnote
    \index{#1}%
  \else
    \edef\tempnumber{\thefootnote}%
    \expandafter\footnoteindex\expandafter{\tempnumber}{#1}%
  \fi
}
\makeatother
\newcommand{\footnoteindex}[2]{\index{#2|fn{#1}}}

\makeindex

\begin{document}

\footnote{First footnote.}
\footnote{Second footnote.\is{inside second footnote}}
\footnote{Third footnote.}

\printindex

\end{document}

I guess \if@noftnote is set by some other part of your full code, so I just let it to \iffalse.

enter image description here

egreg
  • 1,121,712
  • I'm sure I must have missed something, but the index entry I'm getting is: "inside second footnote, 1n3". I tried it both in PDFTeX and DVI TeX. Same output. I'm using MacTeX '15. – sgmoye Dec 11 '15 at 12:38
  • @sgmoye As it often happens, I pasted the wrong code, sorry. I'll fix in a moment. – egreg Dec 11 '15 at 13:07