Ok this question is old, but I encountered the same problem and had to find a solution. The solution involves a bit of tex hacking and is not generic but you should be able to adapt it to your particular case.
The problem
The index package generates links using the \hyperpage
macro, which takes only one argument: it will print this number and link to the page that has this absolute number.
Ad-hoc solution
Saving the number of pages in the front matter in a macro, then shifting all page anchors by that same number.
In practice
This solution is fragile since if the code of your book style or the hyperref
packages changes, it will not work anymore. Still this is a working solution for me.
I modified the \frontmatter
macro in my book style:
(New lines added are lines 2 and 3, note that we need to decrement by 1 as the computation occurs on the new page numbered '1')
\newcommand\mainmatter{\clearemptydoublepage
\count0=\value{page}\advance\count0 by -1
\xdef\pagesfrontmatter{\the\count0}
\@mainmattertrue\pagenumbering{arabic}}
Then comes a trickier part. The \hyperpage
embeds a lot of code, and can handle for instance arguments like '2,4' or '3-5', so we need to modify the end macro that actually outputs the text and hyperlink. If you look at hyperref.sty
, you will find it named \HyInd@removespaces
. We need to redefine it only for the index so that each link has the same text but the anchor is shifted by the right amount (modified lines are those including references to \count0
):
{ % open local group
% locally change how hyperpage creates hyperlinks to take
% frontmatter pages into account
\makeatletter
\def\HyInd@removespaces#1 #2\@nil{%
\toks@=\expandafter{\the\toks@#1}%
\ifx\\#2\\%
\edef\x{\the\toks@}%
\ifx\x\@empty
\else
\count0=\the\toks@\advance\count0 by \pagesfrontmatter%
\hyperlink{page.\the\count0}{\the\toks@}%
\fi
\else
\ltx@ReturnAfterFi{%
\HyInd@removespaces#2\@nil
}%
\fi
}
\makeatother
\printindex
} % close local group