I'd like to have colored boxes around the titles in my toc. The box should begin at the edge of the page and finish after the end of the chapter name.
I found many solutions for having a box going from the chapter number to the page number. However, I couldn't find one corresponding to my need.
Here is an example of what I am trying to achieve:

Nb : due to font integration issues, I am using XeLatex.
edit
As mentioned before, I need to use XeLatex for unicode support. Hence, Tikz are not a good solution as tikzmark and pgfmark are not well supported (as per Why xelatex renders arrows in tikz figures differently than lualatex? and my many many trials).
I managed to get something working partially:
\documentclass[a4paper,11pt, american]{report}
\usepackage[utf8]{inputenc}
\usepackage{tocloft,tikz}
\usetikzlibrary{calc}
\makeatletter
\newcommand{\gettikzxy}[3]{%
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\edef#2{\the\pgf@x}%
\edef#3{\the\pgf@y}%
}
\makeatother
\newcommand*{\tikzcoordinate}[1]{%
\tikz[remember picture, overlay] \coordinate (#1);}
\renewcommand{\cftchapfont}{%
\tikzcoordinate{A}
\bfseries\Large%
}
\renewcommand{\cftchappagefont}{\bfseries}
\renewcommand{\cftchapleader}{%
\tikz[remember picture,overlay]{%
\coordinate (C);%
\coordinate (B) at (current page.west|- A);
\gettikzxy{(A)}{\ax}{\ay}
\gettikzxy{(B)}{\bx}{\by}
\gettikzxy{(C)}{\cx}{\cy}
\fill[red,opacity=.2] ([yshift=+1.3333em,xshift=-.3333em]B) rectangle
([xshift=.3333em,yshift=+-1ex]C |- 0,0);
\ifx\by\cy
\else
\coordinate (D) at (\cx+.3333em,\by+1.3333em);
\coordinate (E) at (\ax-.8em+\linewidth- \cftchapindent- \cftchapnumwidth,\cy+1em);
\gettikzxy{(D)}{\dx}{\dy}
\gettikzxy{(E)}{\ex}{\ey}
\ifdim\dx<\ex
\fill[red,opacity=.2] (D) rectangle (E);
\else
\fill[white,opacity=1] (D) rectangle (E);
\fi
\fi
}%
\bfseries\cftdotfill{\cftdotsep}%
}
\begin{document}
\tableofcontents
\chapter{(title chapter 1)}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\chapter{(veryvery very very very very very very very very very very very very very very very very very very very very very long title chapter 2)}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\chapter{(very very very very very very very very long title chapter 3)}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\end{document}
Now, my problem is that I need the color to be on the background to allow the text to be written in white on top of it. Any clue on how to do that with XeLatex ?


(current page.west). A solution using tikzmark will already use[remember picture,overlay]. Otherwise you may needpgfinterruptboundingbox/ – John Kormylo Feb 18 '23 at 14:41