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 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

2 Answers 2

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

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

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.