I want to add changebars to toc-entries. It actually works fine but I had to disable the command in the \mark commands (so that changebar settles and stops the "rerun" messages in the log-file). The following works but I'm wondering why I have to patch two commands. Why isn't it enough to patch \markboth?
\documentclass{article}
\usepackage{etoolbox}
%must be before babel, as babel redefines markboth:
\patchcmd{\markboth}{\begingroup}{\begingroup\let\cbline\relax}{}{}
\pretocmd{\leftmark}{\let\cbline\relax}{}{}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{changebar}
\newcommand\cbline{}
\DeclareRobustCommand\cbline{\cbstart\cbend}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\begin{document}
\tableofcontents
\section[toc\cbline]{Document}
abc\cbline
\end{document}
Edit
Using \def instead of \let when patching \markboth works:
\patchcmd{\markboth}{\begingroup}{\begingroup\def\cbline{}}{}{}
But I still don't understand why it is necessary as \markboth uses \let for label and index command.
\let\label\relaxworks as expected in\markboth. But I now found the other part: the output routine contains\let\label\@gobble. – Ulrike Fischer May 31 '13 at 09:39