Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to change the definition of \chapter[...]{...} ‎to‎ \chapter[...]{...‎}‎‎‎\thispagestyle{empty}‎‎.‎ To do this, I'm using the code ‎below:‎

\documentclass{book}
\let\origchapter\chapter
\renewcommand{\chapter}[2][]{%
\origchapter[#1]{#2}
\thispagestyle{empty}
}
\begin{document}
\tableofcontents
\chapter{Bla Bla}
Some text ...
\newpage
\chapter{Bla Bla}
\end{document}

‎Everything is ok, but when I call ‎\tableofcontents‎ after the ‎‎\begin{‎document}‎‎‎,‎ ‎I'll‎ get the following error:‎

! LaTeX Error: Something's wrong--perhaps a missing \item.‎‎

What‎ am I ‎‎doing wrong‎?‎

share|improve this question
2  
If you do not need page style plain, then \makeatletter\let\ps@plain\ps@empty can help. –  Heiko Oberdiek Sep 19 '12 at 18:21

2 Answers 2

up vote 9 down vote accepted

Addition to Werner's answer.

Unknown \chapter

The definition of \chapter might not contain \thispagestyle{empty}, because it is hidden in later called macros or this action looks different. Then the patching as in Werner's answer will fail, because {plain} is missing in the definition text of \chapter. Therefore the following example provides a generic solution, it redefines \chapter with support of the star form and the optional argument:

\documentclass{report}

\makeatletter
\newcommand*{\saved@chapter}{}
\let\saved@chapter\chapter
\renewcommand*{\chapter}{%
  \begingroup
  \toks@{\endgroup\saved@chapter}%
  \@ifstar{%
    \toks@\expandafter{\the\toks@*}%
    \final@chapter
  }{\next@chapter}%
}
\newcommand*{\final@chapter}[1]{%
  \the\toks@{#1}%
  \thispagestyle{empty}%
}
\newcommand*{\next@chapter}{%
  \@ifnextchar[{\opt@chapter}{\final@chapter}%
}
\newcommand*{\opt@chapter}{}
\def\opt@chapter[#1]{%
  \toks@\expandafter{\the\toks@[{#1}]}%
  \final@chapter
}
\makeatother

\begin{document}
\tableofcontents
\chapter*{Chapter with star}
\chapter{Chapter without optional argument}
\chapter[Chapter's optional argument]{Chapter with optional argument}
\end{document}

KOMA-Script

The KOMA-Script classes uses the following definition for \chapter:

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
  \thispagestyle{\chapterpagestyle}%
  \global\@topnum\z@
  \@afterindentfalse
  \secdef\@chapter\@schapter
}

It misses plain, because it is replaced by \chapterpagestyle. However, this macro can be redefined, no need for redefining \chapter:

\renewcommand*{\chapterpagestyle}{empty}

Class memoir

Chapters in memoir support a special page style chapter:

\newcommand\chapter{%
  \ifartopt\par\@nameuse{chapterblock}\else
    \clearforchapter
    \thispagestyle{chapter}
    \global\@topnum\z@
  \fi
  \m@mindentafterchapter
  \@ifstar{\@m@mschapter}{\@m@mchapter}}

The page style can be changed by \aliaspagestyle:

\aliaspagestyle{chapter}{empty}

Full example

The following example catches five cases:

  • \chapter is not available.
  • Class memoir.
  • KOMA-Script classes.
  • Patching via etoolbox's \patchcmd (see Werner's answer).
  • Generic redefinition of \chapter.

The code:

\documentclass{scrreprt}

\makeatletter
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname chapter\endcsname\relax
  \wlog{* No \string\chapter.}%
\else
  \@ifclassloaded{memoir}{%
    % Class memoir
    \aliaspagestyle{chapter}{empty}%
    \wlog{* Chapter page style redefined via \string\aliaspagestyle.}%
  }{%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname chapterpagestyle\endcsname\relax
      % Patching with etoolbox
      \RequirePackage{etoolbox}[2010/09/12]%
      \patchcmd{\chapter}{plain}{empty}{%
        \wlog{* Chapter patched by \string\patchcmd.}%
      }{%
        % Generic case
        \newcommand*{\saved@chapter}{}%
        \let\saved@chapter\chapter
        \renewcommand*{\chapter}{%
          \begingroup
          \toks@{\endgroup\saved@chapter}%
          \@ifstar{%
            \toks@\expandafter{\the\toks@*}%
            \final@chapter
          }{\next@chapter}%
        }
        \newcommand*{\final@chapter}[1]{%
          \the\toks@{#1}%
          \thispagestyle{empty}%
        }
        \newcommand*{\next@chapter}{%
          \@ifnextchar[{\opt@chapter}{\final@chapter}%
        }
        \newcommand*{\opt@chapter}{}%
        \def\opt@chapter[#1]{%
          \toks@\expandafter{\the\toks@[{#1}]}%
          \final@chapter
        }%
        \wlog{* Chapter redefined.}%
      }%
    \else
      % KOMA-Script classes
      \renewcommand*{\chapterpagestyle}{empty}%
      \wlog{* Chapter page style set by redefining \string\chapterpagestyle.}%
    \fi
  }%
\fi
\makeatother

\begin{document}
\tableofcontents
\chapter*{Chapter with star}
\chapter{Chapter without optional argument}
\chapter[Chapter's optional argument]{Chapter with optional argument}
\end{document}
share|improve this answer

Your use of arguments are not optimal, since \chapter{<stuff>} defaults to \chapter[<stuff>]{<stuff>} in the absence of an optional argument, not \chapter[]{<stuff>}. It's better to patch \chapter using etoolbox:

\documentclass{book}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\patchcmd{\chapter}% <cmd>
  {plain}% <search>
  {empty}% <replace>
  {}{}% <success><failure>
\begin{document}
\tableofcontents
\chapter{Bla Bla}
Some text ...
\newpage
\chapter{Bla Bla}
\end{document}

This searches for plain in \chapter and changes it to empty. The original definition of \chapter in book.cls is:

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{plain}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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