# More than two page formats for \label / \ref and \index with imakeidx

I'm copying a large antique religious book that has multiple page number formats. In addition to roman and arabic page numbers, there are several additional sections with page numbers such as [1], 1*, and <<1>>. Each section restarts numbering with the value 1, but has different displayed formats.

I need to use labeling/referencing for page references and have various indices I am creating with imakeidx. Each index will have references to the various sections, so some reference items will have page "numbers" in arabic, some roman, some with the various other formats all in the same index.

I'd like to make the \label / \pageref and \index commands work seamlessly with this numbering scheme. A solution that worked very nicely for label/pageref was to redefine \thepage at the start of each section:

\renewcommand{\thepage}{\arabic{page}*} #or maybe \value is better;

Then label and pageref work just fine.

The problem is that this doesn't work with \index, or rather index writes 1* to the appropriate file, but makeindex can't cope with a non-numeric page reference.

Because I'm using imakeidx to create multiple indices, redefining the \index command is somewhat beyond me, as this is redefined by imakeidx already. I think.

Currently, I have a macro that creates the index entries because I'm indexing pieces of music that are imported using the gregoriotex package, and I need to use one of their internal hooks to create the index and label entries for a piece at the proper page to avoid getting the wrong page number.

Is there some clever way to use index entries of the form \index[indexname]{item|format} to accomplish this, keeping in mind that each index will contain entries in all of the different formats?

• makeindex knows about non numeric page numbers (all the latex forms such as alphabetic or Roman) otherwise you can write the page number as a number and then re-style it using the index formatting command |foo defining \foo to reinsert the special page number formatting Jan 13 at 22:06
• I will try. Without |foo, makeindex rejected the non-numeric page numbers. That is, imakeidx (or whatever) wrote 1* to the .idx file but it was rejected as an invalid non-numeric format by makeindex. Jan 13 at 22:21
• yes 1* it won't understand but it can sort a,b,c or i, ii, iii, but arguably they are numeric just but |foo where \foo is \def\foo#1{#1*} would put the * back Jan 13 at 22:26
• Alright - this almost works. I have a follow-on question that has to do with trying to make use of \index{item|foo} within a macro. I guess I should probably post that as a separate question. Jan 14 at 1:31
• Follow on question is here: tex.stackexchange.com/questions/630147/… Jan 14 at 1:46

The above solution in the comments thanks to David Carlisle solves the problem. In my function, I define

\bigfunction{
...
\index{item|foo}
...
}


where foo is defined, e.g.

\newcommand{foo}[1]{#1*}


to get starred page numbers, and similarly for other formats.

I have to then redefine the function \bigfunction at the beginning of each section to get different versions of foo for each section.