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.

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.

share|improve this question
    
This is a very general question. Perhaps tell more about what you are trying to achieve, if you don't look just for a general answer. –  Stefan Kottwitz Jul 31 '11 at 14:59
    
In response to your edited question: Normally, there shouldn't be a need to "re-enable" page numbering -- removing the page number from a chapter's first page is done by properly choosing and customizing a page style (normally plain) for these pages. –  lockstep Jul 31 '11 at 15:18
    
Some chapters need to have number on their first page and some do not, depending on previous pages. –  Andres Jul 31 '11 at 15:30
    
In this case, some chapters need a different page style than others. –  lockstep Jul 31 '11 at 15:39
    
How can I define pagestyle for next chapter before the chapter itself? –  Andres Jul 31 '11 at 15:50
show 1 more comment

1 Answer

up vote 4 down vote accepted

\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}
share|improve this answer
    
The following seems to work: \patchcmd{\addchap}{\clearpage}{\clearpage\foo}{}{} and \patchcmd{\chapter}{\clearpage}{\clearpage\foo}{}{} –  Andres Jul 31 '11 at 15:31
    
Sadly this only works for some commands - I can insert text or \LaTeX, but thispagestyle{empty} has no effect. –  Andres Jul 31 '11 at 15:42
    
That might be because \chapter itself calls \thispagestyle{plain} at a later point. As I answered your original question, I suggest you ask a new one and explain exactly what you want to achieve. –  lockstep Jul 31 '11 at 15:47
    
It probably is so. I looked up declaration of \addchap in scrreprt.cls and found the latest possible place to insert my code. Result:\patchcmd{\chapter}{\secdef}{\foo\secdef}{}{} works for page style too. patchcmd is powerful. –  Andres Jul 31 '11 at 16:30
    
I did :-) btw. perhaps \chapterpagestyle could be used also, as the question seems to deal with a KOMA-Script class. –  Stefan Kottwitz Jul 31 '11 at 17:54
show 1 more comment

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.