TransWikia.com

xindy: var-location-class and ff-ranges; page numbers order problem

TeX - LaTeX Asked by Sim on April 21, 2021

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/
letsvfootnotefootnote
renewcommandfootnote[2][thefootnote]{%
  stepcounter{footnote}%
  gdefinfootnote{T}%
  svfootnote[#1]{#2gdefinfootnote{F}}%
}
gdefinfootnote{F}

% write the footnote number if we're in one
% and 0 otherwise
makeatletter
newcommand{fnind}{if Tinfootnote
@currentlabel%
else 0fi%
}
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}
defformatlocc #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}{thepagespacefnind}{}{}
letxindexfnindex
patchcmd{xindexfn}{@index}{@indexfn}{}{}
patchcmd{xindexfn}{@index}{@indexfn}{}{}
newcommand{indexfn}[2][imki@jobname]{xindexfn[#1]{#2|formatloc}}
makeatother



begin{document}
Some text hereindex{index}.%
footnote{A footnoteindexfn{index}.} %
newpage
More text here.footnote{A footnoteindexfn{index}.}%
newpage
More text here.footnote{A footnoteindexfn{index}.}%
Some text hereindex{index}.%
newpage
More text.
newpage
Some text hereindex{index}.%
newpage
Some text hereindex{index}.%
newpage
Some text hereindex{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

enter image description here

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 :var and :min-range-length must 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/
letsvfootnotefootnote
renewcommandfootnote[2][thefootnote]{%
  stepcounter{footnote}%
  gdefinfootnote{T}%
  svfootnote[#1]{#2gdefinfootnote{F}}%
}
gdefinfootnote{F}

% write the footnote number if we're in one
% and 0 otherwise
makeatletter
newcommand{fnind}{if Tinfootnote
@currentlabel%
else 0fi%
}
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}
defformatlocc #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}{thepagespacefnind}{}{}
letxindexfnindex
patchcmd{xindexfn}{@index}{@indexfn}{}{}
patchcmd{xindexfn}{@index}{@indexfn}{}{}
newcommand{indexfn}[2][imki@jobname]{xindexfn[#1]{#2|formatloc}}
makeatother



begin{document}
Some text hereindexfn{index}.%
footnote{A footnoteindexfn{index}.} %
newpage
More text here.footnote{A footnoteindexfn{index}.}%
newpage
More text here.footnote{A footnoteindexfn{index}.}%
Some text hereindexfn{index}.%
newpage
More text.
newpage
Some text hereindexfn{index}.%
newpage
Some text hereindexfn{index}.%
newpage
Some text hereindexfn{index}.%
printindex
end{document}

enter image description here

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP