Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the hyperref package to enable PDF links & bookmarks in the output file. I would like to achieve the following behavior ([] denotes clickable area}

1 [The first chapter] .............. 3
2 [The second chapter] ............. 8

When using the linktoc=section option in hyperref, I can achieve this:

[1 The first chapter] .............. 3
[2 The second chapter] ............. 8

Which is not really what I wanted.

Anyone aware of a solution?

share|improve this question
    
Welcome to tex.sx! Note that it is unusual around here to have any greeting. –  lockstep Feb 27 '11 at 17:24
    
@lockstep: Hello :) thanks for such a warm welcoming! Indeed, I am new to the TeX part of stackexchange. I didn't realise that a "Hi," at the beginning was an offense against the tex.sx rules. –  Neo Feb 27 '11 at 18:30
    

1 Answer 1

up vote 5 down vote accepted

The following patch should work:

\usepackage{etoolbox}
\makeatletter
\def\process@contentsline#1#2{#1#2\hyper@linkstart{link}{\toc@link@target}\bgroup}
\patchcmd{\contentsline}{\hyper@linkstart{link}{#4}{#2}\hyper@linkend}{\def\toc@link@target{#4}\process@contentsline#2\egroup\hyper@linkend}{}{}
\patchcmd{\contentsline}{\hyper@linkstart{link}{#4}{#2}\hyper@linkend}{\def\toc@link@target{#4}\process@contentsline#2\egroup\hyper@linkend}{}{}
\makeatother

Insert this code after having loaded the hyperref package. It patches hyperref's version of the contentsline macro (two times, as the part to be replaced occurs twice):

Instead of calling the \hyper@linkstart command which creates the clickable link directly, the newly created \process@contentsline macro is called. It outputs its two arguments directly, without a link - these create the section number. Afterwards, it starts the link which will contain the rest of the text of the contents line.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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