xindy:var-location-class 和 ff-ranges;页码顺序问题

xindy:var-location-class 和 ff-ranges;页码顺序问题

我正在处理一个文档,该文档在正文和脚注中都包含索引项。脚注项的显示方式与文本项不同。为了实现这一点,我遵循了答案,我将使用相同的 mwe 来说明我的页码顺序问题。我想要的结果是:

索引,1,1n1,2n2,3,3n3,5ff。

我尝试过两种方法:

1.

对于索引,我定义了一个标记范围 (f., ff.),它工作正常。问题在于位置类别顺序;位置类别相互跟随,这意味着,首先是文本中的所有项目页码 (\index),然后是脚注中的所有项目页码 (\indexfn)。是否有可能构建“混合”位置类别顺序?

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

在此处输入图片描述

如果我添加“-M ff-ranges”,我会得到正确的顺序,但没有 f.、ff。(我相信原因与下面描述的相同)

2.

我只在所有地方使用 \indexfn,这是可能的,因为它可以识别它是否在脚注中。顺序是正确的。这里的问题是我不知道如何为 var-location-class 定义 markup-range。文档说:

... 目前仅允许在标准类中构建范围:var,且:min-range-length不能一起使用。

还有其他我没看到的可能性吗?

%!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}

在此处输入图片描述

相关内容