I am working on a document that contains index items both in the text and in the footnotes. The footnote items are shown differently than the text items. To implement this, I followed this answer and I will use the same mwe to illustrate my page numbers order problem. My desired result is:
index, 1, 1n1, 2n2, 3, 3n3, 5ff.
I have tried two ways:
1.
For index I have defined a markup-range (f., ff.) and it works fine. The problem is the location class order; the location classes follow each other, means, first all item page numbers from the text (\index) and then all from the footnotes (\indexfn). Is there a possibility to build a "mixed" location class order?
mwe-1.tex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt]{scrbook}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage[original]{imakeidx}
\makeindex[program=texindy,options=-M mwe-style -C utf8]
% 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\index{index}.%
\footnote{A footnote\indexfn{index}.} %
\newpage
More text here.\footnote{A footnote\indexfn{index}.}%
\newpage
More text here.\footnote{A footnote\indexfn{index}.}%
Some text here\index{index}.%
\newpage
More text.
\newpage
Some text here\index{index}.%
\newpage
Some text here\index{index}.%
\newpage
Some text here\index{index}.%
\printindex
\end{document}
mwe-style.xdy
;;markup ranges of different length:
(define-location-class "arabic-page-numbers" ("arabic-numbers") :min-range-length 1)
(markup-range :class "arabic-page-numbers" :close ",f." :length 1 :ignore-end)
(markup-range :class "arabic-page-numbers" :close ",ff." :length 2 :ignore-end)
(markup-range :class "arabic-page-numbers" :sep "--")
;;from:https://tex.stackexchange.com/a/330291.
;; 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 ("arabic-page-numbers" "pagefn"))
;; End
If I add "-M ff-ranges" I get a correct order but without f., ff. (I believe for the same reason as described below)
2.
I only use \indexfn everywhere, which is possible, because it recognizes whether it is in the footnote or not. The order is correct. The problem here is that I don't know how to define a markup-range for var-location-class. The documentation says:
... building of ranges is currently only allowed for standard classes
:varand:min-range-lengthmust not be used together.
Is there another possibility that I don't see?
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt]{scrbook}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage[original]{imakeidx}
\makeindex[program=texindy,options=-M mwe-style -C utf8]
% 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\indexfn{index}.%
\footnote{A footnote\indexfn{index}.} %
\newpage
More text here.\footnote{A footnote\indexfn{index}.}%
\newpage
More text here.\footnote{A footnote\indexfn{index}.}%
Some text here\indexfn{index}.%
\newpage
More text.
\newpage
Some text here\indexfn{index}.%
\newpage
Some text here\indexfn{index}.%
\newpage
Some text here\indexfn{index}.%
\printindex
\end{document}

