1

Here is a minimum working example:

    % !TEX TS-program = pdflatexmk
\documentclass{book}

\usepackage{xcolor} 
\usepackage{makeidx}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor={red!50!black}}

\makeindex
\begin{document}
%\frontmatter

\Large \textsc{Reasonable Book}

\tableofcontents

%\mainmatter

\chapter{One}   
Some text \textbf{indexed}\index{indexed}   

%\backmatter
\chapter{FDL}
The purpose of this License 

\addcontentsline{toc}{chapter}{Index}   
\printindex
\end{document}

When I click on Indexin the table of contents I get Chapter 2 FDL instead of Index. (Originally, FDL was in backmatter but that did not seem to be where the problem is so here I commented all three "matters" out.)

3
  • 1
    the \addcontentsline for the index has to be on the same page as the start of the index. insert a line \newpage before it, just to make sure. (and keep the blank line above it.) Mar 13, 2016 at 5:23
  • @barbara beeton \newpage alone did not do it for me. But with \phantomsection it did, texhack notwithstanding, More below, though.
    – schremmer
    Mar 13, 2016 at 17:00
  • sorry, i wasn't thinking about clicking on the link; i was thinking more that the page number would be wrong, and that's what \newpage was intended to correct. and yes, \phnatomsection is certainly needed to get a correct hyperlink. Mar 13, 2016 at 21:32

1 Answer 1

2

Using \usepackage[nottoc]{tocbibind} will provide the Index in the ToC without a manual \addcontentsline. (The nottoc is the option if the ToC itself shouldn't be listed additionally in the ToC.)

This has to be followed by a \newpage\phantomsection to be on the safe side.

   % !TEX TS-program = pdflatexmk
\documentclass{book}

\usepackage{xcolor} 
\usepackage{makeidx}
\usepackage[nottoc]{tocbibind}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor={red!50!black}}

\makeindex
\begin{document}
%\frontmatter

\Large \textsc{Reasonable Book}

\tableofcontents

%\mainmatter

\chapter{One}   
Some text \textbf{indexed}\index{indexed}   

%\backmatter
\chapter{FDL}
The purpose of this License 

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

\newpage
\phantomsection
\printindex
\end{document}

Another solution, with imakeidx -- this is shorter and cleaner, in my point of view. An addition, it does automatically generate the index (if \write18 is enabledand allows for splitted/multiple indexes etc.) Just say\makeindex[intoc]

   % !TEX TS-program = pdflatexmk
\documentclass{book}

\usepackage{xcolor} 
\usepackage{imakeidx}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor={red!50!black}}

\makeindex[intoc]
\begin{document}
%\frontmatter

\Large \textsc{Reasonable Book}

\tableofcontents

%\mainmatter

\chapter{One}   
Some text \textbf{indexed}\index{indexed}   

%\backmatter
\chapter{FDL}
The purpose of this License 

\printindex
\end{document}
6
  • 1. As noted above, \newpage along with \phantomsection worked for me without the tocbibind package. 2. In the magnum opus, which uses the Oberdiek "quick and dirty hack" to allow coexistence with showidx, it still works but here the index page starts with the first entry without showing the title. 3. The tocbibind package does not improve on this in the magnum opus. 4. The imakeidx package seems to conflict with the Oberdiek "quick and dirty hack". (TeX capacity exceeded). I have a mwe that I can post in another question if you are interested.
    – schremmer
    Mar 13, 2016 at 17:16
  • @schremmer: I don't have your 'big opus' at hand and whatever 'hacks' are in there, I can't figure out why that fails.
    – user31729
    Mar 13, 2016 at 17:22
  • The magnum opus is at (freemathtexts.org/InProgress/RAFv7.1) and the Oberdiek hack is at (groups.google.com/forum/#!topic/comp.text.tex/fof9f-cln-I). But, as I said, if you want I can post a new question with a mwe.
    – schremmer
    Mar 13, 2016 at 18:09
  • Strange: if I open the pdf with preview, all is well!
    – schremmer
    Mar 13, 2016 at 20:13
  • @schremmer: I used Adobe Reader...
    – user31729
    Mar 14, 2016 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .