    \def\addcontentsline#1#2#3{%
      \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}%
    }%
    %
    \long\def\addtocontents#1#2{%
      \protected@write\@auxout%
          {\let\label\@gobble%
           \let\index\@gobble%
           \let\glossary\@gobble}%
          {\string\@writefile{#1}{#2}}%
    }%
    %
    \def\contentsline#1{\csname l@#1\endcsname}%
    %
    \def\@dottedtocline#1#2#3#4#5{%
        \ifnum #1>\c@tocdepth%
         \else%
    	\vskip \z@ \@plus.2\p@%
            {\leftskip #2\relax%
    	 \rightskip \@tocrmarg
    	 \parfillskip -\rightskip%
    	 \parindent #2\relax\@afterindenttrue%
    	 \interlinepenalty\@M%
             \leavevmode%
             \@tempdima #3\relax%
             \advance\leftskip \@tempdima \null%
    	 \hskip -\leftskip%
            {#4}%
    	\nobreak\leaders\hbox{$\m@th%
    	                       \mkern \@dotsep mu%
    			       \hbox{.}%
    			       \mkern \@dotsep mu$}%
    	        \hfill \nobreak%
    	        \hb@xt@\@pnumwidth{%
    			     \hfil%
    			     \normalfont%
    			     \normalcolor #5}\par}%
        \fi}%
    %
    \def\numberline#1{\hb@xt@\@tempdima{#1\hfil}}%
    %
    \def\hb@xt@{\hbox to}%