2012-09-01

Shown on Heading, not in Table of Contents

Issue

By the reason on layouting, sometimes there is "somestuff" I should write in a heading command such as \section. It is also shown in the table of contents by \addcontentsline used by \section. But "somestuff" should be enabled only on the heading, not the table of contents. How can I solve that?

Solution

In the document preemble (or style file):
\makeatletter

\let\if@notinaddcontentsline\iftrue
\let\@oldaddcontentsline\addcontentsline
\def\dontaddcontentsline#1{%
  \if@notinaddcontentsline #1 \fi}
\def\addcontentsline#1#2#3{%
  \let\if@notinaddcontentsline\iffalse  
  \@oldaddcontentsline{#1}{#2}{#3}
  \let\if@notinaddcontentsline\iftrue}

\makeatother
Then, write my heading:
\section{foobar\dontaddcontentsline{\\}baz}

0 件のコメント:

コメントを投稿