I'm bit lost with the content of titletoc.sty. I'd like to access toc entries, meaning chapter title, section title and so on to put them in a colorbox. I think it is somewhere in the \def\ttl@tocentry and I'd like to be able to write something like:

\titlecontents{chapter}[0pc]
{\colorbox{red}{chapter title}}
{}
{}
{}%


EDIT: MWE:

\documentclass[12pt]{report}
\usepackage{xcolor}
\usepackage{titletoc}
\titlecontents{chapter}%section
[0pc]%left
{}%above
{}%before with label
{}%before without label
{}%filler and page
[]%after

\begin{document}
\tableofcontents
\chapter{chapter title}
\end{document}

-

As explained in the manual: "As in \titleformat, the last command can take an argument with the title". So:

\titlecontents{chapter}[0pc]
{}
{\colorbox{red}} % the second argument is left implicit
{}
{}%

-
Ok thanks, I'll read the manual again and try to see how I can handle your other response as well (even though I do not feel it is going to be straightforward). – pluton Jun 6 '11 at 11:51

I would redefine the internal definition of chapter

\documentclass[12pt]{report}
\usepackage{xcolor}
\usepackage{titletoc}
\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
{\colorbox{red}{\protect\numberline{\thechapter}#1}}%
\else
\fi
\chaptermark{#1}%
\if@twocolumn
\else
\fi}
\makeatother
\begin{document}
\tableofcontents
\chapter{chapter title}
\end{document}


Here is another solution:

\documentclass[12pt]{report}
\usepackage{xcolor}
\usepackage{titletoc}
\titlecontents{chapter}%section
[0pc]%left
{}%above
{}%before with label
{}%before without label
{}%filler and page
[]%after

\makeatletter

is titletoc needed in your example? I once thought it would be more efficient to redefine the tableofcontents than using titletoc. – pluton Jun 5 '11 at 17:47
I just tried to replace \colorbox by a Tikz picture but it does not work. Seems impossible. – pluton Jun 5 '11 at 18:19