I have the following piece of code in the preamble, that should prevent chapter from beginning on different pages, but, by the same time, when I get to chapter 3 it has enough text to break a page and does not, how can I fix it?
\usepackage{etoolbox}
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother
Unfortunately, I can't build a MWE with the same specs as the original, so I'm letting a only view link to the overleaf project.
As pointed in the coments bellow, LaTeX does not handle well with a whole bunch of text inside sections, so I changed from sections to enumerate environment, and then changed how the item appeared using the enumitem package.
\subsection{A whole bunch of text}
. LaTeX doesn't allow page breaks in section titles. You should make your document into something like\subsection{Title} A whole bunch of text
.