I use \addcontentsline for putting an entry for the index in the table of contents, but I don't want the page number and I want a hyperlink. How can I do this?

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[makeindex]{splitidx}
\usepackage{hyperref}
\newcommand{\ITerm}{IndexTerms}
\newcommand{\IServ}{IndexServs}
\newcommand{\MyLarge}{\Large}
\newcommand{\smindexxspecial}[2]{{\MyLarge#2} \sindex[#1]{#2}}
\newcommand{\smindexspecial}[2]{{\MyLarge#2}\sindex[#1]{#2}}
\newcommand{\smindexvspecial}[2]{{\MyLarge#2}\sindex[#1]{#2}}
\newcommand{\smsindexspecial}[2]{{\MyLarge \url{#2}}\sindex[#1]{#2}}
\newindex[General Index]{IndexTerms}
\newindex[Websites]{IndexServs}
\tableofcontents
\printindex[\ITerm]
\printindex[\IServ]
And this is the end of the story.
\end{document}


When I do this one

\addtocontents{toc}{\protect\contentsline {chapter}{General Index}{}{}}


But when I use this one

%\addcontentsline{toc}{chapter}{General Index}


I have page number and a hyperlink.

Also I want it without pagenumber and with hyperlink.

I should mention that this is nothing to do with index termns page but with index names.. I have two index. The first one named as General Index and the other one Websites. I want this index names in table of contents.

• Why should the index have no page number in the TOC? – egreg Oct 18 '13 at 14:20
• @egreg My tutor want this ;) – blue Oct 18 '13 at 14:21
• “Vuolsi così colà dove si puote ciò che si vuole, e più non dimandare” says Virgil to Dante in the “Divine Comedy”: “Thus is wanted where will is power, ask no more” could be a translation. ;-) – egreg Oct 18 '13 at 14:24

With a minimum of different markup in the document, here's a way:

\documentclass{book}
\usepackage{imakeidx}
\usepackage{hyperref}

% This command does the same as \printindex
% but also encloses the entry in the TOC in a group
% and activates the change of meaning of \l@chapter
\newcommand{\printindexnonumber}[1][\jobname]{%
\printindex[#1]
}
\makeatletter
% this command modifies \l@chapter to ignore the page number
\newcommand\nonextpagenumber{%
\let\orig@l@chapter\l@chapter
\def\l@chapter##1##2{\orig@l@chapter{##1}{}}%
}
\makeatother

\makeindex[intoc]

\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A}
Some text\index{text}

\backmatter
\printindexnonumber

\end{document}


So you have only to use \printindexnonumber instead of \printindex; it will be easy to get back if your tutor changes her/his mind.

For your case with splitindex the solution is similar, it's just necessary to patch \theindex so it will make a note in the Table of Contents. (Note: tocbibind doesn't make the correct link.)

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[makeindex]{splitidx}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\theindex}
{}{}
\csname phantomsection\endcsname
}
\makeatother

\newcommand{\printindexnonumber}[1][\jobname]{%
\printindex[#1]
}
\makeatletter
% this command modifies \l@chapter to ignore the page number
\newcommand\nonextpagenumber{%
\let\orig@l@chapter\l@chapter
\def\l@chapter##1##2{\orig@l@chapter{##1}{}}%
}
\makeatother

\newindex[General Index]{IndexTerms}
\newindex[Websites]{IndexServs}

\begin{document}
\frontmatter
\tableofcontents
\printindexnonumber[IndexTerms]
\printindexnonumber[IndexServs]
\mainmatter
\chapter{Title}
And this is the end of the story.
\sindex[IndexTerms]{X}
\sindex[IndexServs]{Y}
\end{document}


I don't see why using \ITerm and \IServ, when the names are just the same. I removed the \smindexxspecial kind macros from the example to keep it minimal. The colorlinks option to hyperref is just for showing that links are produced.

• I think I described my problem wrong. Only the Index Name should be appear in table of contents without pagenumber not the whole index terms. I have two index and they named as general indey and website. I will edit my question, I solve the problem but I need hyperlink too. – blue Oct 18 '13 at 16:10
• @blue I don't understand. My solution works for as many indices as you want and the hyperlink is created to the index page. – egreg Oct 18 '13 at 16:14
• I edited my question. – blue Oct 18 '13 at 16:39