Previous: User-defined environments, Up: Programming definitions


7.12 Page list and page range parsers

The macros which Eplain uses to parse the page lists and ranges in the index, \idxparselist and \idxparserange (see Page destinations for index terms), are sometimes useful when defining page number encapsulators. They take one argument, text to parse. When a page list (range) is not present, they set \idxpagei to be \empty; when a list (range) is detected, they set \idxpagei and \idxpageii to the first and the second page numbers, respectively.

Eplain's defaults for the page list and page range delimiters are the same as those in MakeIndex, a comma followed by a space (‘, ’) and two dashes (‘--’), respectively. If you customize MakeIndex to use different delimiters, you must not forget to let Eplain know about them with the commands

     \setidxpagelistdelimiter{list-delim}
     \setidxpagerangedelimiter{page-delim}

These commands save the list-delim and page-delim delimiters in \idxpagelistdelimiter and \idxpagerangedelimiter, respectively.

For example, you may want to define a page number markup command which italicizes and properly underlines page ranges by underlining only the page numbers and not the delimiter:

     \def\ituline#1{%
       {\it
       \idxparserange{#1}%
       \ifx\idxpagei\empty
         % The argument is a single page number.
         \underbar{#1}%
       \else
         % The argument is a page range.
         \underbar{\idxpagei}\idxpagerangedelimiter\underbar{\idxpageii}%
       \fi}%
     }

Note that the \ituline macro is not aware of page lists. This is not needed if you use hyperlinks in the index, because \hlidx and \hlidxpage will break up the page lists before calling the user's page encapsulator (see Page destinations for index terms), so \ituline will never see the lists. If, however, you need to design a macro which also takes care of the lists, you can extend \ituline with an additional call to \idxparselist.