3

Is there a way I can make hyperref exclude section/chapter/etc numbering from the link in toc/lof/lot?

I want it becase I highlight the link, and number is not really a part of the section/chapter/etc name.

I searched the manual -- but could not find an option. Perhaps the only way is to redefine some hyperref external command.

Edit:

\documentclass{book}

\usepackage{fontspec} % enagles loading of OpenType fonts
\usepackage{polyglossia} % support for languages

% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setmonofont{DejaVu Sans Mono}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[allcolors=blue,colorlinks]{hyperref}

\begin{document}

\tableofcontents
\chapter{foo}

Foo!

\chapter{bar}

Bar!

\chapter{baz}

Baz!

\end{document}

(supposed to be compiled with XeLaTeX).

1
  • There is probably a cleaner solution, but I think it is possible to do this using the package titletoc and the \titlecontents command. It would be easier to answer if you could provide a minimal working example (MWE).
    – Corentin
    Commented Feb 21, 2013 at 15:26

1 Answer 1

2

A somewhat convoluted method, only for the table of contents:

\documentclass{book}
\usepackage{hyperref}
\usepackage{etoc}
\makeatletter
% store the original table of contents macros
% (they are not modified by hyperref, only \contentsline is)
  \let\latchapter\l@chapter
  \let\latsection\l@section
  \let\latsubsection\l@subsection
%
% then use the etoc package to feed the l@ macros with a filtered out data

\etocsetstyle{chapter}{}{}
{\latchapter{\numberline{\etocthenumber}\etocname}{\etocpage}}{}

\etocsetstyle{section}{}{}
{\latsection{\numberline{\etocthenumber}\etocname}{\etocpage}}{}

\etocsetstyle{subsection}{}{}
{\latsubsection{\numberline{\etocthenumber}\etocname}{\etocpage}}{}
\makeatother
% ready to go!

\begin{document}
\tableofcontents

\chapter{One}
hello
\section{This is a section}
hello
\subsection{a subsection}
hello
\subsection{another subsection}
hello
\section{Another section}
a
\chapter{Two}
b
\section{And one more section}
c
\subsection{an a subsection}
d
\end{document}
3
  • It works! I don't have etoc in repository, so here's a ctan link.
    – Adobe
    Commented Feb 21, 2013 at 20:36
  • 1
    Despite there could be some simpler solutions with e.g. titlesec -- it's nice to have this one also -- since sometimes titlesec is not an option -- for example when it conflicts with some other packages.
    – Adobe
    Commented Feb 21, 2013 at 20:39
  • I am not sure about titlesec/titletoc. A brief look at titletoc has not given me any reason to believe it can separate the number from the name. Both are inside what it calls the label.
    – user4686
    Commented Feb 22, 2013 at 21:26

You must log in to answer this question.

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