# Using imakeidx with custom page numbering

I am using the imakeidx package to generate an index for some course notes. The problem is that the document uses a different page numbering system: it is divided into "lectures" and numbers the pages within the lecture

\numberwithin{page}{lecture}


This causes imakeidx (and plain makeidx) to quit working. Any thoughts for how I can get around this?

Edit: here is a minimal example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{imakeidx}
\makeindex
\numberwithin{page}{section}
\begin{document}
Test\index{Test1}
\printindex
\end{document}


Compiling this produces no errors but does not generate an index. Commenting out line number 5 (\numberwithin{page}{section}) causes the index to be generated.

• quit working is not really helpful. Can you provide us with a minimal working document that shows this feature?
– user31729
Mar 11 '16 at 19:42
• Sure. See edited post.
– Mr.P
Mar 14 '16 at 18:11
• MakeIndex is not able to deal with complex page numbers, so it rejects entries with something like 1.2 as page number. Do you plan to have subitems? Mar 14 '16 at 19:04
• egreg: It would be great to have the option for subitems in the index. However I'll settle for not having them if necessary.
– Mr.P
Mar 15 '16 at 14:40
• This is a MakeIndex problem. Feb 8 '17 at 21:19

It is possible to provide some support for sorting even for page numbers that aren't just normal figures, but setting the page_compositor "." tag in a makeindex .ist file, assuming that no more than one dot occurs in the output.

The document writes a pagesection.ist index style file with the relevant settings and uses imakeidx with the options=-s pagesection.ist key to apply this file to the makeindex run.

\documentclass{article}
\usepackage{amsmath}
\usepackage{imakeidx}
\usepackage{blindtext}

\makeindex[name=pagesection,title={List of something},options=-s pagesection.ist]

\begin{filecontents}{pagesection.ist}
page_precedence "nrRAa"
page_compositor "."
\end{filecontents}

\numberwithin{page}{section}
\begin{document}

\section{Foo section}
Test\index[pagesection]{Test1}
\index[pagesection]{Test2}
\index[pagesection]{foo!bar}

\blindtext[5]
\index[pagesection]{Test2}

\blindtext[10]

\index[pagesection]{foo!bar}

\printindex[pagesection]
\end{document}


A related question is Index by section.subsection