5

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

enter image description here

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%
}

% https://tex.stackexchange.com/questions/51688/applying-lowercase-to-index-entries
\newcommand*{\AddIndexEntry}[3][]{%
  % #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}

\AddIndexEntry{aardvark}{aardvark}
\AddIndexEntry{Saved by Zero}{Saved}
\AddIndexEntry{Saved by Zero}{Zero}
\AddIndexEntry[Name]{zero}{zero}

\clearpage
\addcontentsline{toc}{}{Main Index}
\printindex

\clearpage
\addcontentsline{toc}{}{Name Index}
\printindex[Name]
\end{document}
3

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
\newcommand*{\AddIndexEntry}[3][]{%
  % #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}

\AddIndexEntry{aardvark}{aardvark}
\AddIndexEntry{Saved by Zero}{Saved}
\AddIndexEntry{Saved by Zero}{Zero}
\AddIndexEntry[Name]{zero}{zero}

\clearpage % we want to be sure that all index entries are output
\setcounter{secnumdepth}{0}
\printindex

\printindex[Name]
\end{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.

  • So, I understand why \indexsetup{\level=\section*} don't print in TOC. Thanks for you solution ! – Zouib May 23 '15 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.