1

I could remove text decorations like highlighting or todos from the TOC but not from the header line. I did this without putting the plain text into the optional parameter of \chapter[]{} because pandoc is used to convert the text to latex and currently does not support optional parameters.

Here is a simple MWE:

\documentclass[oneside]{book}

\usepackage{xcolor}
\usepackage{soul}
\usepackage{todonotes}
\usepackage{lipsum}
\usepackage{ulem}
\DeclareRobustCommand{\nohl}[1]{#1}
\addtocontents{toc}{\begingroup%
  \protect\renewcommand{\protect\todo}[1]{}
  \let\hl\nohl
}
\AtEndDocument{%
  \addtocontents{toc}{\endgroup}
}

\begin{document}

\tableofcontents

{\let\clearpage\relax \chapter{Header with \hl{highlights} and \sout{deletions}}}

\section[A second header with a note]{A second header with a note\todo{keep it}}

\lipsum[1-2]

\end{document}

header decorations

How can I remove the highlighting in the header line (default and with fancyhdr) without using the optional parameter of \chapter? Or is it even possible to remove any latex command/macro and just keeping the inner text?

BTW: the \DeclareRobustCommand and \let\hl\nohl is a workaround because \protect\renewcommand{\hl}[1]{#1} produces the error ! Illegal parameter number in definition of \reserved@a.

1
  • i don't know whether \markright or \markboth are compatible with pandoc, but they ought to be worth investigating. Feb 14, 2018 at 15:58

1 Answer 1

1

You can check whether the command is going into the table of contents or headers with \ifx\protect\@unexpandable@protect <code for moving text> \else <normal code> \fi.

Note that in order for this to work, it's important that the macro so defined not be protected / "robust".

Try this:

\documentclass[oneside]{book}

\usepackage{xcolor}
\usepackage{soul}
\usepackage{todonotes}
\usepackage{lipsum}
\usepackage{ulem}

\makeatletter
\newcommand\ifmoving{%
    \ifx\protect\@unexpandable@protect
        \expandafter\@firstoftwo
    \else
        \expandafter\@secondoftwo
    \fi
}

\let\oldhl\hl
% If you used \DeclareRobustCommand or \protected\def it would not work.
\renewcommand\hl{\ifmoving{}{\oldhl}}
\makeatother


\begin{document}

\tableofcontents

{\let\clearpage\relax \chapter{Header with \hl{highlights} and \sout{deletions}}}

\section[A second header with a note]{A second header with a note\todo{keep it}}

\lipsum[1-2]

\end{document}
6
  • Does it also detect if it is inside a figure or table caption? Feb 15, 2018 at 15:23
  • No, if you can explain what you need I can presumably set you up though. Feb 15, 2018 at 17:03
  • I want to have todonotes as inlines, if they where in a float caption, otherwise in the margin (default). See tex.stackexchange.com/questions/246887 Feb 16, 2018 at 16:10
  • How to implement this for commands which should be removed completely (including its parameters) like \todo? I've tried \renewcommand{\todo}[1]{\ifmoving{}{\oldtodo{#1}}} but then strange side node remains and ! LaTeX Error: Float(s) lost. occurrs. Feb 22, 2018 at 14:11
  • @MathiasWalter That seems like the right thing to do to me. Have you tried \renewcommand\todo{\ifmoving{\@gobble}{\oldtodo}}? Feb 22, 2018 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.