# texindy/imakeidx book marks point to incorrect pages with multiple indices

I have two indexes: the Main Index and Name Index. The PDF books are visually correct:

Note that the Name Index starts on Page 6, and the Z entry for the Name Index is on Page 7.

However, up clicking on the Z in the Name Index (which appears on Page 7) I am taken to the Z for the Main Index (Page 6).

This code is adapted form Applying \lowercase to index entries.

## Code:

\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}

\newcommand*\lettergroup[1]{%
\clearpage%
\section*{#1}%
\pdfbookmark[0]{#1}{#1}%
\nopagebreak%
}

% http://tex.stackexchange.com/questions/51688/applying-lowercase-to-index-entries
% #1 = indexed term, #2 = word to index this under
\par\noindent
\lowercase{\def\temp{#3}}%
Indexing: #3%
\if!#1!
\expandafter\index\expandafter{\temp!#2}%
\else
\expandafter\indexopt\expandafter{\temp!#2}{#1}
\fi
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}

\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]

\begin{document}

\clearpage
\printindex

\clearpage
\printindex[Name]
\end{document}

-

Rather than doing manual bookmark placement, I believe it's better to let hyperref work:

\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage{bookmark}

\newcommand*\lettergroup[1]{\subsection{#1}}

% http://tex.stackexchange.com/questions/51688/applying-lowercase-to-index-entries
% #1 = indexed term, #2 = word to index this under
\par\noindent
\lowercase{\def\temp{#3}}%
Indexing: #3%
\if!#1!
\expandafter\index\expandafter{\temp!#2}%
\else
\expandafter\indexopt\expandafter{\temp!#2}{#1}
\fi
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}

\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]
\indexsetup{level=\section}

\begin{document}


The key is, however, to use \subsection for the letter groups, so that they will be children to the index. With \setcounter{secnumdepth}{0} we disable the numbering, and with \indexsetup{level=\section} we tell LaTeX to use \section{\indexname} instead of \section* so that the important actions by hyperref will be performed automatically.