I want my index to show those items appearing within a footnote as page-number plus the footnote symbol, for instance, 137n7 for something in footnote 7 on page 137. Following https://tex.stackexchange.com/a/55460/3935, I use a special indexing command within footnotes that works correctly when the .idx file is processed with MakeIndex. The command depends on the meaning (special to MakeIndex) of a pipe within an \index command, to modify the page number of an indexed item.

But I am processing my index with texindy, not MakeIndex, for foreign-language support, and with texindy those special index entries are ignored. The xindy man page explains:

For raw index entries in LaTeX syntax, \index{aaa|bbb} is interpreted differently. For MakeIndex bbb is markup that is output as a LaTeX tag for this page number. For xindy, this is a location attribute, an abstract identifier that will be later associated with markup that should be output for that attribute.

I do not understand how to handle xindy location attributes to get the original effect. It seems to me that because \footnote has to be appended, this is not simple markup that can be done outside of the original to-be-indexed file itself. Xindy markup syntax is described here on the Xindy documentation site.

MWE:

%!TEX encoding = UTF-8 Unicode

\documentclass[12pt]{scrbook}
\usepackage{makeidx}
\makeindex

\newcommand{\pageandfn}[2]{#2n#1}    % format as <page>n<footnotemark>
\newcommand{\indexfn}[1]{\index{#1@ #1|pageandfn{\thefootnote}}}

\begin{document}
Some text here.%
\footnote{Plain footnote\index{footnote, \texttt{\textbackslash index}}.} %

More text here.\footnote{%
Specially indexed footnote\indexfn{footnote, \texttt{\textbackslash indexfn}}.
}

\printindex
\end{document}

Text after compiling once:

Text proper

Footnotes

Here are the contents of the .idx file:

\indexentry{footnote, \texttt  {\textbackslash index}}{1}
\indexentry{footnote, \texttt  {\textbackslash indexfn}@ footnote, \texttt  {\textbackslash indexfn}|pageandfn{2}}{1}

Processed with MakeIndex and then compiled again:

Index when processed with MakeIndex

Processed with texindy and then compiled again:

Index when processed with <code>texindy</code>

Instead of writing just a page number to the index file, one can write a list of the page number and the footnote number, setting the latter to 0 if the item to be indexed is not in a footnote.

Here is how the idea applies to your MWE. It also uses hyperref for further convenience.

mwe-style.xdy:

;; make xindy and hyperindex work together
;; see http://tex.stackexchange.com/questions/80300/how-can-i-convince-hyperref-and-xindy-to-play-together-nicely
;; (the comment by michal.h21)
;; (markup-locref :open "\hyperpage{" :close "}")
;; now taken care of by attribute formatloc


(define-attributes (("formatloc")) )
(markup-locref :attr "formatloc" :open "\formatloc{" :close "}")


(define-location-class "pagefn" :var
     ("arabic-numbers" :sep " "  "arabic-numbers"))

(define-location-class-order ("pagefn"))

;; End

mwe.tex:

%!TEX encoding = UTF-8 Unicode

\documentclass[12pt]{scrbook}

\usepackage{etoolbox}
\usepackage{hyperref}

\usepackage[original]{imakeidx}

\makeindex[program=texindy,options=-M mwe-style]

% test to detect we are in a footnote;
% taken from
% http://tex.stackexchange.com/questions/171681/detect-whether-im-in-a-footnote/
\let\svfootnote\footnote
\renewcommand\footnote[2][\thefootnote]{%
  \stepcounter{footnote}%
  \gdef\infootnote{T}%
  \svfootnote[#1]{#2\gdef\infootnote{F}}%
}
\gdef\infootnote{F}

% write the footnote number if we're in one
% and 0 otherwise
\makeatletter
\newcommand{\fnind}{\if T\infootnote
\@currentlabel%
\else 0\fi%
}
\makeatother


% \formatlocc formats the locations as given in the .ind index files
% \formatloc is a wrapper for \formatlocc to permit braces
\newcommand{\formatloc}[1]{\formatlocc #1}
\def\formatlocc #1 #2{%
\ifnumequal{#2}{0}{\hyperpage{#1}}{\hyperpage{#1}n#2}%
}



% http://tex.stackexchange.com/questions/20894/make-index-entries-refer-to-something-other-than-the-page-numbers/20910#20910
\makeatletter
\let\@indexfn\@index
\patchcmd{\@indexfn}{\@wrindex}{\@Wrindex}{}{}
\let\@Wrindex\@wrindex
\patchcmd{\@Wrindex}{\thepage}{\thepage\space\fnind}{}{}
\let\xindexfn\index
\patchcmd{\xindexfn}{\@index}{\@indexfn}{}{}
\patchcmd{\xindexfn}{\@index}{\@indexfn}{}{}
\newcommand{\indexfn}[2][\imki@jobname]{\xindexfn[#1]{#2|formatloc}}
\makeatother



\begin{document}
Some text here.%
\footnote{Plain footnote\index{footnote, \texttt{\textbackslash index}}.} %

More text here.\footnote{%
Specially indexed footnote\indexfn{footnote, \texttt{\textbackslash indexfn}}.
}

\printindex
\end{document}

Compile using the -shell-escape flag, or run texindy by hand.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.