# [Tex/LaTex] How to add \printindex to tableofcontents

I want to add the \indexname to the table of contents and to the bookmarks.

Now, I know one way to do this job: add the follow code before \printindex:

\phantomsection
\cleardoublepage


but I want to move all the styling or customize code to single one .sty file

Anybody knows how to do this through renew \printindex command or some method can define in a .sty file?

\documentclass{book}
\usepackage{makeidx}
\usepackage{hyperref}
\usepackage{lipsum}

\makeindex
\begin{document}

\frontmatter
\tableofcontents

\mainmatter
\chapter{one}
\lipsum[1]
\index{word}

\backmatter
\appendix
\phantomsection
\cleardoublepage
\printindex

\end{document}


Three ways.

1. tocbibind

\usepackage{makeidx}
\makeindex
\usepackage[nottoc]{tocbibind}

2. idxlayout

\usepackage{makeidx}
\makeindex
\usepackage[totoc]{idxlayout}

3. imakeidx

\usepackage{imakeidx}
\makeindex[intoc]


With methods 2 and 3 you have also that the last page of the index is balanced.