ヘッダーのテキスト装飾を削除する

ヘッダーのテキスト装飾を削除する

TOC からはハイライトや ToDo などのテキスト装飾を削除できましたが、ヘッダー行からは削除できませんでした。\chapter[]{}テキストを LaTeX に変換するには Pandoc が使用され、現在はオプション パラメータをサポートしていないため、プレーン テキストをオプション パラメータに入れずにこれを行いました。

以下に簡単な 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}

ヘッダーの装飾

\chapter のオプション パラメータを使用せずに、ヘッダー行 (デフォルトおよび fancyhdr 使用時) のハイライト表示を削除するにはどうすればよいでしょうか。または、LaTeX コマンド/マクロを削除して、内部テキストのみを保持することは可能ですか。

ところで、\DeclareRobustCommandおよびはエラーを生成する\let\hl\nohlため回避策です\protect\renewcommand{\hl}[1]{#1}! Illegal parameter number in definition of \reserved@a.

答え1

コマンドが目次またはヘッダーに入力されるかどうかは、 で確認できます\ifx\protect\@unexpandable@protect <code for moving text> \else <normal code> \fi

これを機能させるには、マクロが定義されていることが重要であることに注意してくださいない保護される/「堅牢」。

これを試して:

\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}

関連情報