# Sorting problem with index entries for footnotes as page-n-footnote

I am working on an index for a large scientific manuscript. I would like to have index entries occurring as footnotes to be in the index as page-n-footnote. Courtesy of brannerchinese's code in this forum I have nearly got the problem solved. The issue is that the footnoted indices are not properly sorted. The "Tiger" entry in the index is output as

Tiger, i, 1 Tiger, in1

when it should be

Tiger, i, in1, 1

The .idx entries are of the form

\indexentry{Tiger}{i}
\indexentry{Tiger@Tiger|pageandfn{1}}{i}


and the .ind entries of the form

\item Tiger, i, 1
\item Tiger, \pageandfn{1}{i}


Here's the code:

\documentclass[10 pt,twoside]{memoir}
\chapterstyle{ell}
\usepackage{imakeidx}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\makeindex
\makeatletter
\let\latex@roman\@roman
\makeatother
\usepackage[russian,greek,english]{babel}
\makeatletter
\let\@roman\latex@roman
\makeatother

%these next two commands from
%https://tex.stackexchange.com/questions/328833/page-n-footnote-number-in-index-with-texindy

\newcommand{\pageandfn}[2]{#2n#1}
\newcommand{\indexfn}[1]{\index{#1@#1|pageandfn{\thefootnote}}}
\pagestyle{ruled}
\begin{document}

\frontmatter
\chapter{Preface}
Here's a page and a footnote for the front matter.     Elephant.\index{Elephant} Tiger.\footnote{Tigers are ferocious!\indexfn{Tiger}}\index{Tiger}

\mainmatter
\chapter{First things first}
Here's a page and a footnote for the main matter.\footnote{Cobras are   dangerous!\indexfn{Cobra}} Red panda \index{Red panda} \index{Tiger}

\indexprologue{\noindent\textbf{Bold} page numbers indicate where a term   is defined; page numbers for entries occuring in a footnote are followed   by an \emph{n} and the footnote number.}
\printindex
\end{document}


Here's the .idx file:

\indexentry{Elephant}{i}
\indexentry{Tiger}{i}
\indexentry{Tiger@Tiger|pageandfn{1}}{i}
\indexentry{Red panda}{1}
\indexentry{Tiger}{1}
\indexentry{Cobra@Cobra|pageandfn{1}}{1}

And here's the .ind file:

\begin{theindex}

\item Cobra, \pageandfn{1}{1}

\indexspace

\item Elephant, i

\indexspace

\item Red panda, 1

\indexspace

\item Tiger, i, 1
\item Tiger, \pageandfn{1}{i}

\end{theindex}


Apologies for my cluelessness, and many thanks to the group members for much help over the years!

I'm not quite sure why makeindex makes

\indexentry{Tiger}{i}
\indexentry{Tiger@Tiger|pageandfn{1}}{i}


into two seperate entries. I was wondering why the use of #1@#1 in this macro

\newcommand{\indexfn}[1]{\index{#1@#1|pageandfn{\thefootnote}}}


Indeed, if we change it to

\newcommand{\indexfn}[1]{\index{#1|pageandfn{\thefootnote}}}


then makeindex folds the entries into a single Tiger.

I normally use xindy for indexing, and it will automatically fold both into the same entry (using the original macro definitions), but it will ignore the |pageandfn{1} part. We might be able to get it to work with the right xindy configuration, but the |xxx support in xindy is quite limited

• @dderbes remember to hit the check mark to accept the answer – daleif Aug 2 '18 at 15:22