TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am not able to figure how to do this, and I did look at the etoolbox documentation

The problem is simple to explain: I use etoolbox to append a \clearpage before any \section in a large document so that each section starts on a new page. (it is a book style document, but the MWE below is an article)

There are few sections that are small, and I want to tell etoolbox to not do this for the following section, and then tell it to start again after the section is finished.

How to do this? what is the etoolbox or Latex command for this?

Here is a MWE

\documentclass[12pt]{article}%        
\usepackage{etoolbox}\preto\section{\clearpage}
\usepackage{lipsum}
\begin{document}
\section{A}
\lipsum[75]

\section{B}
\lipsum[75]

%do not add \clearpage here, how? 
\section{C}
\lipsum[75]

%now start adding \clearpage, it is ok
\section{D}
\lipsum[75]
\end{document}

Texlive 2013, Linux mint.

share|improve this question
up vote 10 down vote accepted

A possibility is to create a switch and depending whether the switch is true or false execute the \clearpage command.

\documentclass[12pt]{article}%        
\usepackage{etoolbox}
\usepackage{lipsum}

\newtoggle{clearpagebeforesection}

\preto{\section}{\iftoggle{clearpagebeforesection}{\clearpage}{}}

\begin{document}
\toggletrue{clearpagebeforesection}
\section{A}
\lipsum[75]

\section{B}
\lipsum[75]

%do not add \clearpage here, how? 
\togglefalse{clearpagebeforesection}
\section{C}
\lipsum[75]

%now start adding \clearpage, it is ok
\toggletrue{clearpagebeforesection}
\section{D}
\lipsum[75]

\section{E}
\lipsum[75]
\end{document}
share|improve this answer

One possibility is to create a command that locally (read in group) relaxes \clearpage:

% locally disable clearpage
\newcommand{\specialsection}[1]{
\begingroup
\let\clearpage\relax
\section{#1}
\endgroup
}

This way, \clearpage is set by default to all the sections in the document, but to the \specialsections it doesn't apply.

The complete example:

\documentclass[12pt]{article}%
\usepackage{etoolbox}

\preto\section{\clearpage}

% locally disable clearpage
\newcommand{\specialsection}[1]{
\begingroup
\let\clearpage\relax
\section{#1}
\endgroup
}

\usepackage{lipsum}
\begin{document}
\section{A}
\lipsum[75]

\section{B}
\lipsum[75]

% we use the new command
\specialsection{C}
\lipsum[75]

\section{D}
\lipsum[75]
\end{document}
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.