[Tex/LaTex] Modify chapter command (and KOMA-script addchap)

chaptersetoolboxheader-footermacrossectioning

Is there something like etoolbox's \appto, that also works for \chapter and \addchap?

edit: I intend to use it to re-enable page numbering (which may or may not be disabled using \renewcommand\thepage{}) after each chapter's first page, but if page numbering is already enabled the chapter's first page should also be numbered.

edit2: I am tryng to create a command, that disables page numbering until next chapter, including the first page of next chapter. I was going to do this by using \renewcommand\thepage{} at first and adding some code to \chapter that checks if page numbering has been disabled (using a toggle) and if it is sets chapter's first page's style to plain and re-enables page numbering.

Best Answer

\appto only works for macros without any parameters. Try \apptocmd (or \pretocmd or \patchcmd) instead. See section 3.4 of the etoolbox documentation for the syntax of these commands and other details.

EDIT: Here's a MWE that removes \clearpage from the definition of \chapter.

\documentclass{report}

\usepackage{etoolbox}
\patchcmd{\chapter}{\clearpage}{}{}{}

\begin{document}

Some text.

\chapter{foo}

Some text.

\end{document}

EDIT 2: In response to your second edit: It's a somewhat strange requirement, but here we go:

\documentclass{book}

\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{etoolbox}
\newbool{emptystyle}
\newcommand*{\emptystyleuntilnextchapter}{%
  \pagestyle{empty}%
  \booltrue{emptystyle}%
}
\patchcmd{\chapter}{%
  \thispagestyle{plain}%
}{%
  \thispagestyle{plain}%
  \ifbool{emptystyle}{%
    \thispagestyle{empty}%
    \pagestyle{headings}%
    \boolfalse{emptystyle}%
  }{%
  }%
}{}{}

\begin{document}

\chapter{foo}

\blindtext[12]

\emptystyleuntilnextchapter

\blindtext[6]

\chapter{bar}

\blindtext[6]

\end{document}
Related Question