# How to turn on/off \newcommand{\sectionbreak}{\clearpage} per chapter?

I have a book with lots of chapters and many sections in each chapter.

Some chapters, I want to automatically make each section start on new page, but not in some other chapters.

The problem is that \newcommand{\sectionbreak}{\clearpage} from titlesec when added to preamble, has a global effect on the whole document. So all sections in each chapter will start on new page.

Is there a way to control when this command is active (or other solution) so one can turn it on/off at start of the chapter they want each section to start on or not at a new page?

I can of course not use titlesec command at all, and manually add \clearpage before each section in those specific chapters, but this is too much work, as there are many sections and many chapters, and also if later I changed my mind, I have to go edit them all again one by one.

If there is one command per chapter, then I have to turn that off in one place and it will be much easier to maintain also.

Here is a MWE of what I mean

\documentclass[11pt]{scrbook}

\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}%this is global effect

\begin{document}
\chapter{introduction}
%\Need Command Here To turn OFF Starting Each
%Section On New Page After The First Section
\section{A}
blabla
\section{B}
blabla

\chapter{Another chapter}
%\Need Command Here To turn ON Starting Each Section On New Page
%And later on, in next chapter, I might turn it off again
\section{A}
blabla
\section{B}
blabla

\end{document}


reference start-new-page-with-each-section

btw, I use lualatex.

• just put \renewcommand\sectionbreak{} at the start of chapters where it is disabled and redefine it back to clearpage in the others. – David Carlisle May 17 at 6:40
• @DavidCarlisle thank you. That worked very well. – Nasser May 17 at 7:55

Just put

\renewcommand\sectionbreak{}


at the start of chapters where it is disabled and redefine it back to \clearpage in the others.

Here is an automated way to this this that only requires you to make changes in the preamble. You can use the \SetChaptersWithPageBreaks to give a comma separated list of the numbers of the chapters where you want page breaks between each section. For example, with

\SetChaptersWithPageBreaks{2,3,5}


chapters 2,3 and 5 will have these page breaks and the other chapters will not. With this is place the MWE below produces:

plus quite a few other pages. Here is the full code:

\documentclass[11pt]{scrbook}

\usepackage{titlesec}

\usepackage{expl3}
\ExplSyntaxOn
\clist_new:N \g_chapters_with_page_breaks_clist
\newcommand\SetChaptersWithPageBreaks[1]{
\clist_gset:Nn \g_chapters_with_page_breaks_clist {#1}
}
\newcommand{\sectionbreak}{
\clist_if_in:NxT \g_chapters_with_page_breaks_clist {\arabic{chapter}} {\clearpage}
}
\cs_generate_variant:Nn \clist_if_in:NnT {NxT}
\ExplSyntaxOff

% comma separated list of chapters that require page breaks afer  sections
\SetChaptersWithPageBreaks{2,3,5}

\begin{document}
\chapter{introduction}
\section{A} blabla \section{B} blabla

\chapter{Another chapter}
\section{A} blabla \section{B} blabla

\chapter{Another chapter}
\section{A} blabla \section{B} blabla

\chapter{Another chapter}
\section{A} blabla \section{B} blabla

\chapter{Another chapter}
\section{A} blabla \section{B} blabla

\chapter{Another chapter}
\section{A} blabla \section{B} blabla

\end{document}