8

MakeIndex allows for special formatting of ranges of two, three, or more than three consecutive pages within index entries. One may (with the help of .ist style files) change the range delimiter (by default --) or replace delimiter and end page with a suffix like "sqq.". It is also possible to specify a "ranged" index reference for longer text blocks, using, e.g., \index{bla-par|(} at the start and \index{bla-par|)} at the end of the block. However, formatting of index ranges of exactly two pages is inconsistent: Those created by two "standard" index references on two consecutive pages will use , as delimiter (unlike for longer ranges), while those created by a"ranged" reference will use --. What must be done that either , or -- will be consistently used for all ranges of exactly two pages?

\documentclass{article}

\usepackage{makeidx}
\makeindex

\begin{document}

Some text.\index{bla}\index{foo}\index{gnu}%
    \index{bla-par|(}\index{bla-par|)}\index{foo-par|(}\index{gnu-par|(}

\clearpage

Some text.\index{foo}\index{gnu}\index{foo-par|)}

\clearpage

Some text.\index{gnu}\index{gnu-par|)}

\printindex

\end{document}

enter image description here

6
  • I don't think it's possible to coerce MakeIndex into considering an entry falling in only two consecutive pages as an implicit range.
    – egreg
    Commented Sep 20, 2012 at 12:18
  • @egreg OTOH, MakeIndex allows to replace a two-page range with a suffix using suffix_2p <whatever> in an .ist file.
    – lockstep
    Commented Sep 20, 2012 at 12:24
  • suffix_2p overwrites delim_r but isn't use for your case foo, 1, 2
    – user2478
    Commented Sep 20, 2012 at 12:28
  • @Herbert Actually. suffix_2p "f." will result in foo, 1f. for my example.
    – lockstep
    Commented Sep 20, 2012 at 12:34
  • @lockstep: sorry, I meant that you do not get 1-2 with suffix_2p "--"
    – user2478
    Commented Sep 20, 2012 at 12:40

2 Answers 2

7

If the page numbers are plain arabic numbers, then the following .ist file and some macros split the two-page ranges.

File pagerangemarkup.ist:

\indexentry{bla}{1}
\indexentry{foo}{1}
\indexentry{gnu}{1}
\indexentry{bla-par|(}{1}
\indexentry{bla-par|)}{1}
\indexentry{foo-par|(}{1}
\indexentry{gnu-par|(textbf}{1}
\indexentry{foo}{2}
\indexentry{gnu}{2}
\indexentry{foo-par|)}{2}
\indexentry{gnu}{3}
\indexentry{gnu-par|)}{3}
one@irwin:~/test> mv pag.ist pagerangemarkup.ist
catone@irwin:~/test> cat pagerangemarkup.ist 
delim_0      ", \\IdxPageBegin "
delim_1      ", \\IdxPageBegin "
delim_2      ", \\IdxPageBegin "
delim_n      "\\IdxPageEnd, \\IdxPageBegin "
delim_r      "\\IdxPageEnd\\IdxRange{--}\\IdxPageBegin "
delim_t      "\\IdxPageEnd"
encap_prefix "\\IdxEncapBegin\\"
encap_infix  "{\\IdxPageBegin "
encap_suffix "\\IdxPageEnd}\\IdxEncapEnd"

Test file test.tex (I have added \textbf to get another test case):

\documentclass{article}

\usepackage{makeidx}
\makeindex

\makeatletter
\def\IdxEncapBegin#1\IdxEncapEnd{#1}
\def\IdxPageBegin{%
  \@ifnextchar\IdxEncapBegin{%
    \IdxPage@UnwrapEncap
  }{%
    \IdxPage@Action
  }%
}
\def\IdxPage@UnwrapEncap#1\IdxEncapEnd\IdxPageEnd{%
  #1\IdxEncapEnd
}
\def\IdxPage@Action#1\IdxPageEnd{%
  \def\IdxPage@LastPage{#1}%
  #1%
}
\def\IdxRange#1\IdxPageBegin#2\IdxPageEnd{%
  \ifnum#2=\numexpr(1+\IdxPage@LastPage)\relax
    , %
  \else
    #1%
  \fi
  #2%
}

\begin{document}

Some text.\index{bla}\index{foo}\index{gnu}%
\index{bla-par|(}\index{bla-par|)}\index{foo-par|(}\index{gnu-par|(textbf}

\clearpage

Some text.\index{foo}\index{gnu}\index{foo-par|)}

\clearpage

Some text.\index{gnu}\index{gnu-par|)}

\printindex

\end{document}

Call of makeindex:

makeindex -s pagerangemarkup.ist test

Index

3

run texindy <file>.idx instead of makeindex

3
  • I have never used xindy up to now, but it works indeed (using , as delimiter), so +1. Could you elaborate a bit if there may be also solutions with MakeIndex or if this is a built-in limitation of MakeIndex?
    – lockstep
    Commented Sep 20, 2012 at 12:00
  • I didn't really know, but I suppose that it is a limitation of makeindex because I do not know of any parameter which controls this behaviour.
    – user2478
    Commented Sep 20, 2012 at 12:22
  • Thanks -- if no one comes up with a MakeIndex-based solution within a short time, I will accept your answer.
    – lockstep
    Commented Sep 20, 2012 at 12:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .